Пример #1
0
    def _retrieve_documents_for_rendering(self, revision_id, **filters):
        """Retrieve all necessary documents needed for rendering. If a layering
        policy isn't found in the current revision, retrieve it in a subsequent
        call and add it to the list of documents.
        """
        try:
            documents = db_api.revision_documents_get(revision_id, **filters)
        except errors.RevisionNotFound as e:
            LOG.exception(six.text_type(e))
            raise falcon.HTTPNotFound(description=e.format_message())

        if not any([
                d['schema'].startswith(types.LAYERING_POLICY_SCHEMA)
                for d in documents
        ]):
            try:
                layering_policy_filters = {
                    'deleted': False,
                    'schema': types.LAYERING_POLICY_SCHEMA
                }
                layering_policy = db_api.document_get(
                    **layering_policy_filters)
            except errors.DocumentNotFound as e:
                LOG.exception(e.format_message())
            else:
                documents.append(layering_policy)

        return documents
Пример #2
0
    def substitute_all(self):
        """Substitute all documents that have a `metadata.substitutions` field.

        Concrete (non-abstract) documents can be used as a source of
        substitution into other documents. This substitution is
        layer-independent, a document in the region layer could insert data
        from a document in the site layer.

        :returns: List of fully substituted documents.
        """
        LOG.debug('Substituting secrets for documents: %s', self.documents)
        substituted_docs = []

        for doc in self.documents:
            LOG.debug(
                'Checking for substitutions in schema=%s, metadata.name=%s',
                doc.get_name(), doc.get_schema())
            for sub in doc.get_substitutions():
                src_schema = sub['src']['schema']
                src_name = sub['src']['name']
                src_path = sub['src']['path']
                if src_path == '.':
                    src_path = '.secret'

                # TODO(fmontei): Use secrets_manager for this logic. Need to
                # check Barbican for the secret if it has been encrypted.
                src_doc = db_api.document_get(
                    schema=src_schema,
                    name=src_name,
                    is_secret=True,
                    **{'metadata.layeringDefinition.abstract': False})
                src_secret = utils.jsonpath_parse(src_doc['data'], src_path)

                dest_path = sub['dest']['path']
                dest_pattern = sub['dest'].get('pattern', None)

                LOG.debug(
                    'Substituting from schema=%s name=%s src_path=%s '
                    'into dest_path=%s, dest_pattern=%s', src_schema, src_name,
                    src_path, dest_path, dest_pattern)
                substituted_data = utils.jsonpath_replace(
                    doc['data'], src_secret, dest_path, dest_pattern)
                doc['data'].update(substituted_data)

            substituted_docs.append(doc.to_dict())
        return substituted_docs
Пример #3
0
    def show_document(self, **fields):
        doc = db_api.document_get(**fields)

        self.validate_document(actual=doc)

        return doc