Code Duplication    Length = 57-57 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 4072-4128 (lines=57) @@
4069
        cmd.add_element("copy", task_id)
4070
        return self._send_xml_command(cmd)
4071
4072
    def create_user(
4073
        self,
4074
        name: str,
4075
        *,
4076
        password: Optional[str] = None,
4077
        hosts: Optional[List[str]] = None,
4078
        hosts_allow: Optional[bool] = False,
4079
        ifaces: Optional[List[str]] = None,
4080
        ifaces_allow: Optional[bool] = False,
4081
        role_ids: Optional[List[str]] = None,
4082
    ) -> Any:
4083
        """Create a new user
4084
4085
        Arguments:
4086
            name: Name of the user
4087
            password: Password of the user
4088
            hosts: A list of host addresses (IPs, DNS names)
4089
            hosts_allow: If True allow only access to passed hosts otherwise
4090
                deny access. Default is False for deny hosts.
4091
            ifaces: A list of interface names
4092
            ifaces_allow: If True allow only access to passed interfaces
4093
                otherwise deny access. Default is False for deny interfaces.
4094
            role_ids: A list of role UUIDs for the user
4095
4096
        Returns:
4097
            The response. See :py:meth:`send_command` for details.
4098
        """
4099
        if not name:
4100
            raise RequiredArgument(
4101
                function=self.create_user.__name__, argument='name'
4102
            )
4103
4104
        cmd = XmlCommand("create_user")
4105
        cmd.add_element("name", name)
4106
4107
        if password:
4108
            cmd.add_element("password", password)
4109
4110
        if hosts:
4111
            cmd.add_element(
4112
                "hosts",
4113
                _to_comma_list(hosts),
4114
                attrs={"allow": _to_bool(hosts_allow)},
4115
            )
4116
4117
        if ifaces:
4118
            cmd.add_element(
4119
                "ifaces",
4120
                _to_comma_list(ifaces),
4121
                attrs={"allow": _to_bool(ifaces_allow)},
4122
            )
4123
4124
        if role_ids:
4125
            for role in role_ids:
4126
                cmd.add_element("role", attrs={"id": role})
4127
4128
        return self._send_xml_command(cmd)
4129
4130
    def clone_user(self, user_id: str) -> Any:
4131
        """Clone an existing user

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 2175-2231 (lines=57) @@
2172
        cmd.add_element("copy", task_id)
2173
        return self._send_xml_command(cmd)
2174
2175
    def create_user(
2176
        self,
2177
        name: str,
2178
        *,
2179
        password: Optional[str] = None,
2180
        hosts: Optional[List[str]] = None,
2181
        hosts_allow: Optional[bool] = False,
2182
        ifaces: Optional[List[str]] = None,
2183
        ifaces_allow: Optional[bool] = False,
2184
        role_ids: Optional[List[str]] = None,
2185
    ) -> Any:
2186
        """Create a new user
2187
2188
        Arguments:
2189
            name: Name of the user
2190
            password: Password of the user
2191
            hosts: A list of host addresses (IPs, DNS names)
2192
            hosts_allow: If True allow only access to passed hosts otherwise
2193
                deny access. Default is False for deny hosts.
2194
            ifaces: A list of interface names
2195
            ifaces_allow: If True allow only access to passed interfaces
2196
                otherwise deny access. Default is False for deny interfaces.
2197
            role_ids: A list of role UUIDs for the user
2198
2199
        Returns:
2200
            The response. See :py:meth:`send_command` for details.
2201
        """
2202
        if not name:
2203
            raise RequiredArgument(
2204
                function=self.create_user.__name__, argument='name'
2205
            )
2206
2207
        cmd = XmlCommand("create_user")
2208
        cmd.add_element("name", name)
2209
2210
        if password:
2211
            cmd.add_element("password", password)
2212
2213
        if hosts:
2214
            cmd.add_element(
2215
                "hosts",
2216
                _to_comma_list(hosts),
2217
                attrs={"allow": _to_bool(hosts_allow)},
2218
            )
2219
2220
        if ifaces:
2221
            cmd.add_element(
2222
                "ifaces",
2223
                _to_comma_list(ifaces),
2224
                attrs={"allow": _to_bool(ifaces_allow)},
2225
            )
2226
2227
        if role_ids:
2228
            for role in role_ids:
2229
                cmd.add_element("role", attrs={"id": role})
2230
2231
        return self._send_xml_command(cmd)
2232
2233
    def clone_user(self, user_id: str) -> Any:
2234
        """Clone an existing user