Skip to content

Commit bd27558

Browse files
authored
Merge pull request #332 from y0urself/modify-audit-and-policy
Modify audit and policy
2 parents a7ad2f5 + da6640e commit bd27558

13 files changed

+1146
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10-
* Moved tests for `SeverityLevel` Enum and `get_severity_level_from_string()` [#327](https://github.com/greenbone/python-gvm/pull/327)
10+
* Added the `modify_audit` function [#332](https://github.com/greenbone/python-gvm/pull/332)
11+
* Added the `modify_policy_set_nvt_preference` function [#332](https://github.com/greenbone/python-gvm/pull/332)
12+
* Added the `modify_policy_set_name` function [#332](https://github.com/greenbone/python-gvm/pull/332)
13+
* Added the `modify_policy_set_comment` function [#332](https://github.com/greenbone/python-gvm/pull/332)
14+
* Added the `modify_policy_set_scanner_preference` function [#332](https://github.com/greenbone/python-gvm/pull/332)
15+
* Added the `modify_policy_set_nvt_selection` function [#332](https://github.com/greenbone/python-gvm/pull/332)
16+
* Added the `modify_policy_set_family_selection` function [#332](https://github.com/greenbone/python-gvm/pull/332)
1117

1218
### Changed
19+
* Moved tests for `SeverityLevel` Enum and `get_severity_level_from_string()` [#327](https://github.com/greenbone/python-gvm/pull/327)
20+
1321
### Deprecated
1422
### Removed
1523
### Fixed

gvm/protocols/gmpv9/gmpv9.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,173 @@ def modify_alert(
657657

658658
return self._send_xml_command(cmd)
659659

660+
def modify_audit(
661+
self,
662+
audit_id: str,
663+
*,
664+
name: Optional[str] = None,
665+
policy_id: Optional[str] = None,
666+
target_id: Optional[str] = None,
667+
scanner_id: Optional[str] = None,
668+
alterable: Optional[bool] = None,
669+
hosts_ordering: Optional[HostsOrdering] = None,
670+
schedule_id: Optional[str] = None,
671+
schedule_periods: Optional[int] = None,
672+
comment: Optional[str] = None,
673+
alert_ids: Optional[List[str]] = None,
674+
observers: Optional[List[str]] = None,
675+
preferences: Optional[dict] = None
676+
) -> Any:
677+
"""Modifies an existing task.
678+
679+
Arguments:
680+
audit_id: UUID of audit to modify.
681+
name: The name of the audit.
682+
policy_id: UUID of policy to use by the audit
683+
target_id: UUID of target to be scanned
684+
scanner_id: UUID of scanner to use for scanning the target
685+
comment: The comment on the audit.
686+
alert_ids: List of UUIDs for alerts to be applied to the audit
687+
hosts_ordering: The order hosts are scanned in
688+
schedule_id: UUID of a schedule when the audit should be run.
689+
schedule_periods: A limit to the number of times the audit will be
690+
scheduled, or 0 for no limit.
691+
observers: List of names or ids of users which should be allowed to
692+
observe this audit
693+
preferences: Name/Value pairs of scanner preferences.
694+
695+
Returns:
696+
The response. See :py:meth:`send_command` for details.
697+
"""
698+
self.modify_task(
699+
task_id=audit_id,
700+
name=name,
701+
config_id=policy_id,
702+
target_id=target_id,
703+
scanner_id=scanner_id,
704+
alterable=alterable,
705+
hosts_ordering=hosts_ordering,
706+
schedule_id=schedule_id,
707+
schedule_periods=schedule_periods,
708+
comment=comment,
709+
alert_ids=alert_ids,
710+
observers=observers,
711+
preferences=preferences,
712+
)
713+
714+
def modify_policy_set_nvt_preference(
715+
self,
716+
policy_id: str,
717+
name: str,
718+
nvt_oid: str,
719+
*,
720+
value: Optional[str] = None
721+
) -> Any:
722+
"""Modifies the nvt preferences of an existing policy.
723+
724+
Arguments:
725+
policy_id: UUID of policy to modify.
726+
name: Name for preference to change.
727+
nvt_oid: OID of the NVT associated with preference to modify
728+
value: New value for the preference. None to delete the preference
729+
and to use the default instead.
730+
"""
731+
self.modify_config_set_nvt_preference(
732+
config_id=policy_id,
733+
name=name,
734+
nvt_oid=nvt_oid,
735+
value=value,
736+
)
737+
738+
def modify_policy_set_name(self, policy_id: str, name: str) -> Any:
739+
"""Modifies the name of an existing policy
740+
741+
Arguments:
742+
config_id: UUID of policy to modify.
743+
name: New name for the config.
744+
"""
745+
self.modify_config_set_name(
746+
config_id=policy_id,
747+
name=name,
748+
)
749+
750+
def modify_policy_set_comment(
751+
self, policy_id: str, comment: Optional[str] = ""
752+
) -> Any:
753+
"""Modifies the comment of an existing policy
754+
755+
Arguments:
756+
policy_id: UUID of policy to modify.
757+
comment: Comment to set on a config. Default: ''
758+
"""
759+
self.modify_config_set_comment(
760+
config_id=policy_id,
761+
comment=comment,
762+
)
763+
764+
def modify_policy_set_scanner_preference(
765+
self, policy_id: str, name: str, *, value: Optional[str] = None
766+
) -> Any:
767+
"""Modifies the scanner preferences of an existing policy
768+
769+
Arguments:
770+
policy_id: UUID of policy to modify.
771+
name: Name of the scanner preference to change
772+
value: New value for the preference. None to delete the preference
773+
and to use the default instead.
774+
775+
"""
776+
self.modify_config_set_scanner_preference(
777+
config_id=policy_id,
778+
name=name,
779+
value=value,
780+
)
781+
782+
def modify_policy_set_nvt_selection(
783+
self, policy_id: str, family: str, nvt_oids: List[str]
784+
) -> Any:
785+
"""Modifies the selected nvts of an existing policy
786+
787+
The manager updates the given family in the config to include only the
788+
given NVTs.
789+
790+
Arguments:
791+
policy_id: UUID of policy to modify.
792+
family: Name of the NVT family to include NVTs from
793+
nvt_oids: List of NVTs to select for the family.
794+
"""
795+
self.modify_config_set_nvt_selection(
796+
config_id=policy_id,
797+
family=family,
798+
nvt_oids=nvt_oids,
799+
)
800+
801+
def modify_policy_set_family_selection(
802+
self,
803+
policy_id: str,
804+
families: List[str],
805+
*,
806+
auto_add_new_families: Optional[bool] = True,
807+
auto_add_new_nvts: Optional[bool] = True
808+
) -> Any:
809+
"""
810+
Selected the NVTs of a policy at a family level.
811+
812+
Arguments:
813+
policy_id: UUID of policy to modify.
814+
families: List of NVT family names to select.
815+
auto_add_new_families: Whether new families should be added to the
816+
policy automatically. Default: True.
817+
auto_add_new_nvts: Whether new NVTs in the selected families should
818+
be added to the policy automatically. Default: True.
819+
"""
820+
self.modify_config_set_family_selection(
821+
config_id=policy_id,
822+
families=families,
823+
auto_add_new_families=auto_add_new_families,
824+
auto_add_new_nvts=auto_add_new_nvts,
825+
)
826+
660827
def modify_tls_certificate(
661828
self,
662829
tls_certificate_id: str,

tests/protocols/gmpv208/test_v9_from_gmpv208.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,51 @@ class Gmpv208GetTLSCertificatesTestCase(
154154
pass
155155

156156

157-
class Gmpv208ModifyTestCase(GmpModifyTestCase, Gmpv208TestCase):
157+
class Gmpv208ModifyAuditCommandTestCase(
158+
GmpModifyAuditCommandTestCase, Gmpv208TestCase
159+
):
160+
pass
161+
162+
163+
class Gmpv208ModifyCredentialTestCase(
164+
GmpModifyCredentialTestCase, Gmpv208TestCase
165+
):
166+
pass
167+
168+
169+
class Gmpv208ModifyPolicySetCommentTestCase(
170+
GmpModifyPolicySetCommentTestCase, Gmpv208TestCase
171+
):
172+
pass
173+
174+
175+
class Gmpv208ModifyPolicySetNameTestCase(
176+
GmpModifyPolicySetNameTestCase, Gmpv208TestCase
177+
):
178+
pass
179+
180+
181+
class Gmpv208ModifyPolicySetFamilySelectionTestCase(
182+
GmpModifyPolicySetFamilySelectionTestCase, Gmpv208TestCase
183+
):
184+
pass
185+
186+
187+
class Gmpv208ModifyPolicySetNvtPreferenceTestCase(
188+
GmpModifyPolicySetNvtPreferenceTestCase, Gmpv208TestCase
189+
):
190+
pass
191+
192+
193+
class Gmpv208ModifyPolicySetNvtSelectionTestCase(
194+
GmpModifyPolicySetNvtSelectionTestCase, Gmpv208TestCase
195+
):
196+
pass
197+
198+
199+
class Gmpv208ModifyPolicySetScannerPreferenceTestCase(
200+
GmpModifyPolicySetScannerPreferenceTestCase, Gmpv208TestCase
201+
):
158202
pass
159203

160204

@@ -168,12 +212,9 @@ class Gmpv208ModifyTLSCertificateTestCase(
168212
pass
169213

170214

171-
class Gmpv208CreateScannerTestCase(
172-
GmpCreateScannerTestCase, Gmpv208TestCase
173-
):
215+
class Gmpv208CreateScannerTestCase(GmpCreateScannerTestCase, Gmpv208TestCase):
174216
pass
175217

176-
class Gmpv208ModifyScannerTestCase(
177-
GmpModifyScannerTestCase, Gmpv208TestCase
178-
):
218+
219+
class Gmpv208ModifyScannerTestCase(GmpModifyScannerTestCase, Gmpv208TestCase):
179220
pass

tests/protocols/gmpv9/test_new_gmpv9.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ class Gmpv9GetTLSCertificatesTestCase(
166166
pass
167167

168168

169-
class Gmpv9ModifyTestCase(GmpModifyTestCase, Gmpv9TestCase):
169+
class Gmpv9ModifyAuditCommandTestCase(
170+
GmpModifyAuditCommandTestCase, Gmpv9TestCase
171+
):
172+
pass
173+
174+
175+
class Gmpv9ModifyCredentialTestCase(GmpModifyCredentialTestCase, Gmpv9TestCase):
170176
pass
171177

172178

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

180186

187+
class Gmpv9ModifyPolicySetCommentTestCase(
188+
GmpModifyPolicySetCommentTestCase, Gmpv9TestCase
189+
):
190+
pass
191+
192+
193+
class Gmpv9ModifyPolicySetNameTestCase(
194+
GmpModifyPolicySetNameTestCase, Gmpv9TestCase
195+
):
196+
pass
197+
198+
199+
class Gmpv9ModifyPolicySetFamilySelectionTestCase(
200+
GmpModifyPolicySetFamilySelectionTestCase, Gmpv9TestCase
201+
):
202+
pass
203+
204+
205+
class Gmpv9ModifyPolicySetNvtPreferenceTestCase(
206+
GmpModifyPolicySetNvtPreferenceTestCase, Gmpv9TestCase
207+
):
208+
pass
209+
210+
211+
class Gmpv9ModifyPolicySetNvtSelectionTestCase(
212+
GmpModifyPolicySetNvtSelectionTestCase, Gmpv9TestCase
213+
):
214+
pass
215+
216+
217+
class Gmpv9ModifyPolicySetScannerPreferenceTestCase(
218+
GmpModifyPolicySetScannerPreferenceTestCase, Gmpv9TestCase
219+
):
220+
pass
221+
222+
181223
class Gmpv9ModifyReportFormatTestCase(
182224
GmpModifyReportFormatTestCase, Gmpv9TestCase
183225
):

tests/protocols/gmpv9/testcmds/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,25 @@
5151
from .test_get_tasks import GmpGetTasksTestCase
5252
from .test_get_tls_certificate import GmpGetTlsCertificateTestCase
5353
from .test_get_tls_certificates import GmpGetTLSCertificatesTestCase
54-
from .test_modify_credential import GmpModifyTestCase
54+
from .test_modify_credential import GmpModifyCredentialTestCase
5555
from .test_modify_alert import GmpModifyAlertTestCase
56+
from .test_modify_audit import GmpModifyAuditCommandTestCase
5657
from .test_modify_filter import GmpModifyFilterTestCase
5758
from .test_modify_permission import GmpModifyPermissionTestCase
59+
from .test_modify_policy_set_comment import GmpModifyPolicySetCommentTestCase
60+
from .test_modify_policy_set_family_selection import (
61+
GmpModifyPolicySetFamilySelectionTestCase,
62+
)
63+
from .test_modify_policy_set_name import GmpModifyPolicySetNameTestCase
64+
from .test_modify_policy_set_nvt_preference import (
65+
GmpModifyPolicySetNvtPreferenceTestCase,
66+
)
67+
from .test_modify_policy_set_nvt_selection import (
68+
GmpModifyPolicySetNvtSelectionTestCase,
69+
)
70+
from .test_modify_policy_set_scanner_preference import (
71+
GmpModifyPolicySetScannerPreferenceTestCase,
72+
)
5873
from .test_modify_report_format import GmpModifyReportFormatTestCase
5974
from .test_modify_tag import GmpModifyTagTestCase
6075
from .test_modify_ticket import GmpModifyTicketTestCase

0 commit comments

Comments
 (0)