Code Duplication    Length = 113-113 lines in 2 locations

gvm/protocols/gmpv8/gmpv8.py 1 location

@@ 306-418 (lines=113) @@
303
304
        return self._send_xml_command(cmd)
305
306
    def modify_credential(
307
        self,
308
        credential_id: str,
309
        *,
310
        name: Optional[str] = None,
311
        comment: Optional[str] = None,
312
        allow_insecure: Optional[bool] = None,
313
        certificate: Optional[str] = None,
314
        key_phrase: Optional[str] = None,
315
        private_key: Optional[str] = None,
316
        login: Optional[str] = None,
317
        password: Optional[str] = None,
318
        auth_algorithm: Optional[SnmpAuthAlgorithm] = None,
319
        community: Optional[str] = None,
320
        privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None,
321
        privacy_password: Optional[str] = None,
322
        public_key: Optional[str] = None,
323
    ) -> Any:
324
        """Modifies an existing credential.
325
326
        Arguments:
327
            credential_id: UUID of the credential
328
            name: Name of the credential
329
            comment: Comment for the credential
330
            allow_insecure: Whether to allow insecure use of the credential
331
            certificate: Certificate for the credential
332
            key_phrase: Key passphrase for the private key
333
            private_key: Private key to use for login
334
            login: Username for the credential
335
            password: Password for the credential
336
            auth_algorithm: The authentication algorithm for SNMP
337
            community: The SNMP community
338
            privacy_algorithm: The privacy algorithm for SNMP
339
            privacy_password: The SNMP privacy password
340
            public_key: PGP public key in *armor* plain text format
341
342
        Returns:
343
            The response. See :py:meth:`send_command` for details.
344
        """
345
        if not credential_id:
346
            raise RequiredArgument(
347
                function=self.modify_credential.__name__,
348
                argument='credential_id',
349
            )
350
351
        cmd = XmlCommand("modify_credential")
352
        cmd.set_attribute("credential_id", credential_id)
353
354
        if comment:
355
            cmd.add_element("comment", comment)
356
357
        if name:
358
            cmd.add_element("name", name)
359
360
        if allow_insecure is not None:
361
            cmd.add_element("allow_insecure", _to_bool(allow_insecure))
362
363
        if certificate:
364
            cmd.add_element("certificate", certificate)
365
366
        if key_phrase and private_key:
367
            _xmlkey = cmd.add_element("key")
368
            _xmlkey.add_element("phrase", key_phrase)
369
            _xmlkey.add_element("private", private_key)
370
        elif (not key_phrase and private_key) or (
371
            key_phrase and not private_key
372
        ):
373
            raise RequiredArgument(
374
                function=self.modify_credential.__name__,
375
                argument='key_phrase and private_key',
376
            )
377
378
        if login:
379
            cmd.add_element("login", login)
380
381
        if password:
382
            cmd.add_element("password", password)
383
384
        if auth_algorithm:
385
            if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm):
386
                raise InvalidArgumentType(
387
                    function=self.modify_credential.__name__,
388
                    argument='auth_algorithm',
389
                    arg_type=SnmpAuthAlgorithm.__name__,
390
                )
391
            cmd.add_element("auth_algorithm", auth_algorithm.value)
392
393
        if community:
394
            cmd.add_element("community", community)
395
396
        if privacy_algorithm is not None or privacy_password is not None:
397
            _xmlprivacy = cmd.add_element("privacy")
398
399
            if privacy_algorithm is not None:
400
                if not isinstance(
401
                    privacy_algorithm, self.types.SnmpPrivacyAlgorithm
402
                ):
403
                    raise InvalidArgumentType(
404
                        function=self.modify_credential.__name__,
405
                        argument='privacy_algorithm',
406
                        arg_type=SnmpPrivacyAlgorithm.__name__,
407
                    )
408
409
                _xmlprivacy.add_element("algorithm", privacy_algorithm.value)
410
411
            if privacy_password is not None:
412
                _xmlprivacy.add_element("password", privacy_password)
413
414
        if public_key:
415
            _xmlkey = cmd.add_element("key")
416
            _xmlkey.add_element("public", public_key)
417
418
        return self._send_xml_command(cmd)
419
420
    def create_tag(
421
        self,

gvm/protocols/gmpv208/gmpv208.py 1 location

@@ 2758-2870 (lines=113) @@
2755
2756
        return self._send_xml_command(cmd)
2757
2758
    def modify_credential(
2759
        self,
2760
        credential_id: str,
2761
        *,
2762
        name: Optional[str] = None,
2763
        comment: Optional[str] = None,
2764
        allow_insecure: Optional[bool] = None,
2765
        certificate: Optional[str] = None,
2766
        key_phrase: Optional[str] = None,
2767
        private_key: Optional[str] = None,
2768
        login: Optional[str] = None,
2769
        password: Optional[str] = None,
2770
        auth_algorithm: Optional[SnmpAuthAlgorithm] = None,
2771
        community: Optional[str] = None,
2772
        privacy_algorithm: Optional[SnmpPrivacyAlgorithm] = None,
2773
        privacy_password: Optional[str] = None,
2774
        public_key: Optional[str] = None,
2775
    ) -> Any:
2776
        """Modifies an existing credential.
2777
2778
        Arguments:
2779
            credential_id: UUID of the credential
2780
            name: Name of the credential
2781
            comment: Comment for the credential
2782
            allow_insecure: Whether to allow insecure use of the credential
2783
            certificate: Certificate for the credential
2784
            key_phrase: Key passphrase for the private key
2785
            private_key: Private key to use for login
2786
            login: Username for the credential
2787
            password: Password for the credential
2788
            auth_algorithm: The authentication algorithm for SNMP
2789
            community: The SNMP community
2790
            privacy_algorithm: The privacy algorithm for SNMP
2791
            privacy_password: The SNMP privacy password
2792
            public_key: PGP public key in *armor* plain text format
2793
2794
        Returns:
2795
            The response. See :py:meth:`send_command` for details.
2796
        """
2797
        if not credential_id:
2798
            raise RequiredArgument(
2799
                function=self.modify_credential.__name__,
2800
                argument='credential_id',
2801
            )
2802
2803
        cmd = XmlCommand("modify_credential")
2804
        cmd.set_attribute("credential_id", credential_id)
2805
2806
        if comment:
2807
            cmd.add_element("comment", comment)
2808
2809
        if name:
2810
            cmd.add_element("name", name)
2811
2812
        if allow_insecure is not None:
2813
            cmd.add_element("allow_insecure", _to_bool(allow_insecure))
2814
2815
        if certificate:
2816
            cmd.add_element("certificate", certificate)
2817
2818
        if key_phrase and private_key:
2819
            _xmlkey = cmd.add_element("key")
2820
            _xmlkey.add_element("phrase", key_phrase)
2821
            _xmlkey.add_element("private", private_key)
2822
        elif (not key_phrase and private_key) or (
2823
            key_phrase and not private_key
2824
        ):
2825
            raise RequiredArgument(
2826
                function=self.modify_credential.__name__,
2827
                argument='key_phrase and private_key',
2828
            )
2829
2830
        if login:
2831
            cmd.add_element("login", login)
2832
2833
        if password:
2834
            cmd.add_element("password", password)
2835
2836
        if auth_algorithm:
2837
            if not isinstance(auth_algorithm, self.types.SnmpAuthAlgorithm):
2838
                raise InvalidArgumentType(
2839
                    function=self.modify_credential.__name__,
2840
                    argument='auth_algorithm',
2841
                    arg_type=SnmpAuthAlgorithm.__name__,
2842
                )
2843
            cmd.add_element("auth_algorithm", auth_algorithm.value)
2844
2845
        if community:
2846
            cmd.add_element("community", community)
2847
2848
        if privacy_algorithm is not None or privacy_password is not None:
2849
            _xmlprivacy = cmd.add_element("privacy")
2850
2851
            if privacy_algorithm is not None:
2852
                if not isinstance(
2853
                    privacy_algorithm, self.types.SnmpPrivacyAlgorithm
2854
                ):
2855
                    raise InvalidArgumentType(
2856
                        function=self.modify_credential.__name__,
2857
                        argument='privacy_algorithm',
2858
                        arg_type=SnmpPrivacyAlgorithm.__name__,
2859
                    )
2860
2861
                _xmlprivacy.add_element("algorithm", privacy_algorithm.value)
2862
2863
            if privacy_password is not None:
2864
                _xmlprivacy.add_element("password", privacy_password)
2865
2866
        if public_key:
2867
            _xmlkey = cmd.add_element("key")
2868
            _xmlkey.add_element("public", public_key)
2869
2870
        return self._send_xml_command(cmd)
2871
2872
    def create_ticket(
2873
        self,