-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Draft new implementation for GMP protocol classes base on the co…
…re module Use the core module to re-implement the current GMP protocol classes.
- Loading branch information
1 parent
a65c046
commit d00f702
Showing
4 changed files
with
238 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from ._gmp import GMP | ||
|
||
Gmp = GMP # for backwards compatibility | ||
|
||
__all__ = ( | ||
"GMP", | ||
"Gmp", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from typing import Optional, Union | ||
|
||
from .._protocol import GvmProtocol, T | ||
from .core.requests import ( | ||
Authentication, | ||
PortList, | ||
PortRangeType, | ||
Version, | ||
) | ||
|
||
|
||
class GMPv224(GvmProtocol[T]): | ||
_authenticated = False | ||
|
||
def is_authenticated(self) -> bool: | ||
"""Checks if the user is authenticated | ||
If the user is authenticated privileged GMP commands like get_tasks | ||
may be send to gvmd. | ||
Returns: | ||
bool: True if an authenticated connection to gvmd has been | ||
established. | ||
""" | ||
return self._authenticated | ||
|
||
def authenticate(self, username: str, password: str) -> T: | ||
"""Authenticate to gvmd. | ||
The generated authenticate command will be send to server. | ||
Afterwards the response is read, transformed and returned. | ||
Arguments: | ||
username: Username | ||
password: Password | ||
""" | ||
response = self._send_command( | ||
Authentication.authenticate(username=username, password=password) | ||
) | ||
|
||
if response.is_success: | ||
self._authenticated = True | ||
|
||
return self._transform(response) | ||
|
||
def describe_auth(self) -> T: | ||
"""Describe authentication methods | ||
Returns a list of all used authentication methods if such a list is | ||
available. | ||
Returns: | ||
The response. See :py:meth:`send_command` for details. | ||
""" | ||
return self._send_and_transform_command(Authentication.describe_auth()) | ||
|
||
def modify_auth( | ||
self, group_name: str, auth_conf_settings: dict[str, str] | ||
) -> T: | ||
"""Modifies an existing auth. | ||
Arguments: | ||
group_name: Name of the group to be modified. | ||
auth_conf_settings: The new auth config. | ||
""" | ||
return self._send_and_transform_command( | ||
Authentication.modify_auth(group_name, auth_conf_settings) | ||
) | ||
|
||
def get_version(self) -> T: | ||
return self._send_and_transform_command(Version.get_version()) | ||
|
||
def clone_port_list(self, port_list_id: str) -> T: | ||
return self._send_and_transform_command( | ||
PortList.clone_port_list(port_list_id) | ||
) | ||
|
||
def create_port_list( | ||
self, name: str, port_range: str, *, comment: Optional[str] = None | ||
) -> T: | ||
return self._send_and_transform_command( | ||
PortList.create_port_list(name, port_range, comment=comment) | ||
) | ||
|
||
def create_port_range( | ||
self, | ||
port_list_id: str, | ||
start: int, | ||
end: int, | ||
port_range_type: Union[str, PortRangeType], | ||
*, | ||
comment: Optional[str] = None, | ||
) -> T: | ||
return self._send_and_transform_command( | ||
PortList.create_port_range( | ||
port_list_id, start, end, port_range_type, comment=comment | ||
) | ||
) | ||
|
||
def delete_port_list( | ||
self, port_list_id: str, *, ultimate: bool = False | ||
) -> T: | ||
return self._send_and_transform_command( | ||
PortList.delete_port_list(port_list_id, ultimate=ultimate) | ||
) | ||
|
||
def delete_port_range(self, port_range_id: str) -> T: | ||
return self._send_and_transform_command( | ||
PortList.delete_port_range(port_range_id) | ||
) | ||
|
||
def get_port_lists( | ||
self, | ||
*, | ||
filter_string: Optional[str] = None, | ||
filter_id: Optional[str] = None, | ||
details: Optional[bool] = None, | ||
targets: Optional[bool] = None, | ||
trash: Optional[bool] = None, | ||
) -> T: | ||
return self._send_and_transform_command( | ||
PortList.get_port_lists( | ||
filter_string=filter_string, | ||
filter_id=filter_id, | ||
details=details, | ||
targets=targets, | ||
trash=trash, | ||
) | ||
) | ||
|
||
def get_port_list(self, port_list_id: str) -> T: | ||
return self._send_and_transform_command( | ||
PortList.get_port_list(port_list_id) | ||
) | ||
|
||
def modify_port_list( | ||
self, | ||
port_list_id: str, | ||
*, | ||
comment: Optional[str] = None, | ||
name: Optional[str] = None, | ||
) -> T: | ||
return self._send_and_transform_command( | ||
PortList.modify_port_list(port_list_id, comment=comment, name=name) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SPDX-FileCopyrightText: 2024 Greenbone AG | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from typing import Optional | ||
|
||
from .._protocol import T | ||
from ._gmp224 import GMPv224 | ||
from .core.requests import ( | ||
ResourceNames, | ||
ResourceType, | ||
) | ||
|
||
|
||
class GMPv225(GMPv224[T]): | ||
def get_resource_names( | ||
self, | ||
resource_type: ResourceType, | ||
*, | ||
filter_string: Optional[str] = None, | ||
) -> T: | ||
"""Request a list of resource names and IDs | ||
Arguments: | ||
resource_type: Type must be either ALERT, CERT_BUND_ADV, | ||
CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, | ||
GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, | ||
PORT_LIST, REPORT_FORMAT, REPORT, RESULT, ROLE, | ||
SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE | ||
or USER | ||
filter_string: Filter term to use for the query | ||
""" | ||
return self._send_and_transform_command( | ||
ResourceNames.get_resource_names( | ||
resource_type, filter_string=filter_string | ||
) | ||
) | ||
|
||
def get_resource_name( | ||
self, resource_id: str, resource_type: ResourceType | ||
) -> T: | ||
"""Request a single resource name | ||
Arguments: | ||
resource_id: ID of an existing resource | ||
resource_type: Type must be either ALERT, CERT_BUND_ADV, | ||
CONFIG, CPE, CREDENTIAL, CVE, DFN_CERT_ADV, FILTER, | ||
GROUP, HOST, NOTE, NVT, OS, OVERRIDE, PERMISSION, | ||
PORT_LIST, REPORT_FORMAT, REPORT, RESULT, ROLE, | ||
SCANNER, SCHEDULE, TARGET, TASK, TLS_CERTIFICATE | ||
or USER | ||
""" | ||
return self._send_and_transform_command( | ||
ResourceNames.get_resource_name(resource_id, resource_type) | ||
) |