def update(self, secret_ref, payload=None): """ Update an existing Secret from Barbican :param str secret_ref: Full HATEOAS reference to a Secret :param str payload: New payload to add to secret :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ base.validate_ref(secret_ref, 'Secret') if not secret_ref: raise ValueError('secret_ref is required.') if type(payload) is six.binary_type: headers = {'content-type': "application/octet-stream"} elif type(payload) is six.text_type: headers = {'content-type': "text/plain"} else: raise exceptions.PayloadException("Invalid Payload Type") self._api.put(secret_ref, headers=headers, data=payload)
def delete(self, secret_ref): """ Delete a Secret from Barbican :param secret_ref: The href for the secret to be deleted """ base.validate_ref(secret_ref, 'Secret') if not secret_ref: raise ValueError('secret_ref is required.') self._api._delete(secret_ref)
def delete(self, secret_ref): """Delete a Secret from Barbican :param secret_ref: The href for the secret to be deleted :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ base.validate_ref(secret_ref, 'Secret') if not secret_ref: raise ValueError('secret_ref is required.') self._api.delete(secret_ref)
def get(self, ca_ref): """Retrieve an existing CA from Barbican :param str ca_ref: Full HATEOAS reference to a CA :returns: CA object retrieved from Barbican :rtype: :class:`barbicanclient.cas.CA` :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ LOG.debug("Getting ca - CA href: {0}".format(ca_ref)) base.validate_ref(ca_ref, 'CA') return CA(api=self._api, ca_ref=ca_ref)
def delete(self, secret_ref): """ Delete a Secret from Barbican :param secret_ref: The href for the secret to be deleted :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ base.validate_ref(secret_ref, 'Secret') if not secret_ref: raise ValueError('secret_ref is required.') self._api.delete(secret_ref)
def validate_input_ref(self): res_title = self._acl_type.title() if not self.entity_ref: raise ValueError('{0} href is required.'.format(res_title)) if self._parent_entity_path in self.entity_ref: if '/acl' in self.entity_ref: raise ValueError('{0} ACL URI provided. Expecting {0} URI.' .format(res_title)) ref_type = self._acl_type else: raise ValueError('{0} URI is not specified.'.format(res_title)) base.validate_ref(self.entity_ref, ref_type) return ref_type
def get(self, container_ref): """Retrieve an existing Container from Barbican :param str container_ref: Full HATEOAS reference to a Container :returns: Container object or a subclass of the appropriate type """ LOG.debug( 'Getting container - Container href: {0}'.format(container_ref)) base.validate_ref(container_ref, 'Container') try: response = self._api.get(container_ref) except AttributeError: raise LookupError( 'Container {0} could not be found.'.format(container_ref)) return self._generate_typed_container(response)
def get(self, container_ref): """ Retrieve an existing Container from Barbican :param str container_ref: Full HATEOAS reference to a Container :returns: Container object or a subclass of the appropriate type """ LOG.debug('Getting container - Container href: {0}' .format(container_ref)) base.validate_ref(container_ref, 'Container') try: response = self._api.get(container_ref) except AttributeError: raise LookupError('Container {0} could not be found.' .format(container_ref)) return self._generate_typed_container(response)
def get(self, order_ref): """ Retrieve an existing Order from Barbican :param order_ref: Full HATEOAS reference to an Order :returns: An instance of the appropriate subtype of Order """ LOG.debug("Getting order - Order href: {0}".format(order_ref)) base.validate_ref(order_ref, 'Order') try: response = self._api._get(order_ref) except AttributeError: raise LookupError( 'Order {0} could not be found.'.format(order_ref) ) return self._create_typed_order(response)
def get(self, order_ref): """Retrieve an existing Order from Barbican :param order_ref: Full HATEOAS reference to an Order :returns: An instance of the appropriate subtype of Order :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ LOG.debug("Getting order - Order href: {0}".format(order_ref)) base.validate_ref(order_ref, 'Order') try: response = self._api.get(order_ref) except AttributeError: raise LookupError( 'Order {0} could not be found.'.format(order_ref)) return self._create_typed_order(response)
def get(self, ca_ref): """ Retrieve an existing CA from Barbican :param str ca_ref: Full HATEOAS reference to a CA :returns: CA object retrieved from Barbican :rtype: :class:`barbicanclient.cas.CA` :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ LOG.debug("Getting ca - CA href: {0}".format(ca_ref)) base.validate_ref(ca_ref, 'CA') return CA( api=self._api, ca_ref=ca_ref )
def get(self, secret_ref, payload_content_type=None): """ Retrieve an existing Secret from Barbican :param str secret_ref: Full HATEOAS reference to a Secret :param str payload_content_type: DEPRECATED: Content type to use for payload decryption. Setting this can lead to unexpected results. See Launchpad Bug #1419166. :returns: Secret object retrieved from Barbican :rtype: :class:`barbicanclient.secrets.Secret` """ LOG.debug("Getting secret - Secret href: {0}".format(secret_ref)) base.validate_ref(secret_ref, 'Secret') return Secret( api=self._api, payload_content_type=payload_content_type, secret_ref=secret_ref )
def _reload(self): if not self._container_ref: raise AttributeError("container_ref not set, cannot reload data.") LOG.debug('Getting container - Container href: {0}'.format( self._container_ref)) base.validate_ref(self._container_ref, 'Container') try: response = self._api.get(self._container_ref) except AttributeError: raise LookupError('Container {0} could not be found.'.format( self._container_ref)) self._name = response.get('name') self._consumers = response.get('consumers', []) created = response.get('created') updated = response.get('updated') self._created = parse_isotime(created) if created else None self._updated = parse_isotime(updated) if updated else None self._status = response.get('status')
def get(self, secret_ref, payload_content_type=None): """Retrieve an existing Secret from Barbican :param str secret_ref: Full HATEOAS reference to a Secret :param str payload_content_type: DEPRECATED: Content type to use for payload decryption. Setting this can lead to unexpected results. See Launchpad Bug #1419166. :returns: Secret object retrieved from Barbican :rtype: :class:`barbicanclient.secrets.Secret` :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ LOG.debug("Getting secret - Secret href: {0}".format(secret_ref)) base.validate_ref(secret_ref, 'Secret') return Secret(api=self._api, payload_content_type=payload_content_type, secret_ref=secret_ref)
def _reload(self): if not self._container_ref: raise AttributeError("container_ref not set, cannot reload data.") LOG.debug('Getting container - Container href: {0}' .format(self._container_ref)) base.validate_ref(self._container_ref, 'Container') try: response = self._api.get(self._container_ref) except AttributeError: raise LookupError('Container {0} could not be found.' .format(self._container_ref)) self._name = response.get('name') self._consumers = response.get('consumers', []) created = response.get('created') updated = response.get('updated') self._created = parse_isotime(created) if created else None self._updated = parse_isotime(updated) if updated else None self._status = response.get('status')
def update(self, secret_ref, payload=None): """Update an existing Secret from Barbican :param str secret_ref: Full HATEOAS reference to a Secret :param str payload: New payload to add to secret :raises barbicanclient.exceptions.HTTPAuthError: 401 Responses :raises barbicanclient.exceptions.HTTPClientError: 4xx Responses :raises barbicanclient.exceptions.HTTPServerError: 5xx Responses """ base.validate_ref(secret_ref, 'Secret') if not secret_ref: raise ValueError('secret_ref is required.') if type(payload) is six.binary_type: headers = {'content-type': "application/octet-stream"} elif type(payload) is six.text_type: headers = {'content-type': "text/plain"} else: raise exceptions.PayloadException("Invalid Payload Type") self._api.put(secret_ref, headers=headers, data=payload)
def test_valid_ref(self): ref = 'http://localhost/ff2ca003-5ebb-4b61-8a17-3f9c54ef6356' self.assertTrue(base.validate_ref(ref, 'Thing'))