def decorator(f): if schema not in types.DOCUMENT_SCHEMA_TYPES: raise errors.DeckhandException('Unrecognized document schema %s.' % schema) @functools.wraps(f) def wrapper(bucket_name, documents, *args, **kwargs): existing_documents = revision_documents_get(schema=schema, deleted=False, include_history=False) existing_document_names = [ eng_utils.meta(x) for x in existing_documents ] conflicting_names = [ eng_utils.meta(x) for x in documents if eng_utils.meta(x) not in existing_document_names and x['schema'].startswith(schema) ] if existing_document_names and conflicting_names: raise errors.SingletonDocumentConflict( schema=existing_document_names[0][0], layer=existing_document_names[0][1], name=existing_document_names[0][2], conflict=', '.join([ "[%s, %s] %s" % (x[0], x[1], x[2]) for x in conflicting_names ])) return f(bucket_name, documents, *args, **kwargs) return wrapper
def decorator(f): if schema not in types.DOCUMENT_SCHEMA_TYPES: raise errors.DeckhandException('Unrecognized document schema %s.' % schema) @functools.wraps(f) def wrapper(bucket_name, documents, *args, **kwargs): existing_documents = revision_get_documents(schema=schema, deleted=False, include_history=False) existing_document_names = [x['name'] for x in existing_documents] # `conflict_names` is calculated by checking whether any documents # in `documents` is a layering policy with a name not found in # `existing_documents`. conflicting_names = [ x['metadata']['name'] for x in documents if x['metadata']['name'] not in existing_document_names and x['schema'].startswith(schema) ] if existing_document_names and conflicting_names: raise errors.SingletonDocumentConflict( document=existing_document_names[0], conflict=conflicting_names) return f(bucket_name, documents, *args, **kwargs) return wrapper
def as_after_hook(self): """Extract process_response method as "after" hook :return: after hook function """ # Need to wrap this up in a closure because the parameter counts # differ def after_hook(req, resp, resource=None): return self.process_response(req, resp, resource) try: return after_hook except AttributeError as ex: # No such method, we presume. message_template = ("Failed to get after hook from middleware " "{0} - {1}") message = message_template.format(self.__name__, ex.message) LOG.error(message) raise errors.DeckhandException(message)
def decorator(f): if schema not in types.DOCUMENT_SCHEMA_TYPES: raise errors.DeckhandException( 'Unrecognized document schema %s.' % schema) @functools.wraps(f) def wrapper(bucket_name, documents, *args, **kwargs): existing_documents = revision_documents_get( schema=schema, deleted=False, include_history=False) existing_document_names = [x['name'] for x in existing_documents] conflicting_names = [ x['metadata']['name'] for x in documents if x['metadata']['name'] not in existing_document_names and x['schema'].startswith(schema)] if existing_document_names and conflicting_names: raise errors.SingletonDocumentConflict( document=existing_document_names[0], conflict=conflicting_names) return f(bucket_name, documents, *args, **kwargs) return wrapper