def generate_template_certificate_authority(self, valid_for, connection=None): """ Attempts to generate an template certificate authority. :param valid_for: The number of days that the template should be valid. :return: The Template object. """ if connection == None: connection = self.connection struct = { 'operation': 'generate-template-certificate-authority', 'valid-for': assert_type(valid_for, int) } uri = connection.uri("certificate-templates", self.template_id(), properties=None) response = connection.post(uri, payload=struct) if response.status_code != 201: raise UnexpectedManagementAPIResponse(response.text) return self
def __init__(self, name, description, cert_request, key_type="rsa", key_length=None, pass_phrase=None, connection=None, save_connection=None): """ Create a new certificate template. """ self._config = { "template-name": name, "template-description": description, "req": assert_type(cert_request, Request) } if key_type is not None: self._config['key-type'] = key_type if key_length is not None or pass_phrase is not None: options = {} if key_length is not None: options['key-length'] = key_length if pass_phrase is not None: optoins['pass-phrase'] = pass_phrase self._config['options'] = options self.etag = None self.save_connection = save_connection if save_connection: self.connection = connection else: self.connection = None
def generate_temporary_certificate(self, connection, valid_for, common_name, dns_name, ip_addr, if_necessary=True): """ Attempts to generate a temporary certificate. If `if_necessary` is true, the server will only generate a new temporary certificate if it does not already have one for the specified server. :param valid_for: The number of days that the template should be valid. :param common_name: The common name for the certificate ("Example Corp") :param dns_name: The DNS name for the cert ("example.com") :param ip_addr: The IP address of the server :param if_necessary: Only generate the cert if it's necessary :return: The Template object. """ struct = { 'operation': 'generate-temporary-certificate', 'valid-for': assert_type(valid_for, int), 'common-name': common_name, 'dns-name': dns_name, 'ip-addr': ip_addr, 'if-necessary': 'true' if if_necessary else 'false' } uri = connection.uri("certificate-templates", self.template_id(), properties=None) response = connection.post(uri, payload=struct) if response.status_code != 201: raise UnexpectedManagementAPIResponse(response.text) return self
def set_req(self, value): """ Set the certificate request. :param value: The certificate request. :return: The Template object. """ self._config['req'] = assert_type(value, Request) return self
def generate_temporary_certificate(self, valid_for, common_name, dns_name, ip_addr, connection=None, if_necessary=True): """ Attempts to generate a temporary certificate. If `if_necessary` is true, the server will only generate a new temporary certificate if it does not already have one for the specified server. :param valid_for: The number of days that the template should be valid. :param common_name: The common name for the certificate ("Example Corp") :param dns_name: The DNS name for the cert ("example.com") :param ip_addr: The IP address of the server :param if_necessary: Only generate the cert if it's necessary :return: The Template object. """ if connection == None: connection = self.connection struct = { 'operation': 'generate-temporary-certificate', 'valid-for': assert_type(valid_for, int), 'common-name': common_name, 'dns-name': dns_name, 'ip-addr': ip_addr, 'if-necessary': 'true' if if_necessary else 'false' } uri = connection.uri("certificate-templates", self.template_id(), properties=None) response = connection.post(uri, payload=struct) if response.status_code != 201: raise UnexpectedManagementAPIResponse(response.text) return self