Code Duplication    Length = 38-42 lines in 2 locations

gvm/protocols/gmpv9/gmpv9.py 2 locations

@@ 618-659 (lines=42) @@
615
            preferences=preferences,
616
        )
617
618
    def create_tls_certificate(
619
        self,
620
        name: str,
621
        certificate: str,
622
        *,
623
        comment: Optional[str] = None,
624
        trust: Optional[bool] = None
625
    ) -> Any:
626
        """Create a new TLS certificate
627
628
        Arguments:
629
            name: Name of the TLS certificate, defaulting to the MD5
630
                fingerprint.
631
            certificate: The Base64 encoded certificate data (x.509 DER or PEM).
632
            comment: Comment for the TLS certificate.
633
            trust: Whether the certificate is trusted.
634
635
        Returns:
636
            The response. See :py:meth:`send_command` for details.
637
        """
638
        if not name:
639
            raise RequiredArgument(
640
                function=self.create_tls_certificate.__name__, argument='name'
641
            )
642
        if not certificate:
643
            raise RequiredArgument(
644
                function=self.create_tls_certificate.__name__,
645
                argument='certificate',
646
            )
647
648
        cmd = XmlCommand("create_tls_certificate")
649
650
        if comment:
651
            cmd.add_element("comment", comment)
652
653
        cmd.add_element("name", name)
654
        cmd.add_element("certificate", certificate)
655
656
        if trust:
657
            cmd.add_element("trust", _to_bool(trust))
658
659
        return self._send_xml_command(cmd)
660
661
    def get_aggregates(
662
        self,
@@ 1334-1371 (lines=38) @@
1331
1332
        return self._send_xml_command(cmd)
1333
1334
    def modify_tls_certificate(
1335
        self,
1336
        tls_certificate_id: str,
1337
        *,
1338
        name: Optional[str] = None,
1339
        comment: Optional[str] = None,
1340
        trust: Optional[bool] = None
1341
    ) -> Any:
1342
        """Modifies an existing TLS certificate.
1343
1344
        Arguments:
1345
            tls_certificate_id: UUID of the TLS certificate to be modified.
1346
            name: Name of the TLS certificate, defaulting to the MD5 fingerprint
1347
            comment: Comment for the TLS certificate.
1348
            trust: Whether the certificate is trusted.
1349
1350
        Returns:
1351
            The response. See :py:meth:`send_command` for details.
1352
        """
1353
        if not tls_certificate_id:
1354
            raise RequiredArgument(
1355
                function=self.modify_tls_certificate.__name__,
1356
                argument='tls_certificate_id',
1357
            )
1358
1359
        cmd = XmlCommand("modify_tls_certificate")
1360
        cmd.set_attribute("tls_certificate_id", str(tls_certificate_id))
1361
1362
        if comment:
1363
            cmd.add_element("comment", comment)
1364
1365
        if name:
1366
            cmd.add_element("name", name)
1367
1368
        if trust:
1369
            cmd.add_element("trust", _to_bool(trust))
1370
1371
        return self._send_xml_command(cmd)
1372
1373
    def clone_tls_certificate(self, tls_certificate_id: str) -> Any:
1374
        """Modifies an existing TLS certificate.