(certificate, private_key, intermediates=None,
                   private_key_passphrase=None, expiration=None,
                   name='Magnum TLS Cert', **kwargs)
Stores a certificate in the certificate manager.

        :param certificate: PEM encoded TLS certificate
        :param private_key: private key for the supplied certificate
        :param intermediates: ordered and concatenated intermediate certs
        :param private_key_passphrase: optional passphrase for the supplied key
        :param expiration: the expiration time of the cert in ISO 8601 format
        :param name: a friendly name for the cert

        :returns: the container_ref of the stored cert
        :raises Exception: if certificate storage fails
Stores a certificate in the certificate manager.
Stores a certificate in the certificate manager .
def store_cert(certificate, private_key, intermediates=None,
                   private_key_passphrase=None, expiration=None,
                   name='Magnum TLS Cert', **kwargs):
        """Stores a certificate in the certificate manager.

        :param certificate: PEM encoded TLS certificate
        :param private_key: private key for the supplied certificate
        :param intermediates: ordered and concatenated intermediate certs
        :param private_key_passphrase: optional passphrase for the supplied key
        :param expiration: the expiration time of the cert in ISO 8601 format
        :param name: a friendly name for the cert

        :returns: the container_ref of the stored cert
        :raises Exception: if certificate storage fails
        """
        connection = get_admin_clients().barbican()

        LOG.info("Storing certificate container '%s' in Barbican.", name)

        certificate_secret = None
        private_key_secret = None
        intermediates_secret = None
        pkp_secret = None

        try:
            certificate_secret = connection.secrets.create(
                payload=certificate,
                expiration=expiration,
                name="Certificate"
            )
            private_key_secret = connection.secrets.create(
                payload=private_key,
                expiration=expiration,
                name="Private Key"
            )
            certificate_container = connection.containers.create_certificate(
                name=name,
                certificate=certificate_secret,
                private_key=private_key_secret
            )
            if intermediates:
                intermediates_secret = connection.secrets.create(
                    payload=intermediates,
                    expiration=expiration,
                    name="Intermediates"
                )
                certificate_container.intermediates = intermediates_secret
            if private_key_passphrase:
                pkp_secret = connection.secrets.create(
                    payload=private_key_passphrase,
                    expiration=expiration,
                    name="Private Key Passphrase"
                )
                certificate_container.private_key_passphrase = pkp_secret

            certificate_container.store()
            return certificate_container.container_ref
        #  Barbican (because of Keystone-middleware) sometimes masks
        #  exceptions strangely -- this will catch anything that it raises and
        #  reraise the original exception, while also providing useful
        #  feedback in the logs for debugging
        except magnum_exc.CertificateStorageException:
            for secret in [certificate_secret, private_key_secret,
                           intermediates_secret, pkp_secret]:
                if secret and secret.secret_ref:
                    old_ref = secret.secret_ref
                    try:
                        secret.delete()
                        LOG.info("Deleted secret %s (%s) during rollback.",
                                 secret.name, old_ref)
                    except Exception:
                        LOG.warning(
                            "Failed to delete %s (%s) during rollback. "
                            "This is probably not a problem.",
                            secret.name, old_ref)
            with excutils.save_and_reraise_exception():
                LOG.exception("Error storing certificate data")
def store_cert ( certificate , private_key , intermediates = None , private_key_passphrase = None , expiration = None , name = 'Magnum TLS Cert' , * * kwargs ) : connection = get_admin_clients ( ) . barbican ( ) LOG . info ( "Storing certificate container '%s' in Barbican." , name ) certificate_secret = None private_key_secret = None intermediates_secret = None pkp_secret = None try : certificate_secret = connection . secrets . create ( payload = certificate , expiration = expiration , name = "Certificate" ) private_key_secret = connection . secrets . create ( payload = private_key , expiration = expiration , name = "Private Key" ) certificate_container = connection . containers . create_certificate ( name = name , certificate = certificate_secret , private_key = private_key_secret ) if intermediates : intermediates_secret = connection . secrets . create ( payload = intermediates , expiration = expiration , name = "Intermediates" ) certificate_container . intermediates = intermediates_secret if private_key_passphrase : pkp_secret = connection . secrets . create ( payload = private_key_passphrase , expiration = expiration , name = "Private Key Passphrase" ) certificate_container . private_key_passphrase = pkp_secret certificate_container . store ( ) return certificate_container . container_ref #  Barbican (because of Keystone-middleware) sometimes masks #  exceptions strangely -- this will catch anything that it raises and #  reraise the original exception, while also providing useful #  feedback in the logs for debugging except magnum_exc . CertificateStorageException : for secret in [ certificate_secret , private_key_secret , intermediates_secret , pkp_secret ] : if secret and secret . secret_ref : old_ref = secret . secret_ref try : secret . delete ( ) LOG . info ( "Deleted secret %s (%s) during rollback." , secret . name , old_ref ) except Exception : LOG . warning ( "Failed to delete %s (%s) during rollback. " "This is probably not a problem." , secret . name , old_ref ) with excutils . save_and_reraise_exception ( ) : LOG . exception ( "Error storing certificate data" )