@@ 277-402 (lines=126) @@ | ||
274 | cmd.set_attribute("details", "1") |
|
275 | return self._send_xml_command(cmd) |
|
276 | ||
277 | def modify_task( |
|
278 | self, |
|
279 | task_id: str, |
|
280 | *, |
|
281 | name: Optional[str] = None, |
|
282 | config_id: Optional[str] = None, |
|
283 | target_id: Optional[str] = None, |
|
284 | scanner_id: Optional[str] = None, |
|
285 | alterable: Optional[bool] = None, |
|
286 | hosts_ordering: Optional[HostsOrdering] = None, |
|
287 | schedule_id: Optional[str] = None, |
|
288 | schedule_periods: Optional[int] = None, |
|
289 | comment: Optional[str] = None, |
|
290 | alert_ids: Optional[List[str]] = None, |
|
291 | observers: Optional[List[str]] = None, |
|
292 | preferences: Optional[dict] = None, |
|
293 | ) -> Any: |
|
294 | """Modifies an existing task. |
|
295 | ||
296 | Arguments: |
|
297 | task_id: UUID of task to modify. |
|
298 | name: The name of the task. |
|
299 | config_id: UUID of scan config to use by the task |
|
300 | target_id: UUID of target to be scanned |
|
301 | scanner_id: UUID of scanner to use for scanning the target |
|
302 | comment: The comment on the task. |
|
303 | alert_ids: List of UUIDs for alerts to be applied to the task |
|
304 | hosts_ordering: The order hosts are scanned in |
|
305 | schedule_id: UUID of a schedule when the task should be run. |
|
306 | schedule_periods: A limit to the number of times the task will be |
|
307 | scheduled, or 0 for no limit. |
|
308 | observers: List of names or ids of users which should be allowed to |
|
309 | observe this task |
|
310 | preferences: Name/Value pairs of scanner preferences. |
|
311 | ||
312 | Returns: |
|
313 | The response. See :py:meth:`send_command` for details. |
|
314 | """ |
|
315 | if not task_id: |
|
316 | raise RequiredArgument( |
|
317 | function=self.modify_task.__name__, argument='task_id argument' |
|
318 | ) |
|
319 | ||
320 | cmd = XmlCommand("modify_task") |
|
321 | cmd.set_attribute("task_id", task_id) |
|
322 | ||
323 | if name: |
|
324 | cmd.add_element("name", name) |
|
325 | ||
326 | if comment: |
|
327 | cmd.add_element("comment", comment) |
|
328 | ||
329 | if config_id: |
|
330 | cmd.add_element("config", attrs={"id": config_id}) |
|
331 | ||
332 | if target_id: |
|
333 | cmd.add_element("target", attrs={"id": target_id}) |
|
334 | ||
335 | if alterable is not None: |
|
336 | cmd.add_element("alterable", to_bool(alterable)) |
|
337 | ||
338 | if hosts_ordering: |
|
339 | if not isinstance(hosts_ordering, HostsOrdering): |
|
340 | raise InvalidArgumentType( |
|
341 | function=self.modify_task.__name__, |
|
342 | argument='hosts_ordering', |
|
343 | arg_type=HostsOrdering.__name__, |
|
344 | ) |
|
345 | cmd.add_element("hosts_ordering", hosts_ordering.value) |
|
346 | ||
347 | if scanner_id: |
|
348 | cmd.add_element("scanner", attrs={"id": scanner_id}) |
|
349 | ||
350 | if schedule_id: |
|
351 | cmd.add_element("schedule", attrs={"id": schedule_id}) |
|
352 | ||
353 | if schedule_periods is not None: |
|
354 | if ( |
|
355 | not isinstance(schedule_periods, Integral) |
|
356 | or schedule_periods < 0 |
|
357 | ): |
|
358 | raise InvalidArgument( |
|
359 | "schedule_periods must be an integer greater or equal " |
|
360 | "than 0" |
|
361 | ) |
|
362 | cmd.add_element("schedule_periods", str(schedule_periods)) |
|
363 | ||
364 | if alert_ids is not None: |
|
365 | if not is_list_like(alert_ids): |
|
366 | raise InvalidArgumentType( |
|
367 | function=self.modify_task.__name__, |
|
368 | argument='alert_ids', |
|
369 | arg_type='list', |
|
370 | ) |
|
371 | ||
372 | if len(alert_ids) == 0: |
|
373 | cmd.add_element("alert", attrs={"id": "0"}) |
|
374 | else: |
|
375 | for alert in alert_ids: |
|
376 | cmd.add_element("alert", attrs={"id": str(alert)}) |
|
377 | ||
378 | if observers is not None: |
|
379 | if not is_list_like(observers): |
|
380 | raise InvalidArgumentType( |
|
381 | function=self.modify_task.__name__, |
|
382 | argument='observers', |
|
383 | arg_type='list', |
|
384 | ) |
|
385 | ||
386 | cmd.add_element("observers", to_comma_list(observers)) |
|
387 | ||
388 | if preferences is not None: |
|
389 | if not isinstance(preferences, Mapping): |
|
390 | raise InvalidArgumentType( |
|
391 | function=self.modify_task.__name__, |
|
392 | argument='preferences', |
|
393 | arg_type=Mapping.__name__, |
|
394 | ) |
|
395 | ||
396 | _xmlprefs = cmd.add_element("preferences") |
|
397 | for pref_name, pref_value in preferences.items(): |
|
398 | _xmlpref = _xmlprefs.add_element("preference") |
|
399 | _xmlpref.add_element("scanner_name", pref_name) |
|
400 | _xmlpref.add_element("value", str(pref_value)) |
|
401 | ||
402 | return self._send_xml_command(cmd) |
|
403 | ||
404 | def move_task(self, task_id: str, *, slave_id: Optional[str] = None) -> Any: |
|
405 | """Move an existing task to another GMP slave scanner or the master |
@@ 269-394 (lines=126) @@ | ||
266 | cmd.set_attribute("details", "1") |
|
267 | return self._send_xml_command(cmd) |
|
268 | ||
269 | def modify_audit( |
|
270 | self, |
|
271 | audit_id: str, |
|
272 | *, |
|
273 | name: Optional[str] = None, |
|
274 | policy_id: Optional[str] = None, |
|
275 | target_id: Optional[str] = None, |
|
276 | scanner_id: Optional[str] = None, |
|
277 | alterable: Optional[bool] = None, |
|
278 | hosts_ordering: Optional[HostsOrdering] = None, |
|
279 | schedule_id: Optional[str] = None, |
|
280 | schedule_periods: Optional[int] = None, |
|
281 | comment: Optional[str] = None, |
|
282 | alert_ids: Optional[List[str]] = None, |
|
283 | observers: Optional[List[str]] = None, |
|
284 | preferences: Optional[dict] = None, |
|
285 | ) -> Any: |
|
286 | """Modifies an existing task. |
|
287 | ||
288 | Arguments: |
|
289 | audit_id: UUID of audit to modify. |
|
290 | name: The name of the audit. |
|
291 | policy_id: UUID of policy to use by the audit |
|
292 | target_id: UUID of target to be scanned |
|
293 | scanner_id: UUID of scanner to use for scanning the target |
|
294 | comment: The comment on the audit. |
|
295 | alert_ids: List of UUIDs for alerts to be applied to the audit |
|
296 | hosts_ordering: The order hosts are scanned in |
|
297 | schedule_id: UUID of a schedule when the audit should be run. |
|
298 | schedule_periods: A limit to the number of times the audit will be |
|
299 | scheduled, or 0 for no limit. |
|
300 | observers: List of names or ids of users which should be allowed to |
|
301 | observe this audit |
|
302 | preferences: Name/Value pairs of scanner preferences. |
|
303 | ||
304 | Returns: |
|
305 | The response. See :py:meth:`send_command` for details. |
|
306 | """ |
|
307 | if not audit_id: |
|
308 | raise RequiredArgument( |
|
309 | function=self.modify_task.__name__, argument='task_id argument' |
|
310 | ) |
|
311 | ||
312 | cmd = XmlCommand("modify_task") |
|
313 | cmd.set_attribute("task_id", audit_id) |
|
314 | ||
315 | if name: |
|
316 | cmd.add_element("name", name) |
|
317 | ||
318 | if comment: |
|
319 | cmd.add_element("comment", comment) |
|
320 | ||
321 | if policy_id: |
|
322 | cmd.add_element("config", attrs={"id": policy_id}) |
|
323 | ||
324 | if target_id: |
|
325 | cmd.add_element("target", attrs={"id": target_id}) |
|
326 | ||
327 | if alterable is not None: |
|
328 | cmd.add_element("alterable", to_bool(alterable)) |
|
329 | ||
330 | if hosts_ordering: |
|
331 | if not isinstance(hosts_ordering, HostsOrdering): |
|
332 | raise InvalidArgumentType( |
|
333 | function=self.modify_task.__name__, |
|
334 | argument='hosts_ordering', |
|
335 | arg_type=HostsOrdering.__name__, |
|
336 | ) |
|
337 | cmd.add_element("hosts_ordering", hosts_ordering.value) |
|
338 | ||
339 | if scanner_id: |
|
340 | cmd.add_element("scanner", attrs={"id": scanner_id}) |
|
341 | ||
342 | if schedule_id: |
|
343 | cmd.add_element("schedule", attrs={"id": schedule_id}) |
|
344 | ||
345 | if schedule_periods is not None: |
|
346 | if ( |
|
347 | not isinstance(schedule_periods, Integral) |
|
348 | or schedule_periods < 0 |
|
349 | ): |
|
350 | raise InvalidArgument( |
|
351 | "schedule_periods must be an integer greater or equal " |
|
352 | "than 0" |
|
353 | ) |
|
354 | cmd.add_element("schedule_periods", str(schedule_periods)) |
|
355 | ||
356 | if alert_ids is not None: |
|
357 | if not is_list_like(alert_ids): |
|
358 | raise InvalidArgumentType( |
|
359 | function=self.modify_task.__name__, |
|
360 | argument='alert_ids', |
|
361 | arg_type='list', |
|
362 | ) |
|
363 | ||
364 | if len(alert_ids) == 0: |
|
365 | cmd.add_element("alert", attrs={"id": "0"}) |
|
366 | else: |
|
367 | for alert in alert_ids: |
|
368 | cmd.add_element("alert", attrs={"id": str(alert)}) |
|
369 | ||
370 | if observers is not None: |
|
371 | if not is_list_like(observers): |
|
372 | raise InvalidArgumentType( |
|
373 | function=self.modify_task.__name__, |
|
374 | argument='observers', |
|
375 | arg_type='list', |
|
376 | ) |
|
377 | ||
378 | cmd.add_element("observers", to_comma_list(observers)) |
|
379 | ||
380 | if preferences is not None: |
|
381 | if not isinstance(preferences, Mapping): |
|
382 | raise InvalidArgumentType( |
|
383 | function=self.modify_task.__name__, |
|
384 | argument='preferences', |
|
385 | arg_type=Mapping.__name__, |
|
386 | ) |
|
387 | ||
388 | _xmlprefs = cmd.add_element("preferences") |
|
389 | for pref_name, pref_value in preferences.items(): |
|
390 | _xmlpref = _xmlprefs.add_element("preference") |
|
391 | _xmlpref.add_element("scanner_name", pref_name) |
|
392 | _xmlpref.add_element("value", str(pref_value)) |
|
393 | ||
394 | return self._send_xml_command(cmd) |
|
395 | ||
396 | def resume_audit(self, audit_id: str) -> Any: |
|
397 | """Resume an existing stopped audit |