Skip to content

Commit

Permalink
Merge pull request #332 from y0urself/modify-audit-and-policy
Browse files Browse the repository at this point in the history
Modify audit and policy
  • Loading branch information
y0urself authored Nov 12, 2020
2 parents a7ad2f5 + da6640e commit bd27558
Show file tree
Hide file tree
Showing 13 changed files with 1,146 additions and 11 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
* Moved tests for `SeverityLevel` Enum and `get_severity_level_from_string()` [#327](https://github.com/greenbone/python-gvm/pull/327)
* Added the `modify_audit` function [#332](https://github.com/greenbone/python-gvm/pull/332)
* Added the `modify_policy_set_nvt_preference` function [#332](https://github.com/greenbone/python-gvm/pull/332)
* Added the `modify_policy_set_name` function [#332](https://github.com/greenbone/python-gvm/pull/332)
* Added the `modify_policy_set_comment` function [#332](https://github.com/greenbone/python-gvm/pull/332)
* Added the `modify_policy_set_scanner_preference` function [#332](https://github.com/greenbone/python-gvm/pull/332)
* Added the `modify_policy_set_nvt_selection` function [#332](https://github.com/greenbone/python-gvm/pull/332)
* Added the `modify_policy_set_family_selection` function [#332](https://github.com/greenbone/python-gvm/pull/332)

### Changed
* Moved tests for `SeverityLevel` Enum and `get_severity_level_from_string()` [#327](https://github.com/greenbone/python-gvm/pull/327)

### Deprecated
### Removed
### Fixed
Expand Down
167 changes: 167 additions & 0 deletions gvm/protocols/gmpv9/gmpv9.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,173 @@ def modify_alert(

return self._send_xml_command(cmd)

def modify_audit(
self,
audit_id: str,
*,
name: Optional[str] = None,
policy_id: Optional[str] = None,
target_id: Optional[str] = None,
scanner_id: Optional[str] = None,
alterable: Optional[bool] = None,
hosts_ordering: Optional[HostsOrdering] = None,
schedule_id: Optional[str] = None,
schedule_periods: Optional[int] = None,
comment: Optional[str] = None,
alert_ids: Optional[List[str]] = None,
observers: Optional[List[str]] = None,
preferences: Optional[dict] = None
) -> Any:
"""Modifies an existing task.
Arguments:
audit_id: UUID of audit to modify.
name: The name of the audit.
policy_id: UUID of policy to use by the audit
target_id: UUID of target to be scanned
scanner_id: UUID of scanner to use for scanning the target
comment: The comment on the audit.
alert_ids: List of UUIDs for alerts to be applied to the audit
hosts_ordering: The order hosts are scanned in
schedule_id: UUID of a schedule when the audit should be run.
schedule_periods: A limit to the number of times the audit will be
scheduled, or 0 for no limit.
observers: List of names or ids of users which should be allowed to
observe this audit
preferences: Name/Value pairs of scanner preferences.
Returns:
The response. See :py:meth:`send_command` for details.
"""
self.modify_task(
task_id=audit_id,
name=name,
config_id=policy_id,
target_id=target_id,
scanner_id=scanner_id,
alterable=alterable,
hosts_ordering=hosts_ordering,
schedule_id=schedule_id,
schedule_periods=schedule_periods,
comment=comment,
alert_ids=alert_ids,
observers=observers,
preferences=preferences,
)

def modify_policy_set_nvt_preference(
self,
policy_id: str,
name: str,
nvt_oid: str,
*,
value: Optional[str] = None
) -> Any:
"""Modifies the nvt preferences of an existing policy.
Arguments:
policy_id: UUID of policy to modify.
name: Name for preference to change.
nvt_oid: OID of the NVT associated with preference to modify
value: New value for the preference. None to delete the preference
and to use the default instead.
"""
self.modify_config_set_nvt_preference(
config_id=policy_id,
name=name,
nvt_oid=nvt_oid,
value=value,
)

def modify_policy_set_name(self, policy_id: str, name: str) -> Any:
"""Modifies the name of an existing policy
Arguments:
config_id: UUID of policy to modify.
name: New name for the config.
"""
self.modify_config_set_name(
config_id=policy_id,
name=name,
)

def modify_policy_set_comment(
self, policy_id: str, comment: Optional[str] = ""
) -> Any:
"""Modifies the comment of an existing policy
Arguments:
policy_id: UUID of policy to modify.
comment: Comment to set on a config. Default: ''
"""
self.modify_config_set_comment(
config_id=policy_id,
comment=comment,
)

def modify_policy_set_scanner_preference(
self, policy_id: str, name: str, *, value: Optional[str] = None
) -> Any:
"""Modifies the scanner preferences of an existing policy
Arguments:
policy_id: UUID of policy to modify.
name: Name of the scanner preference to change
value: New value for the preference. None to delete the preference
and to use the default instead.
"""
self.modify_config_set_scanner_preference(
config_id=policy_id,
name=name,
value=value,
)

def modify_policy_set_nvt_selection(
self, policy_id: str, family: str, nvt_oids: List[str]
) -> Any:
"""Modifies the selected nvts of an existing policy
The manager updates the given family in the config to include only the
given NVTs.
Arguments:
policy_id: UUID of policy to modify.
family: Name of the NVT family to include NVTs from
nvt_oids: List of NVTs to select for the family.
"""
self.modify_config_set_nvt_selection(
config_id=policy_id,
family=family,
nvt_oids=nvt_oids,
)

def modify_policy_set_family_selection(
self,
policy_id: str,
families: List[str],
*,
auto_add_new_families: Optional[bool] = True,
auto_add_new_nvts: Optional[bool] = True
) -> Any:
"""
Selected the NVTs of a policy at a family level.
Arguments:
policy_id: UUID of policy to modify.
families: List of NVT family names to select.
auto_add_new_families: Whether new families should be added to the
policy automatically. Default: True.
auto_add_new_nvts: Whether new NVTs in the selected families should
be added to the policy automatically. Default: True.
"""
self.modify_config_set_family_selection(
config_id=policy_id,
families=families,
auto_add_new_families=auto_add_new_families,
auto_add_new_nvts=auto_add_new_nvts,
)

def modify_tls_certificate(
self,
tls_certificate_id: str,
Expand Down
55 changes: 48 additions & 7 deletions tests/protocols/gmpv208/test_v9_from_gmpv208.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,51 @@ class Gmpv208GetTLSCertificatesTestCase(
pass


class Gmpv208ModifyTestCase(GmpModifyTestCase, Gmpv208TestCase):
class Gmpv208ModifyAuditCommandTestCase(
GmpModifyAuditCommandTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyCredentialTestCase(
GmpModifyCredentialTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyPolicySetCommentTestCase(
GmpModifyPolicySetCommentTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyPolicySetNameTestCase(
GmpModifyPolicySetNameTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyPolicySetFamilySelectionTestCase(
GmpModifyPolicySetFamilySelectionTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyPolicySetNvtPreferenceTestCase(
GmpModifyPolicySetNvtPreferenceTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyPolicySetNvtSelectionTestCase(
GmpModifyPolicySetNvtSelectionTestCase, Gmpv208TestCase
):
pass


class Gmpv208ModifyPolicySetScannerPreferenceTestCase(
GmpModifyPolicySetScannerPreferenceTestCase, Gmpv208TestCase
):
pass


Expand All @@ -168,12 +212,9 @@ class Gmpv208ModifyTLSCertificateTestCase(
pass


class Gmpv208CreateScannerTestCase(
GmpCreateScannerTestCase, Gmpv208TestCase
):
class Gmpv208CreateScannerTestCase(GmpCreateScannerTestCase, Gmpv208TestCase):
pass

class Gmpv208ModifyScannerTestCase(
GmpModifyScannerTestCase, Gmpv208TestCase
):

class Gmpv208ModifyScannerTestCase(GmpModifyScannerTestCase, Gmpv208TestCase):
pass
44 changes: 43 additions & 1 deletion tests/protocols/gmpv9/test_new_gmpv9.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ class Gmpv9GetTLSCertificatesTestCase(
pass


class Gmpv9ModifyTestCase(GmpModifyTestCase, Gmpv9TestCase):
class Gmpv9ModifyAuditCommandTestCase(
GmpModifyAuditCommandTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyCredentialTestCase(GmpModifyCredentialTestCase, Gmpv9TestCase):
pass


Expand All @@ -178,6 +184,42 @@ class Gmpv9ModifyPermissionTestCase(GmpModifyPermissionTestCase, Gmpv9TestCase):
pass


class Gmpv9ModifyPolicySetCommentTestCase(
GmpModifyPolicySetCommentTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyPolicySetNameTestCase(
GmpModifyPolicySetNameTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyPolicySetFamilySelectionTestCase(
GmpModifyPolicySetFamilySelectionTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyPolicySetNvtPreferenceTestCase(
GmpModifyPolicySetNvtPreferenceTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyPolicySetNvtSelectionTestCase(
GmpModifyPolicySetNvtSelectionTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyPolicySetScannerPreferenceTestCase(
GmpModifyPolicySetScannerPreferenceTestCase, Gmpv9TestCase
):
pass


class Gmpv9ModifyReportFormatTestCase(
GmpModifyReportFormatTestCase, Gmpv9TestCase
):
Expand Down
17 changes: 16 additions & 1 deletion tests/protocols/gmpv9/testcmds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,25 @@
from .test_get_tasks import GmpGetTasksTestCase
from .test_get_tls_certificate import GmpGetTlsCertificateTestCase
from .test_get_tls_certificates import GmpGetTLSCertificatesTestCase
from .test_modify_credential import GmpModifyTestCase
from .test_modify_credential import GmpModifyCredentialTestCase
from .test_modify_alert import GmpModifyAlertTestCase
from .test_modify_audit import GmpModifyAuditCommandTestCase
from .test_modify_filter import GmpModifyFilterTestCase
from .test_modify_permission import GmpModifyPermissionTestCase
from .test_modify_policy_set_comment import GmpModifyPolicySetCommentTestCase
from .test_modify_policy_set_family_selection import (
GmpModifyPolicySetFamilySelectionTestCase,
)
from .test_modify_policy_set_name import GmpModifyPolicySetNameTestCase
from .test_modify_policy_set_nvt_preference import (
GmpModifyPolicySetNvtPreferenceTestCase,
)
from .test_modify_policy_set_nvt_selection import (
GmpModifyPolicySetNvtSelectionTestCase,
)
from .test_modify_policy_set_scanner_preference import (
GmpModifyPolicySetScannerPreferenceTestCase,
)
from .test_modify_report_format import GmpModifyReportFormatTestCase
from .test_modify_tag import GmpModifyTagTestCase
from .test_modify_ticket import GmpModifyTicketTestCase
Expand Down
Loading

0 comments on commit bd27558

Please sign in to comment.