Пример #1
0
    def __init__(self, *args, **kwargs):
        super(Collection, self).__init__(*args, **kwargs)

        bucket_id = self.request.matchdict['bucket_id']
        object_exists_or_404(self.request,
                             collection_id='bucket',
                             object_id=bucket_id)

        self.collection.id_generator = NameGenerator()
Пример #2
0
    def __init__(self, *args, **kwargs):
        super(Group, self).__init__(*args, **kwargs)

        bucket_id = self.request.matchdict['bucket_id']
        object_exists_or_404(self.request,
                             collection_id='bucket',
                             object_id=bucket_id)

        self.collection.id_generator = NameGenerator()
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(Group, self).__init__(*args, **kwargs)

        bucket_id = self.request.matchdict['bucket_id']
        object_exists_or_404(self.request,
                             collection_id='bucket',
                             object_id=bucket_id)

        parent_id = '/buckets/%s' % bucket_id
        self.collection.parent_id = parent_id
        self.collection.id_generator = NameGenerator()
Пример #4
0
    def __init__(self, *args, **kwargs):
        super(Record, self).__init__(*args, **kwargs)

        bucket_id = self.request.matchdict['bucket_id']
        object_exists_or_404(self.request,
                             collection_id='bucket',
                             object_id=bucket_id)

        collection_id = self.request.matchdict['collection_id']
        object_exists_or_404(self.request,
                             collection_id='collection',
                             parent_id='/buckets/%s' % bucket_id,
                             object_id=collection_id)
Пример #5
0
    def __init__(self, *args, **kwargs):
        super(Record, self).__init__(*args, **kwargs)

        bucket_id = self.request.matchdict['bucket_id']
        object_exists_or_404(self.request,
                             collection_id='bucket',
                             object_id=bucket_id)

        collection_id = self.request.matchdict['collection_id']
        object_exists_or_404(self.request,
                             collection_id='collection',
                             parent_id='/buckets/%s' % bucket_id,
                             object_id=collection_id)

        parent_id = '/buckets/%s/collections/%s' % (bucket_id, collection_id)
        self.collection.parent_id = parent_id
Пример #6
0
    def __init__(self, *args, **kwargs):
        super(Record, self).__init__(*args, **kwargs)

        self.bucket_id = self.request.matchdict['bucket_id']
        self.collection_id = self.request.matchdict['collection_id']
        collection_parent_id = '/buckets/%s' % self.bucket_id
        self._collection = object_exists_or_404(self.request,
                                                collection_id='collection',
                                                parent_id=collection_parent_id,
                                                object_id=self.collection_id)
Пример #7
0
    def __init__(self, *args, **kwargs):
        super(Record, self).__init__(*args, **kwargs)

        # Check if already fetched before (in batch).
        collections = self.request.bound_data.setdefault('collections', {})
        collection_uri = self.get_parent_id(self.request)
        if collection_uri not in collections:
            # Unknown yet, fetch from storage.
            collection_parent_id = '/buckets/%s' % self.bucket_id
            collection = object_exists_or_404(self.request,
                                              collection_id='collection',
                                              parent_id=collection_parent_id,
                                              object_id=self.collection_id)
            collections[collection_uri] = collection

        self._collection = collections[collection_uri]
Пример #8
0
    def __init__(self, *args, **kwargs):
        super(Record, self).__init__(*args, **kwargs)

        # Check if already fetched before (in batch).
        collections = self.request.bound_data.setdefault('collections', {})
        collection_uri = self.get_parent_id(self.request)
        if collection_uri not in collections:
            # Unknown yet, fetch from storage.
            collection_parent_id = '/buckets/%s' % self.bucket_id
            collection = object_exists_or_404(self.request,
                                              collection_id='collection',
                                              parent_id=collection_parent_id,
                                              object_id=self.collection_id)
            collections[collection_uri] = collection

        self._collection = collections[collection_uri]
Пример #9
0
    def __init__(self, request, **kwargs):
        # Before all, first check that the parent collection exists.
        # Check if already fetched before (in batch).
        collections = request.bound_data.setdefault('collections', {})
        collection_uri = self.get_parent_id(request)
        if collection_uri not in collections:
            # Unknown yet, fetch from storage.
            bucket_uri = utils.instance_uri(request, 'bucket', id=self.bucket_id)
            collection = object_exists_or_404(request,
                                              collection_id='collection',
                                              parent_id=bucket_uri,
                                              object_id=self.collection_id)
            collections[collection_uri] = collection
        self._collection = collections[collection_uri]

        super().__init__(request, **kwargs)
Пример #10
0
    def __init__(self, request, **kwargs):
        # Before all, first check that the parent collection exists.
        # Check if already fetched before (in batch).
        collections = request.bound_data.setdefault('collections', {})
        collection_uri = self.get_parent_id(request)
        if collection_uri not in collections:
            # Unknown yet, fetch from storage.
            collection_parent_id = utils.instance_uri(request, 'bucket',
                                                      id=self.bucket_id)
            collection = object_exists_or_404(request,
                                              collection_id='collection',
                                              parent_id=collection_parent_id,
                                              object_id=self.collection_id)
            collections[collection_uri] = collection

        super(Record, self).__init__(request, **kwargs)
        self._collection = collections[collection_uri]
Пример #11
0
    def __init__(self, request, **kwargs):
        # Before all, first check that the parent collection exists.
        # Check if already fetched before (in batch).
        collections = request.bound_data.setdefault("collections", {})
        collection_uri = self.get_parent_id(request)
        if collection_uri not in collections:
            # Unknown yet, fetch from storage.
            bucket_uri = utils.instance_uri(request, "bucket", id=self.bucket_id)
            collection = object_exists_or_404(
                request,
                resource_name="collection",
                parent_id=bucket_uri,
                object_id=self.collection_id,
            )
            collections[collection_uri] = collection
        self._collection = collections[collection_uri]

        super().__init__(request, **kwargs)
Пример #12
0
def validate_from_bucket_schema_or_400(data,
                                       resource_name,
                                       request,
                                       id_field,
                                       ignore_fields=[]):
    """Lookup in the parent objects if a schema was defined for this resource.

    If the schema validation feature is enabled, if a schema is/are defined, and if the
    data does not validate it/them, then it raises a 400 exception.
    """
    settings = request.registry.settings
    schema_validation = "experimental_collection_schema_validation"
    # If disabled from settings, do nothing.
    if not asbool(settings.get(schema_validation)):
        return

    bucket_id = request.matchdict["bucket_id"]
    bucket_uri = utils.instance_uri(request, "bucket", id=bucket_id)
    buckets = request.bound_data.setdefault("buckets", {})
    if bucket_uri not in buckets:
        # Unknown yet, fetch from storage.
        bucket = object_exists_or_404(request,
                                      resource_name="bucket",
                                      parent_id="",
                                      object_id=bucket_id)
        buckets[bucket_uri] = bucket

    # Let's see if the bucket defines a schema for this resource.
    metadata_field = f"{resource_name}:schema"
    bucket = buckets[bucket_uri]
    if metadata_field not in bucket:
        return

    # Validate or fail with 400.
    schema = bucket[metadata_field]
    try:
        validate_schema(data,
                        schema,
                        ignore_fields=ignore_fields,
                        id_field=id_field)
    except ValidationError as e:
        raise_invalid(request, name=e.field, description=e.message)
    except RefResolutionError as e:
        raise_invalid(request, name="schema", description=str(e))
Пример #13
0
def validate_from_bucket_schema_or_400(data, resource_name, request, ignore_fields=[]):
    """Lookup in the parent objects if a schema was defined for this resource.

    If the schema validation feature is enabled, if a schema is/are defined, and if the
    data does not validate it/them, then it raises a 400 exception.
    """
    settings = request.registry.settings
    schema_validation = 'experimental_collection_schema_validation'
    # If disabled from settings, do nothing.
    if not asbool(settings.get(schema_validation)):
        return

    bucket_id = request.matchdict["bucket_id"]
    bucket_uri = utils.instance_uri(request, 'bucket', id=bucket_id)
    buckets = request.bound_data.setdefault('buckets', {})
    if bucket_uri not in buckets:
        # Unknown yet, fetch from storage.
        bucket = object_exists_or_404(request,
                                      collection_id='bucket',
                                      parent_id='',
                                      object_id=bucket_id)
        buckets[bucket_uri] = bucket

    # Let's see if the bucket defines a schema for this resource.
    metadata_field = "{}:schema".format(resource_name)
    bucket = buckets[bucket_uri]
    if metadata_field not in bucket:
        return

    # Validate or fail with 400.
    schema = bucket[metadata_field]
    try:
        validate_schema(data, schema, ignore_fields=ignore_fields)
    except ValidationError as e:
        raise_invalid(request, name=e.field, description=e.message)
    except RefResolutionError as e:
        raise_invalid(request, name='schema', description=str(e))