Code Duplication    Length = 30-32 lines in 2 locations

gvm/protocols/gmpv8/gmpv8.py 1 location

@@ 261-292 (lines=32) @@
258
            _xmlkey = cmd.add_element("key")
259
            _xmlkey.add_element("private", private_key)
260
261
        if credential_type == CredentialType.SNMP:
262
            if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm):
263
                raise InvalidArgumentType(
264
                    function=self.create_credential.__name__,
265
                    argument='auth_algorithm',
266
                    arg_type=SnmpAuthAlgorithm.__name__,
267
                )
268
269
            cmd.add_element("auth_algorithm", auth_algorithm.value)
270
271
            if community:
272
                cmd.add_element("community", community)
273
274
            if privacy_algorithm is not None or privacy_password:
275
                _xmlprivacy = cmd.add_element("privacy")
276
277
                if privacy_algorithm is not None:
278
                    if not isinstance(
279
                        privacy_algorithm, self.types.SnmpPrivacyAlgorithm
280
                    ):
281
                        raise InvalidArgumentType(
282
                            function=self.create_credential.__name__,
283
                            argument='privacy_algorithm',
284
                            arg_type=SnmpPrivacyAlgorithm.__name__,
285
                        )
286
287
                    _xmlprivacy.add_element(
288
                        "algorithm", privacy_algorithm.value
289
                    )
290
291
                if privacy_password:
292
                    _xmlprivacy.add_element("password", privacy_password)
293
294
        if credential_type == CredentialType.PGP_ENCRYPTION_KEY:
295
            if not public_key:

gvm/protocols/gmpv7/gmpv7.py 1 location

@@ 687-716 (lines=30) @@
684
            _xmlkey = cmd.add_element("key")
685
            _xmlkey.add_element("private", private_key)
686
687
        if credential_type == CredentialType.SNMP:
688
            if not isinstance(auth_algorithm, SnmpAuthAlgorithm):
689
                raise InvalidArgumentType(
690
                    function=self.create_credential.__name__,
691
                    argument="auth_algorithm",
692
                    arg_type=SnmpAuthAlgorithm.__name__,
693
                )
694
695
            cmd.add_element("auth_algorithm", auth_algorithm.value)
696
697
            if community:
698
                cmd.add_element("community", community)
699
700
            if privacy_algorithm is not None or privacy_password:
701
                _xmlprivacy = cmd.add_element("privacy")
702
703
                if privacy_algorithm is not None:
704
                    if not isinstance(privacy_algorithm, SnmpPrivacyAlgorithm):
705
                        raise InvalidArgumentType(
706
                            function=self.create_credential.__name__,
707
                            argument="privacy_algorithm",
708
                            arg_type=SnmpPrivacyAlgorithm.__name__,
709
                        )
710
711
                    _xmlprivacy.add_element(
712
                        "algorithm", privacy_algorithm.value
713
                    )
714
715
                if privacy_password:
716
                    _xmlprivacy.add_element("password", privacy_password)
717
718
        return self._send_xml_command(cmd)
719