Code Duplication    Length = 93-98 lines in 2 locations

gvm/protocols/gmpv214/gmpv214.py 1 location

@@ 623-715 (lines=93) @@
620
621
        return self._send_xml_command(cmd)
622
623
    def modify_user(
624
        self,
625
        user_id: str = None,
626
        *,
627
        name: Optional[str] = None,
628
        comment: Optional[str] = None,
629
        password: Optional[str] = None,
630
        auth_source: Optional[UserAuthType] = None,
631
        role_ids: Optional[List[str]] = None,
632
        hosts: Optional[List[str]] = None,
633
        hosts_allow: Optional[bool] = False,
634
        ifaces: Optional[List[str]] = None,
635
        ifaces_allow: Optional[bool] = False,
636
        group_ids: Optional[List[str]] = None,
637
    ) -> Any:
638
639
        """Modifies an existing user. Most of the fields need to be supplied
640
        for changing a single field even if no change is wanted for those.
641
        Else empty values are inserted for the missing fields instead.
642
643
        Arguments:
644
            user_id: UUID of the user to be modified.
645
            name: The new name for the user.
646
            comment: Comment on the user.
647
            password: The password for the user.
648
            auth_source: Source allowed for authentication for this user.
649
            roles_id: List of roles UUIDs for the user.
650
            hosts: User access rules: List of hosts.
651
            hosts_allow: Defines how the hosts list is to be interpreted.
652
                If False (default) the list is treated as a deny list.
653
                All hosts are allowed by default except those provided by
654
                the hosts parameter. If True the list is treated as a
655
                allow list. All hosts are denied by default except those
656
                provided by the hosts parameter.
657
            ifaces: User access rules: List of ifaces.
658
            ifaces_allow: Defines how the ifaces list is to be interpreted.
659
                If False (default) the list is treated as a deny list.
660
                All ifaces are allowed by default except those provided by
661
                the ifaces parameter. If True the list is treated as a
662
                allow list. All ifaces are denied by default except those
663
                provided by the ifaces parameter.
664
            group_ids: List of group UUIDs for the user.
665
666
        Returns:
667
            The response. See :py:meth:`send_command` for details.
668
        """
669
        if not user_id:
670
            raise RequiredArgument(
671
                function=self.modify_user.__name__, argument='user_id'
672
            )
673
674
        cmd = XmlCommand("modify_user")
675
676
        if user_id:
677
            cmd.set_attribute("user_id", user_id)
678
679
        if name:
680
            cmd.add_element("new_name", name)
681
682
        if role_ids:
683
            for role in role_ids:
684
                cmd.add_element("role", attrs={"id": role})
685
686
        if hosts:
687
            cmd.add_element(
688
                "hosts",
689
                to_comma_list(hosts),
690
                attrs={"allow": to_bool(hosts_allow)},
691
            )
692
693
        if ifaces:
694
            cmd.add_element(
695
                "ifaces",
696
                to_comma_list(ifaces),
697
                attrs={"allow": to_bool(ifaces_allow)},
698
            )
699
700
        if comment:
701
            cmd.add_element("comment", comment)
702
703
        if password:
704
            cmd.add_element("password", password)
705
706
        if auth_source:
707
            _xmlauthsrc = cmd.add_element("sources")
708
            _xmlauthsrc.add_element("source", auth_source.value)
709
710
        if group_ids:
711
            _xmlgroups = cmd.add_element("groups")
712
            for group_id in group_ids:
713
                _xmlgroups.add_element("group", attrs={"id": group_id})
714
715
        return self._send_xml_command(cmd)
716

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 6467-6564 (lines=98) @@
6464
6465
        return self._send_xml_command(cmd)
6466
6467
    def modify_user(
6468
        self,
6469
        user_id: str = None,
6470
        name: str = None,
6471
        *,
6472
        new_name: Optional[str] = None,
6473
        comment: Optional[str] = None,
6474
        password: Optional[str] = None,
6475
        auth_source: Optional[UserAuthType] = None,
6476
        role_ids: Optional[List[str]] = None,
6477
        hosts: Optional[List[str]] = None,
6478
        hosts_allow: Optional[bool] = False,
6479
        ifaces: Optional[List[str]] = None,
6480
        ifaces_allow: Optional[bool] = False,
6481
        group_ids: Optional[List[str]] = None,
6482
    ) -> Any:
6483
        """Modifies an existing user. Most of the fields need to be supplied
6484
        for changing a single field even if no change is wanted for those.
6485
        Else empty values are inserted for the missing fields instead.
6486
6487
        Arguments:
6488
            user_id: UUID of the user to be modified. Overrides name element
6489
                argument.
6490
            name: The name of the user to be modified. Either user_id or name
6491
                must be passed.
6492
            new_name: The new name for the user.
6493
            comment: Comment on the user.
6494
            password: The password for the user.
6495
            auth_source: Source allowed for authentication for this user.
6496
            roles_id: List of roles UUIDs for the user.
6497
            hosts: User access rules: List of hosts.
6498
            hosts_allow: Defines how the hosts list is to be interpreted.
6499
                If False (default) the list is treated as a deny list.
6500
                All hosts are allowed by default except those provided by
6501
                the hosts parameter. If True the list is treated as a
6502
                allow list. All hosts are denied by default except those
6503
                provided by the hosts parameter.
6504
            ifaces: User access rules: List of ifaces.
6505
            ifaces_allow: Defines how the ifaces list is to be interpreted.
6506
                If False (default) the list is treated as a deny list.
6507
                All ifaces are allowed by default except those provided by
6508
                the ifaces parameter. If True the list is treated as a
6509
                allow list. All ifaces are denied by default except those
6510
                provided by the ifaces parameter.
6511
            group_ids: List of group UUIDs for the user.
6512
6513
        Returns:
6514
            The response. See :py:meth:`send_command` for details.
6515
        """
6516
        if not user_id and not name:
6517
            raise RequiredArgument(
6518
                function=self.modify_user.__name__, argument='user_id or name'
6519
            )
6520
6521
        cmd = XmlCommand("modify_user")
6522
6523
        if user_id:
6524
            cmd.set_attribute("user_id", user_id)
6525
        else:
6526
            cmd.add_element("name", name)
6527
6528
        if new_name:
6529
            cmd.add_element("new_name", new_name)
6530
6531
        if role_ids:
6532
            for role in role_ids:
6533
                cmd.add_element("role", attrs={"id": role})
6534
6535
        if hosts:
6536
            cmd.add_element(
6537
                "hosts",
6538
                to_comma_list(hosts),
6539
                attrs={"allow": to_bool(hosts_allow)},
6540
            )
6541
6542
        if ifaces:
6543
            cmd.add_element(
6544
                "ifaces",
6545
                to_comma_list(ifaces),
6546
                attrs={"allow": to_bool(ifaces_allow)},
6547
            )
6548
6549
        if comment:
6550
            cmd.add_element("comment", comment)
6551
6552
        if password:
6553
            cmd.add_element("password", password)
6554
6555
        if auth_source:
6556
            _xmlauthsrc = cmd.add_element("sources")
6557
            _xmlauthsrc.add_element("source", auth_source.value)
6558
6559
        if group_ids:
6560
            _xmlgroups = cmd.add_element("groups")
6561
            for group_id in group_ids:
6562
                _xmlgroups.add_element("group", attrs={"id": group_id})
6563
6564
        return self._send_xml_command(cmd)
6565
6566
    def restore(self, entity_id: str) -> Any:
6567
        """Restore an entity from the trashcan