Code Duplication    Length = 38-42 lines in 2 locations

gvm/protocols/gmpv208/entities/tls_certificates.py 2 locations

@@ 50-91 (lines=42) @@
47
48
        return self._send_xml_command(cmd)
49
50
    def create_tls_certificate(
51
        self,
52
        name: str,
53
        certificate: str,
54
        *,
55
        comment: Optional[str] = None,
56
        trust: Optional[bool] = None,
57
    ) -> Any:
58
        """Create a new TLS certificate
59
60
        Arguments:
61
            name: Name of the TLS certificate, defaulting to the MD5
62
                fingerprint.
63
            certificate: The Base64 encoded certificate data (x.509 DER or PEM).
64
            comment: Comment for the TLS certificate.
65
            trust: Whether the certificate is trusted.
66
67
        Returns:
68
            The response. See :py:meth:`send_command` for details.
69
        """
70
        if not name:
71
            raise RequiredArgument(
72
                function=self.create_tls_certificate.__name__, argument='name'
73
            )
74
        if not certificate:
75
            raise RequiredArgument(
76
                function=self.create_tls_certificate.__name__,
77
                argument='certificate',
78
            )
79
80
        cmd = XmlCommand("create_tls_certificate")
81
82
        if comment:
83
            cmd.add_element("comment", comment)
84
85
        cmd.add_element("name", name)
86
        cmd.add_element("certificate", certificate)
87
88
        if trust:
89
            cmd.add_element("trust", to_bool(trust))
90
91
        return self._send_xml_command(cmd)
92
93
    def delete_tls_certificate(self, tls_certificate_id: str) -> Any:
94
        """Deletes an existing tls certificate
@@ 173-210 (lines=38) @@
170
171
        return self._send_xml_command(cmd)
172
173
    def modify_tls_certificate(
174
        self,
175
        tls_certificate_id: str,
176
        *,
177
        name: Optional[str] = None,
178
        comment: Optional[str] = None,
179
        trust: Optional[bool] = None,
180
    ) -> Any:
181
        """Modifies an existing TLS certificate.
182
183
        Arguments:
184
            tls_certificate_id: UUID of the TLS certificate to be modified.
185
            name: Name of the TLS certificate, defaulting to the MD5 fingerprint
186
            comment: Comment for the TLS certificate.
187
            trust: Whether the certificate is trusted.
188
189
        Returns:
190
            The response. See :py:meth:`send_command` for details.
191
        """
192
        if not tls_certificate_id:
193
            raise RequiredArgument(
194
                function=self.modify_tls_certificate.__name__,
195
                argument='tls_certificate_id',
196
            )
197
198
        cmd = XmlCommand("modify_tls_certificate")
199
        cmd.set_attribute("tls_certificate_id", str(tls_certificate_id))
200
201
        if comment:
202
            cmd.add_element("comment", comment)
203
204
        if name:
205
            cmd.add_element("name", name)
206
207
        if trust:
208
            cmd.add_element("trust", to_bool(trust))
209
210
        return self._send_xml_command(cmd)
211