Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #32: Add support for SSL certificate management. #33

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions acapi2/resources/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,97 @@ def enable_cron(self, cron_id: str) -> Session:
response = self.request(uri=uri, method="POST", data="")

return response

def get_ssl_settings(self) -> dict:
"""
Return the SSL settings for the environment.
"""
uri = f"{self.uri}/ssl"
response = self.request(uri=uri)

return response.json()

def get_ssl_certs(self) -> dict:
"""
Return a list of SSL certificates.
"""
uri = f"{self.uri}/ssl/certificates"
response = self.request(uri=uri)

return response.json().get('_embedded', {}).get('items')

def get_ssl_cert(self, cert_id) -> dict:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot the type hint here for cert_id :)

"""
Return an SSL cert.
"""
uri = f"{self.uri}/ssl/certificates/{cert_id}"
response = self.request(uri=uri)

return response.json()

def install_ssl_cert(
self,
label: str,
certificate: str,
private_key: str,
ca_certificates: str = None,
legacy: bool = False,
csr_id: int = None,
) -> Session:
"""
Add a new SSL cert to the environment.
:param: label: Human-friendly identifier for the cert.
:param: certificate: The certificate in PEM format.
:param: private_key: The private keyfor the cert in PEM format.
:param: ca_certificates: Any chain certificates, in PEM format.
Defaults to None.
:param: legacy: Legacy in the sense of Acquia's legacy architecture,
not an old version of the SSL or TLS standards. See Acquia's docs
for more details. Defaults to False.
:param: csr_id: Associate with an existing installed CSR. Defaults
to None.
"""
uri = f"{self.uri}/ssl/certificates"
data = {
"legacy": legacy,
"label": label,
"certificate": certificate,
"private_key": private_key,
}
if csr_id is not None:
data['csr_id'] = csr_id
if ca_certificates is not None:
data['ca_certificates'] = ca_certificates
response = self.request(uri=uri, method="POST", data=data)

return response

def delete_ssl_cert(self, cert_id) -> Session:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

"""
Remove an SSL cert.
:param: cert_id: The Acquia certificate ID.
"""
uri = f"{self.uri}/ssl/certificates/{cert_id}"
response = self.request(uri=uri, method="DELETE")

return response

def activate_ssl_cert(self, cert_id) -> Session:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

"""
Activate a previously installed SSL cert.
:param: cert_id: The Acquia certificate ID.
"""
uri = f"{self.uri}/ssl/certificates/{cert_id}/actions/activate"
response = self.request(uri=uri, method="POST", data={})

return response

def deactivate_ssl_cert(self, cert_id) -> Session:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also here :)

"""
Deactivate a previously installed SSL cert.
:param: cert_id: The Acquia certificate ID.
"""
uri = f"{self.uri}/ssl/certificates/{cert_id}/actions/deactivate"
response = self.request(uri=uri, method="POST", data={})

return response