Code Duplication    Length = 85-85 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 607-691 (lines=85) @@
604
            function=self.create_policy.__name__,
605
        )
606
607
    def create_tag(
608
        self,
609
        name: str,
610
        resource_type: EntityType,
611
        *,
612
        resource_filter: Optional[str] = None,
613
        resource_ids: Optional[List[str]] = None,
614
        value: Optional[str] = None,
615
        comment: Optional[str] = None,
616
        active: Optional[bool] = None,
617
    ) -> Any:
618
        """Create a tag.
619
620
        Arguments:
621
            name: Name of the tag. A full tag name consisting of namespace and
622
                predicate e.g. `foo:bar`.
623
            resource_type: Entity type the tag is to be attached to.
624
            resource_filter: Filter term to select resources the tag is to be
625
                attached to. Only one of resource_filter or resource_ids can be
626
                provided.
627
            resource_ids: IDs of the resources the tag is to be attached to.
628
                Only one of resource_filter or resource_ids can be provided.
629
            value: Value associated with the tag.
630
            comment: Comment for the tag.
631
            active: Whether the tag should be active.
632
633
        Returns:
634
            The response. See :py:meth:`send_command` for details.
635
        """
636
        if not name:
637
            raise RequiredArgument(
638
                function=self.create_tag.__name__, argument='name'
639
            )
640
641
        if resource_filter and resource_ids:
642
            raise InvalidArgument(
643
                "create_tag accepts either resource_filter or resource_ids "
644
                "argument",
645
                function=self.create_tag.__name__,
646
            )
647
648
        if not resource_type:
649
            raise RequiredArgument(
650
                function=self.create_tag.__name__, argument='resource_type'
651
            )
652
653
        if not isinstance(resource_type, self.types.EntityType):
654
            raise InvalidArgumentType(
655
                function=self.create_tag.__name__,
656
                argument='resource_type',
657
                arg_type=EntityType.__name__,
658
            )
659
660
        cmd = XmlCommand('create_tag')
661
        cmd.add_element('name', name)
662
663
        _xmlresources = cmd.add_element("resources")
664
        if resource_filter is not None:
665
            _xmlresources.set_attribute("filter", resource_filter)
666
667
        for resource_id in resource_ids or []:
668
            _xmlresources.add_element(
669
                "resource", attrs={"id": str(resource_id)}
670
            )
671
672
        _actual_resource_type = resource_type
673
        if resource_type.value == EntityType.AUDIT.value:
674
            _actual_resource_type = EntityType.TASK
675
        elif resource_type.value == EntityType.POLICY.value:
676
            _actual_resource_type = EntityType.SCAN_CONFIG
677
        _xmlresources.add_element("type", _actual_resource_type.value)
678
679
        if comment:
680
            cmd.add_element("comment", comment)
681
682
        if value:
683
            cmd.add_element("value", value)
684
685
        if active is not None:
686
            if active:
687
                cmd.add_element("active", "1")
688
            else:
689
                cmd.add_element("active", "0")
690
691
        return self._send_xml_command(cmd)
692
693
    def create_task(
694
        self,

gvm/protocols/gmpv9/gmpv9.py 1 location

@@ 480-564 (lines=85) @@
477
            function=self.create_policy.__name__,
478
        )
479
480
    def create_tag(
481
        self,
482
        name: str,
483
        resource_type: EntityType,
484
        *,
485
        resource_filter: Optional[str] = None,
486
        resource_ids: Optional[List[str]] = None,
487
        value: Optional[str] = None,
488
        comment: Optional[str] = None,
489
        active: Optional[bool] = None,
490
    ) -> Any:
491
        """Create a tag.
492
493
        Arguments:
494
            name: Name of the tag. A full tag name consisting of namespace and
495
                predicate e.g. `foo:bar`.
496
            resource_type: Entity type the tag is to be attached to.
497
            resource_filter: Filter term to select resources the tag is to be
498
                attached to. Only one of resource_filter or resource_ids can be
499
                provided.
500
            resource_ids: IDs of the resources the tag is to be attached to.
501
                Only one of resource_filter or resource_ids can be provided.
502
            value: Value associated with the tag.
503
            comment: Comment for the tag.
504
            active: Whether the tag should be active.
505
506
        Returns:
507
            The response. See :py:meth:`send_command` for details.
508
        """
509
        if not name:
510
            raise RequiredArgument(
511
                function=self.create_tag.__name__, argument='name'
512
            )
513
514
        if resource_filter and resource_ids:
515
            raise InvalidArgument(
516
                "create_tag accepts either resource_filter or resource_ids "
517
                "argument",
518
                function=self.create_tag.__name__,
519
            )
520
521
        if not resource_type:
522
            raise RequiredArgument(
523
                function=self.create_tag.__name__, argument='resource_type'
524
            )
525
526
        if not isinstance(resource_type, self.types.EntityType):
527
            raise InvalidArgumentType(
528
                function=self.create_tag.__name__,
529
                argument='resource_type',
530
                arg_type=EntityType.__name__,
531
            )
532
533
        cmd = XmlCommand('create_tag')
534
        cmd.add_element('name', name)
535
536
        _xmlresources = cmd.add_element("resources")
537
        if resource_filter is not None:
538
            _xmlresources.set_attribute("filter", resource_filter)
539
540
        for resource_id in resource_ids or []:
541
            _xmlresources.add_element(
542
                "resource", attrs={"id": str(resource_id)}
543
            )
544
545
        _actual_resource_type = resource_type
546
        if resource_type.value == EntityType.AUDIT.value:
547
            _actual_resource_type = EntityType.TASK
548
        elif resource_type.value == EntityType.POLICY.value:
549
            _actual_resource_type = EntityType.SCAN_CONFIG
550
        _xmlresources.add_element("type", _actual_resource_type.value)
551
552
        if comment:
553
            cmd.add_element("comment", comment)
554
555
        if value:
556
            cmd.add_element("value", value)
557
558
        if active is not None:
559
            if active:
560
                cmd.add_element("active", "1")
561
            else:
562
                cmd.add_element("active", "0")
563
564
        return self._send_xml_command(cmd)
565
566
    def create_task(
567
        self,