) return "", 204 @request_search_args @request_view_args @response_handler(many=True) def search(self): """List secret links for a record.""" items = self.service.read_secret_links( id_=resource_requestctx.view_args["pid_value"], identity=g.identity, ) return items.to_dict(), 200 request_pid_args = request_parser({"client": SanitizedUnicode()}, location='args') class RDMManagedPIDProviderResource(RecordResource): """PID provider resource.""" def create_url_rules(self): """Create the URL rules for the pid provider resource.""" def p(route): """Prefix a route with the URL prefix.""" return f"{self.config.url_prefix}{route}" routes = self.config.routes return [ route("GET", p(routes["item"]), self.create), route("DELETE", p(routes["item"]), self.delete), ]
ResponseHandler(JSONSerializer(), headers=etag_headers), "application/vnd.inveniordm.v1+json": ResponseHandler( MarshmallowJSONSerializer( schema_cls=VocabularyL10NItemSchema, many_schema_cls=VocabularyL10NListSchema, ), headers=etag_headers, ), } # # Decorators # request_search_args = request_parser(from_conf("request_args"), location="args") request_view_args = request_parser(from_conf("request_view_args"), location="view_args") request_headers = request_parser({"if_match": ma.fields.Int()}, location='headers') request_data = request_body_parser( parsers=from_conf('request_body_parsers'), default_content_type=from_conf('default_content_type')) # # Resource #
import marshmallow as ma from flask import g from flask_resources import Resource, from_conf, request_body_parser, \ request_parser, resource_requestctx, response_handler, route from ..errors import ErrorHandlersMixin from .utils import es_preference # # Decorators # request_data = request_body_parser( parsers=from_conf('request_body_parsers'), default_content_type=from_conf('default_content_type')) request_read_args = request_parser(from_conf('request_read_args'), location='args') request_view_args = request_parser(from_conf('request_view_args'), location='view_args') request_headers = request_parser({"if_match": ma.fields.Int()}, location='headers') request_search_args = request_parser(from_conf('request_search_args'), location='args') # # Resource # class RecordResource(ErrorHandlersMixin, Resource):
import marshmallow as ma from flask import g from flask_resources import JSONDeserializer, RequestBodyParser, Resource, \ request_body_parser, request_parser, resource_requestctx, \ response_handler, route from ..errors import ErrorHandlersMixin from .parser import RequestStreamParser # # Decorator helpers # request_view_args = request_parser( { 'pid_value': ma.fields.Str(required=True), 'key': ma.fields.Str() }, location='view_args') request_data = request_body_parser( parsers={"application/json": RequestBodyParser(JSONDeserializer())}, default_content_type="application/json", ) request_stream = request_body_parser( parsers={"application/octet-stream": RequestStreamParser()}, default_content_type="application/octet-stream", ) #
@request_search_args @request_view_args @response_handler(many=True) def search(self): """List secret links for a record.""" items = self.service.secret_links.read_all( id_=resource_requestctx.view_args["pid_value"], identity=g.identity, ) return items.to_dict(), 200 # IIIF decorators iiif_request_view_args = request_parser( from_conf("request_view_args"), location="view_args" ) def with_iiif_content_negotiation(serializer): """Always response as JSON LD regardless of the request type.""" return with_content_negotiation( response_handlers={ "application/ld+json": ResponseHandler(serializer()), }, default_accept_mimetype="application/ld+json", ) class IIIFResource(ErrorHandlersMixin, Resource): """IIIF resource."""
# Responsibilities # - HTTP interface to the service - i.e. parses and translate an HTTP request # into a service method call. # - Request body parsing: deserialization of the request body into the common # form required by the service. # - Request (URL path, URL query string, headers) parsing. # - Performs authentication but not authorization. # A decorator we use to extract arguments from the request. user_request_parser = request_parser( # A Marshmallow schema defines the validation rules applied. {'user': ma.fields.Int(missing=None)}, # The location parameters defines from where to read the values (options # are args = request.args, view_args = request.view_args, # headers = request.headers) location='args', # Below defines what to do with unknown values (passed to marshmallow # schema). Either ma.EXCLUDE, ma.INCLUDE or ma.RAISE unknown=ma.EXCLUDE, ) class TodoResource(Resource): def __init__(self, config, service): super().__init__(config) # The service layer is injected into the resource, so that the resource # have a service instance to perform it's task with. self.service = service # # Resource API