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

Support for SSL certificate mappings on Cloud Load Balancers #578

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
110 changes: 110 additions & 0 deletions pyrax/cloudloadbalancers.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,46 @@ def delete_ssl_termination(self):
return self.manager.delete_ssl_termination(self)


def list_certificate_mappings(self):
"""
Returns a list of SSL certificate mappings on the load balancer.
"""
return self.manager.list_certificate_mappings(self)


def add_certificate_mapping(self, hostName, privatekey, certificate,
intermediateCertificate=False):
"""
Adds an SSL certificate mapping to the load balancer.
"""
return self.manager.add_certificate_mapping(self, hostName, privatekey,
certificate, intermediateCertificate)


def get_certificate_mapping(self, certificateMappingId):
"""
Returns a dict representing a single SSL certificate mapping
for the load balancer.
"""
return self.manager.get_certificate_mapping(self, certificateMappingId)


def update_certificate_mapping(self, certificateMappingId, hostName=False,
privatekey=False, certificate=False, intermediateCertificate=False):
"""
Updates an existing SSL certificate mapping on the load balancer.
"""
return self.manager.update_certificate_mapping(self, certificateMappingId,
hostName, privatekey, certificate, intermediateCertificate)


def delete_certificate_mapping(self, certificateMappingId):
"""
Deletes the SSL certificate mapping for the load balancer.
"""
return self.manager.delete_certificate_mapping(self, certificateMappingId)


def get_metadata(self):
"""
Returns the current metadata for the load balancer.
Expand Down Expand Up @@ -797,6 +837,76 @@ def delete_ssl_termination(self, loadbalancer):
resp, body = self.api.method_delete(uri)


def list_certificate_mappings(self, loadbalancer):
"""
Returns a list of SSL certificate mappings on the load balancer.
"""
uri = "/loadbalancers/%s/ssltermination/certificatemappings" % utils.get_id(loadbalancer)
resp, body = self.api.method_get(uri)
return body.get("certificateMappings", {})


def add_certificate_mapping(self, loadbalancer, hostName, privatekey, certificate,
intermediateCertificate=False):
"""
Adds an SSL certificate mapping to the load balancer.
"""
uri = "/loadbalancers/%s/ssltermination/certificatemappings" % utils.get_id(loadbalancer)
req_body = {
"hostName": hostName,
"privateKey": privatekey,
"certificate": certificate,
}
if intermediateCertificate:
req_body["intermediateCertificate"] = intermediateCertificate
resp, body = self.api.method_post(uri, body={"certificateMapping": req_body })
return body.get("certificateMapping", {})


def get_certificate_mapping(self, loadbalancer, certificateMappingId):
"""
Returns a dict representing a single SSL certificate mapping
for the load balancer.
"""
uri = "/loadbalancers/%s/ssltermination/certificatemappings/%s" % (
utils.get_id(loadbalancer), certificateMappingId)
resp, body = self.api.method_get(uri)
return body.get("certificateMapping", {})


def update_certificate_mapping(self, loadbalancer, certificateMappingId, hostName=None,
privatekey=False, certificate=False, intermediateCertificate=False):
"""
Updates an existing SSL certificate mapping on the load balancer.
"""
mapping_info = self.get_certificate_mapping(loadbalancer, certificateMappingId)
if not mapping_info:
raise exc.NoSuchObject("The certificate mapping ID you requested does not exist")
uri = "/loadbalancers/%s/ssltermination/certificatemappings/%s" % (
utils.get_id(loadbalancer), certificateMappingId)
req_body = {}
if hostName:
req_body["hostName"] = hostName
if privatekey:
req_body["privateKey"] = privatekey
if certificate:
req_body["certificate"] = certificate
if intermediateCertificate:
req_body["intermediateCertificate"] = intermediateCertificate

resp, body = self.api.method_put(uri, body={"certificateMapping": req_body })
return body


def delete_certificate_mapping(self, loadbalancer, certificateMappingId):
"""
Deletes the SSL certificate mapping for the load balancer.
"""
uri = "/loadbalancers/%s/ssltermination/certificatemappings/%s" % (
utils.get_id(loadbalancer), certificateMappingId)
resp, body = self.api.method_delete(uri)


def get_metadata(self, loadbalancer, node=None, raw=False):
"""
Returns the current metadata for the load balancer. If 'node' is
Expand Down
2 changes: 1 addition & 1 deletion pyrax/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

version = "1.9.5"
version = "1.9.6"
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't necessary, we'll handle this if it's released.

Copy link
Author

Choose a reason for hiding this comment

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

Realized that after I PR'd; underestimated the involvement you guys have.