Code Duplication    Length = 32-32 lines in 2 locations

gvm/protocols/gmpv7/__init__.py 1 location

@@ 636-667 (lines=32) @@
633
            _xmlkey = cmd.add_element("key")
634
            _xmlkey.add_element("private", private_key)
635
636
        if credential_type == CredentialType.SNMP:
637
            if not isinstance(auth_algorithm, SnmpAuthAlgorithm):
638
                raise InvalidArgument(
639
                    "create_credential requires auth_algorithm to be a "
640
                    "SnmpAuthAlgorithm instance",
641
                    function="create_credential",
642
                    argument="auth_algorithm",
643
                )
644
645
            cmd.add_element("auth_algorithm", auth_algorithm.value)
646
647
            if community:
648
                cmd.add_element("community", community)
649
650
            if privacy_algorithm is not None or privacy_password:
651
                _xmlprivacy = cmd.add_element("privacy")
652
653
                if privacy_algorithm is not None:
654
                    if not isinstance(privacy_algorithm, SnmpPrivacyAlgorithm):
655
                        raise InvalidArgument(
656
                            "create_credential requires algorithm to be a "
657
                            "SnmpPrivacyAlgorithm instance",
658
                            function="create_credential",
659
                            argument="privacy_algorithm",
660
                        )
661
662
                    _xmlprivacy.add_element(
663
                        "algorithm", privacy_algorithm.value
664
                    )
665
666
                if privacy_password:
667
                    _xmlprivacy.add_element("password", privacy_password)
668
669
        return self._send_xml_command(cmd)
670

gvm/protocols/gmpv8/__init__.py 1 location

@@ 270-301 (lines=32) @@
267
            _xmlkey = cmd.add_element("key")
268
            _xmlkey.add_element("private", private_key)
269
270
        if credential_type == CredentialType.SNMP:
271
            if not isinstance(auth_algorithm, SnmpAuthAlgorithm):
272
                raise InvalidArgument(
273
                    "create_credential requires auth_algorithm to be a "
274
                    "SnmpAuthAlgorithm instance",
275
                    function="create_credential",
276
                    argument="auth_algorithm",
277
                )
278
279
            cmd.add_element("auth_algorithm", auth_algorithm.value)
280
281
            if community:
282
                cmd.add_element("community", community)
283
284
            if privacy_algorithm is not None or privacy_password:
285
                _xmlprivacy = cmd.add_element("privacy")
286
287
                if privacy_algorithm is not None:
288
                    if not isinstance(privacy_algorithm, SnmpPrivacyAlgorithm):
289
                        raise InvalidArgument(
290
                            "create_credential requires algorithm to be a "
291
                            "SnmpPrivacyAlgorithm instance",
292
                            function="create_credential",
293
                            argument="privacy_algorithm",
294
                        )
295
296
                    _xmlprivacy.add_element(
297
                        "algorithm", privacy_algorithm.value
298
                    )
299
300
                if privacy_password:
301
                    _xmlprivacy.add_element("password", privacy_password)
302
303
        if credential_type == CredentialType.PGP_ENCRYPTION_KEY:
304
            if not public_key: