def store_cert(certificate, private_key, intermediates=None, private_key_passphrase=None, context=None, **kwargs): """Stores (i.e., registers) a cert with the cert manager. This method stores the specified cert to x509keypair model and returns a UUID that can be used to retrieve it. :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 :returns: the UUID of the stored cert """ x509keypair = { 'certificate': certificate, 'private_key': private_key, 'private_key_passphrase': private_key_passphrase, 'intermediates': intermediates, 'project_id': context.project_id, 'user_id': context.user_id } x509keypair_obj = objects.X509KeyPair(context, **x509keypair) x509keypair_obj.create() return x509keypair_obj.uuid
def test_x509keypair_create(self): expected_x509keypair = objects.X509KeyPair({}) expected_x509keypair.create = mock.MagicMock() self.x509keypair_handler.x509keypair_create(self.context, expected_x509keypair) expected_x509keypair.create.assert_called_once_with(self.context)
def test_create(self): with mock.patch.object(self.dbapi, 'create_x509keypair', autospec=True) as mock_create_x509keypair: mock_create_x509keypair.return_value = self.fake_x509keypair x509keypair = objects.X509KeyPair(self.context, **self.fake_x509keypair) x509keypair.create() mock_create_x509keypair.assert_called_once_with( self.fake_x509keypair) self.assertEqual(self.context, x509keypair._context)
def get_test_x509keypair(context, **kw): """Return a X509KeyPair object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_x509keypair = db_utils.get_test_x509keypair(**kw) # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del db_x509keypair['id'] x509keypair = objects.X509KeyPair(context) for key in db_x509keypair: setattr(x509keypair, key, db_x509keypair[key]) return x509keypair
def post(self, x509keypair): """Create a new x509keypair. :param x509keypair: a x509keypair within the request body. """ x509keypair_dict = x509keypair.as_dict() context = pecan.request.context x509keypair_dict['project_id'] = context.project_id x509keypair_dict['user_id'] = context.user_id x509keypair_obj = objects.X509KeyPair(context, **x509keypair_dict) new_x509keypair = pecan.request.rpcapi.x509keypair_create( x509keypair_obj) # Set the HTTP Location Header pecan.response.location = link.build_url('x509keypairs', new_x509keypair.uuid) return X509KeyPair.convert_with_links(new_x509keypair)