Code Duplication    Length = 38-42 lines in 2 locations

gvm/protocols/gmpv9/gmpv9.py 2 locations

@@ 448-489 (lines=42) @@
445
            preferences=preferences,
446
        )
447
448
    def create_tls_certificate(
449
        self,
450
        name: str,
451
        certificate: str,
452
        *,
453
        comment: Optional[str] = None,
454
        trust: Optional[bool] = None
455
    ) -> Any:
456
        """Create a new TLS certificate
457
458
        Arguments:
459
            name: Name of the TLS certificate, defaulting to the MD5
460
                fingerprint.
461
            certificate: The Base64 encoded certificate data (x.509 DER or PEM).
462
            comment: Comment for the TLS certificate.
463
            trust: Whether the certificate is trusted.
464
465
        Returns:
466
            The response. See :py:meth:`send_command` for details.
467
        """
468
        if not name:
469
            raise RequiredArgument(
470
                function=self.create_tls_certificate.__name__, argument='name'
471
            )
472
        if not certificate:
473
            raise RequiredArgument(
474
                function=self.create_tls_certificate.__name__,
475
                argument='certificate',
476
            )
477
478
        cmd = XmlCommand("create_tls_certificate")
479
480
        if comment:
481
            cmd.add_element("comment", comment)
482
483
        cmd.add_element("name", name)
484
        cmd.add_element("certificate", certificate)
485
486
        if trust:
487
            cmd.add_element("trust", _to_bool(trust))
488
489
        return self._send_xml_command(cmd)
490
491
    def get_tls_certificates(
492
        self,
@@ 660-697 (lines=38) @@
657
658
        return self._send_xml_command(cmd)
659
660
    def modify_tls_certificate(
661
        self,
662
        tls_certificate_id: str,
663
        *,
664
        name: Optional[str] = None,
665
        comment: Optional[str] = None,
666
        trust: Optional[bool] = None
667
    ) -> Any:
668
        """Modifies an existing TLS certificate.
669
670
        Arguments:
671
            tls_certificate_id: UUID of the TLS certificate to be modified.
672
            name: Name of the TLS certificate, defaulting to the MD5 fingerprint
673
            comment: Comment for the TLS certificate.
674
            trust: Whether the certificate is trusted.
675
676
        Returns:
677
            The response. See :py:meth:`send_command` for details.
678
        """
679
        if not tls_certificate_id:
680
            raise RequiredArgument(
681
                function=self.modify_tls_certificate.__name__,
682
                argument='tls_certificate_id',
683
            )
684
685
        cmd = XmlCommand("modify_tls_certificate")
686
        cmd.set_attribute("tls_certificate_id", str(tls_certificate_id))
687
688
        if comment:
689
            cmd.add_element("comment", comment)
690
691
        if name:
692
            cmd.add_element("name", name)
693
694
        if trust:
695
            cmd.add_element("trust", _to_bool(trust))
696
697
        return self._send_xml_command(cmd)
698
699
    def clone_tls_certificate(self, tls_certificate_id: str) -> Any:
700
        """Modifies an existing TLS certificate.