def store(self): """ Stores the Secret in Barbican. New Secret objects are not persisted in Barbican until this method is called. :raises: PayloadException """ secret_dict = { 'name': self.name, 'algorithm': self.algorithm, 'mode': self.mode, 'bit_length': self.bit_length, 'secret_type': self.secret_type, 'expiration': self.expiration } if self.payload == '': raise exceptions.PayloadException("Invalid Payload: " "Cannot Be Empty String") if self.payload is not None and not isinstance( self.payload, (six.text_type, six.binary_type)): raise exceptions.PayloadException("Invalid Payload Type") if self.payload_content_type or self.payload_content_encoding: """ Setting the payload_content_type and payload_content_encoding manually is deprecated. This clause of the if statement is here for backwards compatibility and should be removed in a future release. """ secret_dict['payload'] = self.payload secret_dict['payload_content_type'] = self.payload_content_type secret_dict['payload_content_encoding'] = ( self.payload_content_encoding) elif type(self.payload) is six.binary_type: """ six.binary_type is stored as application/octet-stream and it is base64 encoded for a one-step POST """ secret_dict['payload'] = (base64.b64encode( self.payload)).decode('UTF-8') secret_dict['payload_content_type'] = u'application/octet-stream' secret_dict['payload_content_encoding'] = u'base64' elif type(self.payload) is six.text_type: """ six.text_type is stored as text/plain """ secret_dict['payload'] = self.payload secret_dict['payload_content_type'] = u'text/plain' secret_dict = base.filter_null_keys(secret_dict) LOG.debug("Request body: {0}".format( base.censored_copy(secret_dict, ['payload']))) # Save, store secret_ref and return response = self._api.post(self._entity, json=secret_dict) if response: self._secret_ref = response.get('secret_ref') return self.secret_ref
def __init__(self, api, type, status=None, created=None, updated=None, meta=None, order_ref=None, error_status_code=None, error_reason=None): super(Order, self).__init__() self._api = api self._type = type self._status = status if created: self._created = parse_isotime(created) else: self._created = None if updated: self._updated = parse_isotime(updated) else: self._updated = None self._order_ref = order_ref self._meta = base.filter_null_keys(meta) self._error_status_code = error_status_code self._error_reason = error_reason if 'expiration' in self._meta.keys(): self._meta['expiration'] = parse_isotime(self._meta['expiration'])
def __init__(self, api, type, status=None, created=None, updated=None, meta=None, order_ref=None, error_status_code=None, error_reason=None, sub_status=None, sub_status_message=None, creator_id=None): super(Order, self).__init__() self._api = api self._type = type self._status = status self._sub_status = sub_status self._sub_status_message = sub_status_message self._creator_id = creator_id if created: self._created = parse_isotime(created) else: self._created = None if updated: self._updated = parse_isotime(updated) else: self._updated = None self._order_ref = order_ref self._meta = base.filter_null_keys(meta) self._error_status_code = error_status_code self._error_reason = error_reason if 'expiration' in self._meta.keys(): self._meta['expiration'] = parse_isotime(self._meta['expiration'])
def store(self): """ Stores the Secret in Barbican. New Secret objects are not persisted in Barbican until this method is called. :raises: PayloadException """ secret_dict = { 'name': self.name, 'algorithm': self.algorithm, 'mode': self.mode, 'bit_length': self.bit_length, 'secret_type': self.secret_type, 'expiration': self.expiration } if not self.payload: raise exceptions.PayloadException("Missing Payload") if not isinstance(self.payload, (six.text_type, six.binary_type)): raise exceptions.PayloadException("Invalid Payload Type") if self.payload_content_type or self.payload_content_encoding: """ Setting the payload_content_type and payload_content_encoding manually is deprecated. This clause of the if statement is here for backwards compatibility and should be removed in a future release. """ secret_dict['payload'] = self.payload secret_dict['payload_content_type'] = self.payload_content_type secret_dict['payload_content_encoding'] = ( self.payload_content_encoding ) elif type(self.payload) is six.binary_type: """ six.binary_type is stored as application/octet-stream and it is base64 encoded for a one-step POST """ secret_dict['payload'] = ( base64.b64encode(self.payload) ).decode('UTF-8') secret_dict['payload_content_type'] = u'application/octet-stream' secret_dict['payload_content_encoding'] = u'base64' elif type(self.payload) is six.text_type: """ six.text_type is stored as text/plain """ secret_dict['payload'] = self.payload secret_dict['payload_content_type'] = u'text/plain' secret_dict = base.filter_null_keys(secret_dict) LOG.debug("Request body: {0}".format(secret_dict)) # Save, store secret_ref and return response = self._api.post(self._entity, json=secret_dict) if response: self._secret_ref = response.get('secret_ref') return self.secret_ref
def store(self): """Store Container in Barbican""" secret_refs = self._get_secrets_and_store_them_if_necessary() container_dict = base.filter_null_keys({ 'name': self.name, 'type': self._type, 'secret_refs': secret_refs }) LOG.debug("Request body: {0}".format(container_dict)) # Save, store container_ref and return response = self._api.post(self._entity, json=container_dict) if response: self._container_ref = response['container_ref'] return self.container_ref