Code Duplication    Length = 38-42 lines in 4 locations

gvm/protocols/gmpv9/gmpv9.py 2 locations

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

gvm/protocols/gmpv208/gmpv208.py 2 locations

@@ 741-782 (lines=42) @@
738
            preferences=preferences,
739
        )
740
741
    def create_tls_certificate(
742
        self,
743
        name: str,
744
        certificate: str,
745
        *,
746
        comment: Optional[str] = None,
747
        trust: Optional[bool] = None,
748
    ) -> Any:
749
        """Create a new TLS certificate
750
751
        Arguments:
752
            name: Name of the TLS certificate, defaulting to the MD5
753
                fingerprint.
754
            certificate: The Base64 encoded certificate data (x.509 DER or PEM).
755
            comment: Comment for the TLS certificate.
756
            trust: Whether the certificate is trusted.
757
758
        Returns:
759
            The response. See :py:meth:`send_command` for details.
760
        """
761
        if not name:
762
            raise RequiredArgument(
763
                function=self.create_tls_certificate.__name__, argument='name'
764
            )
765
        if not certificate:
766
            raise RequiredArgument(
767
                function=self.create_tls_certificate.__name__,
768
                argument='certificate',
769
            )
770
771
        cmd = XmlCommand("create_tls_certificate")
772
773
        if comment:
774
            cmd.add_element("comment", comment)
775
776
        cmd.add_element("name", name)
777
        cmd.add_element("certificate", certificate)
778
779
        if trust:
780
            cmd.add_element("trust", _to_bool(trust))
781
782
        return self._send_xml_command(cmd)
783
784
    def get_aggregates(
785
        self,
@@ 1446-1483 (lines=38) @@
1443
1444
        return self._send_xml_command(cmd)
1445
1446
    def modify_tls_certificate(
1447
        self,
1448
        tls_certificate_id: str,
1449
        *,
1450
        name: Optional[str] = None,
1451
        comment: Optional[str] = None,
1452
        trust: Optional[bool] = None,
1453
    ) -> Any:
1454
        """Modifies an existing TLS certificate.
1455
1456
        Arguments:
1457
            tls_certificate_id: UUID of the TLS certificate to be modified.
1458
            name: Name of the TLS certificate, defaulting to the MD5 fingerprint
1459
            comment: Comment for the TLS certificate.
1460
            trust: Whether the certificate is trusted.
1461
1462
        Returns:
1463
            The response. See :py:meth:`send_command` for details.
1464
        """
1465
        if not tls_certificate_id:
1466
            raise RequiredArgument(
1467
                function=self.modify_tls_certificate.__name__,
1468
                argument='tls_certificate_id',
1469
            )
1470
1471
        cmd = XmlCommand("modify_tls_certificate")
1472
        cmd.set_attribute("tls_certificate_id", str(tls_certificate_id))
1473
1474
        if comment:
1475
            cmd.add_element("comment", comment)
1476
1477
        if name:
1478
            cmd.add_element("name", name)
1479
1480
        if trust:
1481
            cmd.add_element("trust", _to_bool(trust))
1482
1483
        return self._send_xml_command(cmd)
1484
1485
    def clone_alert(self, alert_id: str) -> Any:
1486
        """Clone an existing alert