Code Duplication    Length = 93-98 lines in 2 locations

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 5135-5232 (lines=98) @@
5132
5133
        return self._send_xml_command(cmd)
5134
5135
    def modify_user(
5136
        self,
5137
        user_id: str = None,
5138
        name: str = None,
5139
        *,
5140
        new_name: Optional[str] = None,
5141
        comment: Optional[str] = None,
5142
        password: Optional[str] = None,
5143
        auth_source: Optional[UserAuthType] = None,
5144
        role_ids: Optional[List[str]] = None,
5145
        hosts: Optional[List[str]] = None,
5146
        hosts_allow: Optional[bool] = False,
5147
        ifaces: Optional[List[str]] = None,
5148
        ifaces_allow: Optional[bool] = False,
5149
        group_ids: Optional[List[str]] = None,
5150
    ) -> Any:
5151
        """Modifies an existing user. Most of the fields need to be supplied
5152
        for changing a single field even if no change is wanted for those.
5153
        Else empty values are inserted for the missing fields instead.
5154
        Arguments:
5155
            user_id: UUID of the user to be modified. Overrides name element
5156
                argument.
5157
            name: The name of the user to be modified. Either user_id or name
5158
                must be passed.
5159
            new_name: The new name for the user.
5160
            comment: Comment on the user.
5161
            password: The password for the user.
5162
            auth_source: Source allowed for authentication for this user.
5163
            roles_id: List of roles UUIDs for the user.
5164
            hosts: User access rules: List of hosts.
5165
            hosts_allow: Defines how the hosts list is to be interpreted.
5166
                If False (default) the list is treated as a deny list.
5167
                All hosts are allowed by default except those provided by
5168
                the hosts parameter. If True the list is treated as a
5169
                allow list. All hosts are denied by default except those
5170
                provided by the hosts parameter.
5171
            ifaces: User access rules: List of ifaces.
5172
            ifaces_allow: Defines how the ifaces list is to be interpreted.
5173
                If False (default) the list is treated as a deny list.
5174
                All ifaces are allowed by default except those provided by
5175
                the ifaces parameter. If True the list is treated as a
5176
                allow list. All ifaces are denied by default except those
5177
                provided by the ifaces parameter.
5178
            group_ids: List of group UUIDs for the user.
5179
5180
        Returns:
5181
            The response. See :py:meth:`send_command` for details.
5182
        """
5183
        if not user_id and not name:
5184
            raise RequiredArgument(
5185
                function=self.modify_user.__name__, argument='user_id or name'
5186
            )
5187
5188
        cmd = XmlCommand("modify_user")
5189
5190
        if user_id:
5191
            cmd.set_attribute("user_id", user_id)
5192
        else:
5193
            cmd.add_element("name", name)
5194
5195
        if new_name:
5196
            cmd.add_element("new_name", new_name)
5197
5198
        if role_ids:
5199
            for role in role_ids:
5200
                cmd.add_element("role", attrs={"id": role})
5201
5202
        if hosts:
5203
            cmd.add_element(
5204
                "hosts",
5205
                to_comma_list(hosts),
5206
                attrs={"allow": to_bool(hosts_allow)},
5207
            )
5208
5209
        if ifaces:
5210
            cmd.add_element(
5211
                "ifaces",
5212
                to_comma_list(ifaces),
5213
                attrs={"allow": to_bool(ifaces_allow)},
5214
            )
5215
5216
        if comment:
5217
            cmd.add_element("comment", comment)
5218
5219
        if password:
5220
            cmd.add_element("password", password)
5221
5222
        if auth_source:
5223
            _xmlauthsrc = cmd.add_element("sources")
5224
            _xmlauthsrc.add_element("source", auth_source.value)
5225
5226
        if group_ids:
5227
            _xmlgroups = cmd.add_element("groups")
5228
            for group_id in group_ids:
5229
                _xmlgroups.add_element("group", attrs={"id": group_id})
5230
5231
        return self._send_xml_command(cmd)
5232
5233
    def restore(self, entity_id: str) -> Any:
5234
        """Restore an entity from the trashcan
5235

gvm/protocols/gmpv214/gmpv214.py 1 location

@@ 61-153 (lines=93) @@
58
        # Is authenticated on gvmd
59
        self._authenticated = False
60
61
    def modify_user(
62
        self,
63
        user_id: str = None,
64
        *,
65
        name: Optional[str] = None,
66
        comment: Optional[str] = None,
67
        password: Optional[str] = None,
68
        auth_source: Optional[UserAuthType] = None,
69
        role_ids: Optional[List[str]] = None,
70
        hosts: Optional[List[str]] = None,
71
        hosts_allow: Optional[bool] = False,
72
        ifaces: Optional[List[str]] = None,
73
        ifaces_allow: Optional[bool] = False,
74
        group_ids: Optional[List[str]] = None,
75
    ) -> Any:
76
77
        """Modifies an existing user. Most of the fields need to be supplied
78
        for changing a single field even if no change is wanted for those.
79
        Else empty values are inserted for the missing fields instead.
80
81
        Arguments:
82
            user_id: UUID of the user to be modified.
83
            name: The new name for the user.
84
            comment: Comment on the user.
85
            password: The password for the user.
86
            auth_source: Source allowed for authentication for this user.
87
            roles_id: List of roles UUIDs for the user.
88
            hosts: User access rules: List of hosts.
89
            hosts_allow: Defines how the hosts list is to be interpreted.
90
                If False (default) the list is treated as a deny list.
91
                All hosts are allowed by default except those provided by
92
                the hosts parameter. If True the list is treated as a
93
                allow list. All hosts are denied by default except those
94
                provided by the hosts parameter.
95
            ifaces: User access rules: List of ifaces.
96
            ifaces_allow: Defines how the ifaces list is to be interpreted.
97
                If False (default) the list is treated as a deny list.
98
                All ifaces are allowed by default except those provided by
99
                the ifaces parameter. If True the list is treated as a
100
                allow list. All ifaces are denied by default except those
101
                provided by the ifaces parameter.
102
            group_ids: List of group UUIDs for the user.
103
104
        Returns:
105
            The response. See :py:meth:`send_command` for details.
106
        """
107
        if not user_id:
108
            raise RequiredArgument(
109
                function=self.modify_user.__name__, argument='user_id'
110
            )
111
112
        cmd = XmlCommand("modify_user")
113
114
        if user_id:
115
            cmd.set_attribute("user_id", user_id)
116
117
        if name:
118
            cmd.add_element("new_name", name)
119
120
        if role_ids:
121
            for role in role_ids:
122
                cmd.add_element("role", attrs={"id": role})
123
124
        if hosts:
125
            cmd.add_element(
126
                "hosts",
127
                to_comma_list(hosts),
128
                attrs={"allow": to_bool(hosts_allow)},
129
            )
130
131
        if ifaces:
132
            cmd.add_element(
133
                "ifaces",
134
                to_comma_list(ifaces),
135
                attrs={"allow": to_bool(ifaces_allow)},
136
            )
137
138
        if comment:
139
            cmd.add_element("comment", comment)
140
141
        if password:
142
            cmd.add_element("password", password)
143
144
        if auth_source:
145
            _xmlauthsrc = cmd.add_element("sources")
146
            _xmlauthsrc.add_element("source", auth_source.value)
147
148
        if group_ids:
149
            _xmlgroups = cmd.add_element("groups")
150
            for group_id in group_ids:
151
                _xmlgroups.add_element("group", attrs={"id": group_id})
152
153
        return self._send_xml_command(cmd)
154