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

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