@@ -47,6 +47,16 @@ def _get_force_https(self):
4747 def _set_force_https (self , force ):
4848 self ._edge .api .put ('/config/fileservices/webdav/forceHttps' , force )
4949
50+ def _import_certificate (self , path , private_key , * certificates ):
51+ key_object = PrivateKey .load_private_key (private_key )
52+ certificates = [X509Certificate .load_certificate (certificate ) for certificate in certificates ]
53+ certificate_chain = [certificate .pem_data .decode ('utf-8' ) for certificate in create_certificate_chain (* certificates )]
54+ server_certificate = '' .join ([key_object .pem_data .decode ('utf-8' )] + certificate_chain )
55+ logging .getLogger ('cterasdk.edge' ).info ("Uploading Web Server SSL certificate." )
56+ response = self ._edge .api .put (path , f"\n { server_certificate } " )
57+ logging .getLogger ('cterasdk.edge' ).info ("Uploaded Web Server SSL certificate." )
58+ return response
59+
5060
5161class SSLv1 (SSL ):
5262 """ Edge Filer SSLv1 APIs """
@@ -85,15 +95,7 @@ def import_certificate(self, private_key, *certificates):
8595 :param str private_key: The PEM-encoded private key, or a path to the PEM-encoded private key file
8696 :param list[str] certificates: The PEM-encoded certificates, or a list of paths to the PEM-encoded certificates
8797 """
88-
89- key_object = PrivateKey .load_private_key (private_key )
90- certificates = [X509Certificate .load_certificate (certificate ) for certificate in certificates ]
91- certificate_chain = [certificate .pem_data .decode ('utf-8' ) for certificate in create_certificate_chain (* certificates )]
92- server_certificate = '' .join ([key_object .pem_data .decode ('utf-8' )] + certificate_chain )
93- logging .getLogger ('cterasdk.edge' ).info ("Uploading SSL certificate." )
94- response = self ._edge .api .put ('/config/certificate' , f"\n { server_certificate } " )
95- logging .getLogger ('cterasdk.edge' ).info ("Uploaded SSL certificate." )
96- return response
98+ return self ._import_certificate ('/config/certificate' , private_key , * certificates )
9799
98100
99101class SSLv78 (SSL ):
@@ -130,14 +132,7 @@ def import_certificate(self, private_key, *certificates):
130132 :param str private_key: The PEM-encoded private key, or a path to the PEM-encoded private key file
131133 :param list[str] certificates: The PEM-encoded certificates, or a list of paths to the PEM-encoded certificates
132134 """
133- key_object = PrivateKey .load_private_key (private_key )
134- certificates = [X509Certificate .load_certificate (certificate ) for certificate in certificates ]
135- certificate_chain = [certificate .pem_data .decode ('utf-8' ) for certificate in create_certificate_chain (* certificates )]
136- server_certificate = '' .join ([key_object .pem_data .decode ('utf-8' )] + certificate_chain )
137- logging .getLogger ('cterasdk.edge' ).info ("Uploading SSL certificate." )
138- response = self ._edge .api .put ('/config/certificates/serverCertificate' , f"\n { server_certificate } " )
139- logging .getLogger ('cterasdk.edge' ).info ("Uploaded SSL certificate." )
140- return response
135+ return self ._import_certificate ('/config/certificates/serverCertificate' , private_key , * certificates )
141136
142137
143138class TrustedCAs (BaseCommand ):
0 commit comments