Code Duplication    Length = 85-85 lines in 2 locations

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,

gvm/protocols/gmpv208/gmpv208.py 1 location

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