Skip to content

Commit 59b84bb

Browse files
authored
Merge pull request #289 from y0urself/tasks-parameter
Added tasks parameter to get_config
2 parents 4a1e92c + e969e42 commit 59b84bb

File tree

6 files changed

+52
-64
lines changed

6 files changed

+52
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Added
1010
### Changed
11+
* Added the `tasks` parameter to `get_config()`. [#289](https://github.com/greenbone/python-gvm/pull/289)
1112
### Deprecated
1213
### Removed
1314
### Fixed

gvm/protocols/gmpv208/gmpv208.py

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -177,56 +177,6 @@ def get_info(self, info_id: str, info_type: InfoType) -> Any:
177177
cmd.set_attribute("details", "1")
178178
return self._send_xml_command(cmd)
179179

180-
def modify_schedule(
181-
self,
182-
schedule_id: str,
183-
*,
184-
name: Optional[str] = None,
185-
icalendar: Optional[str] = None,
186-
timezone: Optional[str] = None,
187-
comment: Optional[str] = None
188-
) -> Any:
189-
"""Modifies an existing schedule
190-
191-
Arguments:
192-
schedule_id: UUID of the schedule to be modified
193-
name: Name of the schedule
194-
icalendar: `iCalendar`_ (RFC 5545) based data.
195-
timezone: Timezone to use for the icalender events e.g
196-
Europe/Berlin. If the datetime values in the icalendar data are
197-
missing timezone information this timezone gets applied.
198-
Otherwise the datetime values from the icalendar data are
199-
displayed in this timezone
200-
commenhedule.
201-
202-
Returns:
203-
The response. See :py:meth:`send_command` for details.
204-
205-
.. _iCalendar:
206-
https://tools.ietf.org/html/rfc5545
207-
"""
208-
if not schedule_id:
209-
raise RequiredArgument(
210-
function=self.modify_schedule.__name__, argument='schedule_id'
211-
)
212-
213-
cmd = XmlCommand("modify_schedule")
214-
cmd.set_attribute("schedule_id", schedule_id)
215-
216-
if name:
217-
cmd.add_element("name", name)
218-
219-
if icalendar:
220-
cmd.add_element("icalendar", icalendar)
221-
222-
if timezone:
223-
cmd.add_element("timezone", timezone)
224-
225-
if comment:
226-
cmd.add_element("comment", comment)
227-
228-
return self._send_xml_command(cmd)
229-
230180
def create_target(
231181
self,
232182
name: str,
@@ -271,6 +221,10 @@ def create_target(
271221
Returns:
272222
The response. See :py:meth:`send_command` for details.
273223
"""
224+
225+
cmd = XmlCommand("create_target")
226+
_xmlname = cmd.add_element("name", name)
227+
274228
if make_unique is not None:
275229
warnings.warn(
276230
'create_target make_unique argument is deprecated '
@@ -283,16 +237,6 @@ def create_target(
283237
function=self.create_target.__name__, argument='name'
284238
)
285239

286-
# since 20.08 one of port_range or port_list_id is required!
287-
if not port_range and not port_list_id:
288-
raise RequiredArgument(
289-
function=self.create_target.__name__,
290-
argument='port_range or port_list_id',
291-
)
292-
293-
cmd = XmlCommand("create_target")
294-
_xmlname = cmd.add_element("name", name)
295-
296240
if asset_hosts_filter:
297241
cmd.add_element(
298242
"asset_hosts", attrs={"filter": str(asset_hosts_filter)}
@@ -347,6 +291,13 @@ def create_target(
347291
"reverse_lookup_unify", _to_bool(reverse_lookup_unify)
348292
)
349293

294+
# since 20.08 one of port_range or port_list_id is required!
295+
if not port_range and not port_list_id:
296+
raise RequiredArgument(
297+
function=self.create_target.__name__,
298+
argument='port_range or port_list_id',
299+
)
300+
350301
if port_range:
351302
cmd.add_element("port_range", port_range)
352303

gvm/protocols/gmpv7/gmpv7.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2993,11 +2993,14 @@ def get_configs(
29932993

29942994
return self._send_xml_command(cmd)
29952995

2996-
def get_config(self, config_id: str) -> Any:
2996+
def get_config(
2997+
self, config_id: str, *, tasks: Optional[bool] = None
2998+
) -> Any:
29972999
"""Request a single scan config
29983000
29993001
Arguments:
30003002
config_id: UUID of an existing scan config
3003+
tasks: Whether to get tasks using this config
30013004
30023005
Returns:
30033006
The response. See :py:meth:`send_command` for details.
@@ -3011,6 +3014,9 @@ def get_config(self, config_id: str) -> Any:
30113014

30123015
cmd.set_attribute("config_id", config_id)
30133016

3017+
if tasks is not None:
3018+
cmd.set_attribute("tasks", _to_bool(tasks))
3019+
30143020
# for single entity always request all details
30153021
cmd.set_attribute("details", "1")
30163022
return self._send_xml_command(cmd)

gvm/protocols/gmpv9/gmpv9.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,16 +743,21 @@ def get_policies(
743743
trash=trash,
744744
)
745745

746-
def get_config(self, config_id: str) -> Any:
746+
def get_config(
747+
self, config_id: str, *, tasks: Optional[bool] = None
748+
) -> Any:
747749
"""Request a single scan config
748750
749751
Arguments:
750752
config_id: UUID of an existing scan config
753+
tasks: Whether to get tasks using this config
751754
752755
Returns:
753756
The response. See :py:meth:`send_command` for details.
754757
"""
755-
return self.__get_config(config_id, UsageType.SCAN)
758+
return self.__get_config(
759+
config_id=config_id, usage_type=UsageType.SCAN, tasks=tasks
760+
)
756761

757762
def get_policy(self, policy_id: str) -> Any:
758763
"""Request a single policy
@@ -1086,16 +1091,26 @@ def __get_configs(
10861091

10871092
return self._send_xml_command(cmd)
10881093

1089-
def __get_config(self, config_id: str, usage_type: UsageType) -> Any:
1094+
def __get_config(
1095+
self,
1096+
config_id: str,
1097+
usage_type: UsageType,
1098+
*,
1099+
tasks: Optional[bool] = None
1100+
) -> Any:
10901101
if not config_id:
10911102
raise RequiredArgument(
10921103
function=self.get_config.__name__, argument='config_id'
10931104
)
10941105

10951106
cmd = XmlCommand("get_configs")
10961107
cmd.set_attribute("config_id", config_id)
1108+
10971109
cmd.set_attribute("usage_type", usage_type.value)
10981110

1111+
if tasks is not None:
1112+
cmd.set_attribute("tasks", _to_bool(tasks))
1113+
10991114
# for single entity always request all details
11001115
cmd.set_attribute("details", "1")
11011116

tests/protocols/gmpv7/testcmds/test_get_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def test_get_config(self):
2929
'<get_configs config_id="a1" details="1"/>'
3030
)
3131

32+
def test_get_config_with_tasks(self):
33+
self.gmp.get_config('a1', tasks=True)
34+
35+
self.connection.send.has_been_called_with(
36+
'<get_configs config_id="a1" tasks="1" details="1"/>'
37+
)
38+
3239
def test_fail_without_config_id(self):
3340
with self.assertRaises(GvmError):
3441
self.gmp.get_config(None)

tests/protocols/gmpv9/testcmds/test_get_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def test_get_config(self):
2929
'<get_configs config_id="a1" usage_type="scan" details="1"/>'
3030
)
3131

32+
def test_get_config_with_tasks(self):
33+
self.gmp.get_config('a1', tasks=True)
34+
35+
self.connection.send.has_been_called_with(
36+
'<get_configs config_id="a1" usage_type="scan" '
37+
'tasks="1" details="1"/>'
38+
)
39+
3240
def test_fail_without_config_id(self):
3341
with self.assertRaises(GvmError):
3442
self.gmp.get_config(None)

0 commit comments

Comments
 (0)