Code Duplication    Length = 126-126 lines in 2 locations

gvm/protocols/gmpv208/entities/tasks.py 1 location

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

gvm/protocols/gmpv208/entities/audits.py 1 location

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