Code Duplication    Length = 107-107 lines in 2 locations

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 4360-4466 (lines=107) @@
4357
4358
        return self._send_xml_command(cmd)
4359
4360
    def modify_alert(
4361
        self,
4362
        alert_id: str,
4363
        *,
4364
        name: Optional[str] = None,
4365
        comment: Optional[str] = None,
4366
        filter_id: Optional[str] = None,
4367
        event: Optional[AlertEvent] = None,
4368
        event_data: Optional[dict] = None,
4369
        condition: Optional[AlertCondition] = None,
4370
        condition_data: Optional[dict] = None,
4371
        method: Optional[AlertMethod] = None,
4372
        method_data: Optional[dict] = None
4373
    ) -> Any:
4374
        """Modifies an existing alert.
4375
4376
        Arguments:
4377
            alert_id: UUID of the alert to be modified.
4378
            name: Name of the Alert.
4379
            condition: The condition that must be satisfied for the alert to
4380
                occur. If the event is either 'Updated SecInfo
4381
                arrived' or 'New SecInfo arrived', condition must be 'Always'.
4382
                Otherwise, condition can also be on of 'Severity at least',
4383
                'Filter count changed' or 'Filter count at least'.
4384
            condition_data: Data that defines the condition
4385
            event: The event that must happen for the alert to occur, one of
4386
                'Task run status changed', 'Updated SecInfo arrived' or
4387
                'New SecInfo arrived'
4388
            event_data: Data that defines the event
4389
            method: The method by which the user is alerted, one of 'SCP',
4390
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email';
4391
                if the event is neither 'Updated SecInfo arrived' nor
4392
                'New SecInfo arrived', method can also be one of 'Start Task',
4393
                'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'.
4394
            method_data: Data that defines the method
4395
            filter_id: Filter to apply when executing alert
4396
            comment: Comment for the alert
4397
4398
        Returns:
4399
            The response. See :py:meth:`send_command` for details.
4400
        """
4401
4402
        if not alert_id:
4403
            raise RequiredArgument(
4404
                function=self.modify_alert.__name__, argument='alert_id'
4405
            )
4406
4407
        cmd = XmlCommand("modify_alert")
4408
        cmd.set_attribute("alert_id", str(alert_id))
4409
4410
        if name:
4411
            cmd.add_element("name", name)
4412
4413
        if comment:
4414
            cmd.add_element("comment", comment)
4415
4416
        if filter_id:
4417
            cmd.add_element("filter", attrs={"id": filter_id})
4418
4419
        if condition:
4420
            if not isinstance(condition, AlertCondition):
4421
                raise InvalidArgumentType(
4422
                    function=self.modify_alert.__name__,
4423
                    argument='condition',
4424
                    arg_type=AlertCondition.__name__,
4425
                )
4426
4427
            conditions = cmd.add_element("condition", condition.value)
4428
4429
            if condition_data is not None:
4430
                for key, value in condition_data.items():
4431
                    _data = conditions.add_element("data", value)
4432
                    _data.add_element("name", key)
4433
4434
        if method:
4435
            if not isinstance(method, AlertMethod):
4436
                raise InvalidArgumentType(
4437
                    function=self.modify_alert.__name__,
4438
                    argument='method',
4439
                    arg_type=AlertMethod.__name__,
4440
                )
4441
4442
            methods = cmd.add_element("method", method.value)
4443
4444
            if method_data is not None:
4445
                for key, value in method_data.items():
4446
                    _data = methods.add_element("data", value)
4447
                    _data.add_element("name", key)
4448
4449
        if event:
4450
            if not isinstance(event, AlertEvent):
4451
                raise InvalidArgumentType(
4452
                    function=self.modify_alert.__name__,
4453
                    argument='event',
4454
                    arg_type=AlertEvent.__name__,
4455
                )
4456
4457
            _check_event(event, condition, method)
4458
4459
            events = cmd.add_element("event", event.value)
4460
4461
            if event_data is not None:
4462
                for key, value in event_data.items():
4463
                    _data = events.add_element("data", value)
4464
                    _data.add_element("name", key)
4465
4466
        return self._send_xml_command(cmd)
4467
4468
    def modify_asset(self, asset_id: str, comment: Optional[str] = "") -> Any:
4469
        """Modifies an existing asset.

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 528-634 (lines=107) @@
525
526
        return self._send_xml_command(cmd)
527
528
    def modify_alert(
529
        self,
530
        alert_id: str,
531
        *,
532
        name: Optional[str] = None,
533
        comment: Optional[str] = None,
534
        filter_id: Optional[str] = None,
535
        event: Optional[AlertEvent] = None,
536
        event_data: Optional[dict] = None,
537
        condition: Optional[AlertCondition] = None,
538
        condition_data: Optional[dict] = None,
539
        method: Optional[AlertMethod] = None,
540
        method_data: Optional[dict] = None
541
    ) -> Any:
542
        """Modifies an existing alert.
543
544
        Arguments:
545
            alert_id: UUID of the alert to be modified.
546
            name: Name of the Alert.
547
            condition: The condition that must be satisfied for the alert to
548
                occur. If the event is either 'Updated SecInfo
549
                arrived' or 'New SecInfo arrived', condition must be 'Always'.
550
                Otherwise, condition can also be on of 'Severity at least',
551
                'Filter count changed' or 'Filter count at least'.
552
            condition_data: Data that defines the condition
553
            event: The event that must happen for the alert to occur, one of
554
                'Task run status changed', 'Updated SecInfo arrived' or
555
                'New SecInfo arrived'
556
            event_data: Data that defines the event
557
            method: The method by which the user is alerted, one of 'SCP',
558
                'Send', 'SMB', 'SNMP', 'Syslog' or 'Email';
559
                if the event is neither 'Updated SecInfo arrived' nor
560
                'New SecInfo arrived', method can also be one of 'Start Task',
561
                'HTTP Get', 'Sourcefire Connector' or 'verinice Connector'.
562
            method_data: Data that defines the method
563
            filter_id: Filter to apply when executing alert
564
            comment: Comment for the alert
565
566
        Returns:
567
            The response. See :py:meth:`send_command` for details.
568
        """
569
570
        if not alert_id:
571
            raise RequiredArgument(
572
                function=self.modify_alert.__name__, argument='alert_id'
573
            )
574
575
        cmd = XmlCommand("modify_alert")
576
        cmd.set_attribute("alert_id", str(alert_id))
577
578
        if name:
579
            cmd.add_element("name", name)
580
581
        if comment:
582
            cmd.add_element("comment", comment)
583
584
        if filter_id:
585
            cmd.add_element("filter", attrs={"id": filter_id})
586
587
        if condition:
588
            if not isinstance(condition, AlertCondition):
589
                raise InvalidArgumentType(
590
                    function=self.modify_alert.__name__,
591
                    argument='condition',
592
                    arg_type=AlertCondition.__name__,
593
                )
594
595
            conditions = cmd.add_element("condition", condition.value)
596
597
            if condition_data is not None:
598
                for key, value in condition_data.items():
599
                    _data = conditions.add_element("data", value)
600
                    _data.add_element("name", key)
601
602
        if method:
603
            if not isinstance(method, AlertMethod):
604
                raise InvalidArgumentType(
605
                    function=self.modify_alert.__name__,
606
                    argument='method',
607
                    arg_type=AlertMethod.__name__,
608
                )
609
610
            methods = cmd.add_element("method", method.value)
611
612
            if method_data is not None:
613
                for key, value in method_data.items():
614
                    _data = methods.add_element("data", value)
615
                    _data.add_element("name", key)
616
617
        if event:
618
            if not isinstance(event, AlertEvent):
619
                raise InvalidArgumentType(
620
                    function=self.modify_alert.__name__,
621
                    argument='event',
622
                    arg_type=AlertEvent.__name__,
623
                )
624
625
            _check_event(event, condition, method)
626
627
            events = cmd.add_element("event", event.value)
628
629
            if event_data is not None:
630
                for key, value in event_data.items():
631
                    _data = events.add_element("data", value)
632
                    _data.add_element("name", key)
633
634
        return self._send_xml_command(cmd)
635
636
    def modify_tls_certificate(
637
        self,