예제 #1
0
def create_secret_metadatum(secret=None,
                            key="key",
                            value="value",
                            session=None):
    secret_meta = models.SecretStoreMetadatum(key, value)
    secret_meta.secret_id = secret.id
    secret_meta_repo = repositories.get_secret_meta_repository()
    secret_meta_repo.create_from(secret_meta, session=session)
    return secret_meta
예제 #2
0
    def save(self, metadata, secret_model):
        """Saves the the specified metadata for the secret.

        :raises NotFound if entity does not exist.
        """
        now = timeutils.utcnow()

        for k, v in metadata.items():
            meta_model = models.SecretStoreMetadatum(k, v)
            meta_model.updated_at = now
            meta_model.secret = secret_model
            meta_model.save()
예제 #3
0
    def _test_secret_and_datum_for_content_type(self, content_type):
        self.assertIn(content_type, mime_types.INTERNAL_CTYPES)

        # TODO(rm_work): This is deprecated and should eventually be removed
        self.datum.content_type = mime_types.INTERNAL_CTYPES[content_type]

        # Set up the Secret Metadata
        content_meta = models.SecretStoreMetadatum('content_type',
                                                   self.datum.content_type)
        self.secret.secret_store_metadata['content_type'] = content_meta

        fields = mime_types.augment_fields_with_content_types(self.secret)

        self.assertIn('content_types', fields)
        content_types = fields['content_types']
        self.assertIn('default', content_types)
        self.assertEqual(self.datum.content_type, content_types['default'])
예제 #4
0
def create_secret(id_ref="id", name="name",
                  algorithm=None, bit_length=None,
                  mode=None, encrypted_datum=None, content_type=None):
    """Generate a Secret entity instance."""
    info = {'id': id_ref,
            'name': name,
            'algorithm': algorithm,
            'bit_length': bit_length,
            'mode': mode}
    secret = models.Secret(info)
    secret.id = id_ref
    if encrypted_datum:
        secret.encrypted_data = [encrypted_datum]
    if content_type:
        content_meta = models.SecretStoreMetadatum('content_type',
                                                   content_type)
        secret.secret_store_metadata['content_type'] = content_meta
    return secret