File: _vts.py

package info (click to toggle)
python-gvm 26.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,132 kB
  • sloc: python: 44,662; makefile: 18
file content (72 lines) | stat: -rw-r--r-- 2,136 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# SPDX-FileCopyrightText: 2025 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""
API wrapper for accessing vulnerability test (VT) metadata from the openvasd HTTP API.
"""

import urllib.parse

import httpx

from ._api import OpenvasdAPI


class VtsAPI(OpenvasdAPI):
    """
    Provides access to the openvasd /vts endpoints.

    This includes retrieving the list of all available vulnerability tests
    as well as fetching detailed information for individual VTs by OID.
    """

    def get_all(self) -> httpx.Response:
        """
        Retrieve the list of all available vulnerability tests (VTs).

        This corresponds to a GET request to `/vts`.

        Returns:
            The full `httpx.Response` containing a JSON list of VT entries.

        Raises:
            httpx.HTTPStatusError: If the server returns a non-success status and exceptions are not suppressed.

        See: GET /vts in the openvasd API documentation.
        """
        try:
            response = self._client.get("/vts")
            response.raise_for_status()
            return response
        except httpx.HTTPStatusError as e:
            if self._suppress_exceptions:
                return e.response
            raise

    def get(self, oid: str) -> httpx.Response:
        """
        Retrieve detailed information about a specific VT by OID.

        This corresponds to a GET request to `/vts/{oid}`.

        Args:
            oid: The OID (object identifier) of the vulnerability test.

        Returns:
            The full `httpx.Response` containing VT metadata for the given OID.

        Raises:
            httpx.HTTPStatusError: If the server returns a non-success status and exceptions are not suppressed.

        See: GET /vts/{id} in the openvasd API documentation.
        """
        quoted_oid = urllib.parse.quote(oid)
        try:
            response = self._client.get(f"/vts/{quoted_oid}")
            response.raise_for_status()
            return response
        except httpx.HTTPStatusError as e:
            if self._suppress_exceptions:
                return e.response
            raise