Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GMP version 22.6 #1196

Merged
merged 6 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gvm/protocols/gmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ._gmp import GMP
from ._gmp224 import GMPv224
from ._gmp225 import GMPv225
from ._gmp226 import GMPv226

Gmp = GMP # for backwards compatibility

Expand All @@ -27,4 +28,5 @@
"Gmp",
"GMPv224",
"GMPv225",
"GMPv226",
)
25 changes: 21 additions & 4 deletions gvm/protocols/gmp/_gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import warnings
from types import TracebackType
from typing import Callable, Optional, Type, Union

from gvm.__version__ import __version__
from gvm.connections import GvmConnection
from gvm.errors import GvmError
from gvm.protocols.core import Response

from .._protocol import GvmProtocol, T, str_transform
from ._gmp224 import GMPv224
from ._gmp225 import GMPv225
from ._gmp226 import GMPv226
from .requests import Version

SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T]]
SUPPORTED_GMP_VERSIONS = Union[GMPv224[T], GMPv225[T], GMPv226[T]]
_SUPPORTED_GMP_VERSION_STRINGS = ["22.4", "22.5", "22.6"]


class GMP(GvmProtocol[T]):
Expand All @@ -30,9 +34,11 @@ class GMP(GvmProtocol[T]):
from gvm.protocols.gmp import GMP

with GMP(connection) as gmp:
# gmp can be an instance of gvm.protocols.gmp.GMPv224 or
# gvm.protocols.gmp.GMPv225 depending
# on the supported GMP version of the remote manager daemon
# gmp can be an instance of
# gvm.protocols.gmp.GMPv224,
# gvm.protocols.gmp.GMPv225
# or gvm.protocols.gmp.GMPv226
# depending on the supported GMP version of the remote manager daemon
resp = gmp.get_tasks()

"""
Expand Down Expand Up @@ -88,10 +94,21 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:
gmp_class = GMPv224
elif major_version == 22 and minor_version == 5:
gmp_class = GMPv225
elif major_version == 22 and minor_version >= 6:
gmp_class = GMPv226
if minor_version > 6:
warnings.warn(
"Remote manager daemon uses a newer GMP version then "
f"supported by python-gvm {__version__}. Please update to "
"a newer release of python-gvm if possible. "
f"Remote GMP version is {major_version}.{minor_version}. "
f"Supported GMP versions are {', '.join(_SUPPORTED_GMP_VERSION_STRINGS)}."
)
else:
raise GvmError(
"Remote manager daemon uses an unsupported version of GMP. "
f"The GMP version was {major_version}.{minor_version}"
f"Supported GMP versions are {', '.join(_SUPPORTED_GMP_VERSION_STRINGS)}."
)

return gmp_class(self._connection, transform=self._transform_callable) # type: ignore[arg-type]
Expand Down
Loading