Code Duplication    Length = 93-98 lines in 3 locations

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 6079-6176 (lines=98) @@
6076
6077
        return self._send_xml_command(cmd)
6078
6079
    def modify_user(
6080
        self,
6081
        user_id: str = None,
6082
        name: str = None,
6083
        *,
6084
        new_name: Optional[str] = None,
6085
        comment: Optional[str] = None,
6086
        password: Optional[str] = None,
6087
        auth_source: Optional[UserAuthType] = None,
6088
        role_ids: Optional[List[str]] = None,
6089
        hosts: Optional[List[str]] = None,
6090
        hosts_allow: Optional[bool] = False,
6091
        ifaces: Optional[List[str]] = None,
6092
        ifaces_allow: Optional[bool] = False,
6093
        group_ids: Optional[List[str]] = None,
6094
    ) -> Any:
6095
        """Modifies an existing user. Most of the fields need to be supplied
6096
        for changing a single field even if no change is wanted for those.
6097
        Else empty values are inserted for the missing fields instead.
6098
6099
        Arguments:
6100
            user_id: UUID of the user to be modified. Overrides name element
6101
                argument.
6102
            name: The name of the user to be modified. Either user_id or name
6103
                must be passed.
6104
            new_name: The new name for the user.
6105
            comment: Comment on the user.
6106
            password: The password for the user.
6107
            auth_source: Source allowed for authentication for this user.
6108
            roles_id: List of roles UUIDs for the user.
6109
            hosts: User access rules: List of hosts.
6110
            hosts_allow: Defines how the hosts list is to be interpreted.
6111
                If False (default) the list is treated as a deny list.
6112
                All hosts are allowed by default except those provided by
6113
                the hosts parameter. If True the list is treated as a
6114
                allow list. All hosts are denied by default except those
6115
                provided by the hosts parameter.
6116
            ifaces: User access rules: List of ifaces.
6117
            ifaces_allow: Defines how the ifaces list is to be interpreted.
6118
                If False (default) the list is treated as a deny list.
6119
                All ifaces are allowed by default except those provided by
6120
                the ifaces parameter. If True the list is treated as a
6121
                allow list. All ifaces are denied by default except those
6122
                provided by the ifaces parameter.
6123
            group_ids: List of group UUIDs for the user.
6124
6125
        Returns:
6126
            The response. See :py:meth:`send_command` for details.
6127
        """
6128
        if not user_id and not name:
6129
            raise RequiredArgument(
6130
                function=self.modify_user.__name__, argument='user_id or name'
6131
            )
6132
6133
        cmd = XmlCommand("modify_user")
6134
6135
        if user_id:
6136
            cmd.set_attribute("user_id", user_id)
6137
        else:
6138
            cmd.add_element("name", name)
6139
6140
        if new_name:
6141
            cmd.add_element("new_name", new_name)
6142
6143
        if role_ids:
6144
            for role in role_ids:
6145
                cmd.add_element("role", attrs={"id": role})
6146
6147
        if hosts:
6148
            cmd.add_element(
6149
                "hosts",
6150
                _to_comma_list(hosts),
6151
                attrs={"allow": _to_bool(hosts_allow)},
6152
            )
6153
6154
        if ifaces:
6155
            cmd.add_element(
6156
                "ifaces",
6157
                _to_comma_list(ifaces),
6158
                attrs={"allow": _to_bool(ifaces_allow)},
6159
            )
6160
6161
        if comment:
6162
            cmd.add_element("comment", comment)
6163
6164
        if password:
6165
            cmd.add_element("password", password)
6166
6167
        if auth_source:
6168
            _xmlauthsrc = cmd.add_element("sources")
6169
            _xmlauthsrc.add_element("source", auth_source.value)
6170
6171
        if group_ids:
6172
            _xmlgroups = cmd.add_element("groups")
6173
            for group_id in group_ids:
6174
                _xmlgroups.add_element("group", attrs={"id": group_id})
6175
6176
        return self._send_xml_command(cmd)
6177
6178
    def move_task(self, task_id: str, *, slave_id: Optional[str] = None) -> Any:
6179
        """Move an existing task to another GMP slave scanner or the master

gvm/protocols/gmpv214/gmpv214.py 1 location

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

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 7040-7137 (lines=98) @@
7037
7038
        return self._send_xml_command(cmd)
7039
7040
    def modify_user(
7041
        self,
7042
        user_id: str = None,
7043
        name: str = None,
7044
        *,
7045
        new_name: Optional[str] = None,
7046
        comment: Optional[str] = None,
7047
        password: Optional[str] = None,
7048
        auth_source: Optional[UserAuthType] = None,
7049
        role_ids: Optional[List[str]] = None,
7050
        hosts: Optional[List[str]] = None,
7051
        hosts_allow: Optional[bool] = False,
7052
        ifaces: Optional[List[str]] = None,
7053
        ifaces_allow: Optional[bool] = False,
7054
        group_ids: Optional[List[str]] = None,
7055
    ) -> Any:
7056
        """Modifies an existing user. Most of the fields need to be supplied
7057
        for changing a single field even if no change is wanted for those.
7058
        Else empty values are inserted for the missing fields instead.
7059
7060
        Arguments:
7061
            user_id: UUID of the user to be modified. Overrides name element
7062
                argument.
7063
            name: The name of the user to be modified. Either user_id or name
7064
                must be passed.
7065
            new_name: The new name for the user.
7066
            comment: Comment on the user.
7067
            password: The password for the user.
7068
            auth_source: Source allowed for authentication for this user.
7069
            roles_id: List of roles UUIDs for the user.
7070
            hosts: User access rules: List of hosts.
7071
            hosts_allow: Defines how the hosts list is to be interpreted.
7072
                If False (default) the list is treated as a deny list.
7073
                All hosts are allowed by default except those provided by
7074
                the hosts parameter. If True the list is treated as a
7075
                allow list. All hosts are denied by default except those
7076
                provided by the hosts parameter.
7077
            ifaces: User access rules: List of ifaces.
7078
            ifaces_allow: Defines how the ifaces list is to be interpreted.
7079
                If False (default) the list is treated as a deny list.
7080
                All ifaces are allowed by default except those provided by
7081
                the ifaces parameter. If True the list is treated as a
7082
                allow list. All ifaces are denied by default except those
7083
                provided by the ifaces parameter.
7084
            group_ids: List of group UUIDs for the user.
7085
7086
        Returns:
7087
            The response. See :py:meth:`send_command` for details.
7088
        """
7089
        if not user_id and not name:
7090
            raise RequiredArgument(
7091
                function=self.modify_user.__name__, argument='user_id or name'
7092
            )
7093
7094
        cmd = XmlCommand("modify_user")
7095
7096
        if user_id:
7097
            cmd.set_attribute("user_id", user_id)
7098
        else:
7099
            cmd.add_element("name", name)
7100
7101
        if new_name:
7102
            cmd.add_element("new_name", new_name)
7103
7104
        if role_ids:
7105
            for role in role_ids:
7106
                cmd.add_element("role", attrs={"id": role})
7107
7108
        if hosts:
7109
            cmd.add_element(
7110
                "hosts",
7111
                _to_comma_list(hosts),
7112
                attrs={"allow": _to_bool(hosts_allow)},
7113
            )
7114
7115
        if ifaces:
7116
            cmd.add_element(
7117
                "ifaces",
7118
                _to_comma_list(ifaces),
7119
                attrs={"allow": _to_bool(ifaces_allow)},
7120
            )
7121
7122
        if comment:
7123
            cmd.add_element("comment", comment)
7124
7125
        if password:
7126
            cmd.add_element("password", password)
7127
7128
        if auth_source:
7129
            _xmlauthsrc = cmd.add_element("sources")
7130
            _xmlauthsrc.add_element("source", auth_source.value)
7131
7132
        if group_ids:
7133
            _xmlgroups = cmd.add_element("groups")
7134
            for group_id in group_ids:
7135
                _xmlgroups.add_element("group", attrs={"id": group_id})
7136
7137
        return self._send_xml_command(cmd)
7138
7139
    def move_task(self, task_id: str, *, slave_id: Optional[str] = None) -> Any:
7140
        """Move an existing task to another GMP slave scanner or the master