Python flask_restplus.Resource() Examples
The following are 18
code examples of flask_restplus.Resource().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_restplus
, or try the search function
.
Example #1
Source File: activate.py From treadmill with Apache License 2.0 | 6 votes |
def init(api, cors, impl): """Configures REST handlers for docker authz resource.""" del cors namespace = api.namespace( _URL, description='Docker authz plugin activate call' ) # only /Plugin.Activate allowd, /Plugin.Activate/ not allowed @namespace.route('') class _Activate(restplus.Resource): """Treadmill docker authz plugin activate resource""" def post(self): """Returns plugin name monitors.""" status = http.client.OK return flask.Response( json.dumps(impl.activate()), status=status, mimetype='application/json' ) # return URL explicitly because there is '.' in URL return _URL
Example #2
Source File: entitysearch.py From biolink-api with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get(self, term): """ Returns list of matching concepts or entities using lexical search """ args = simple_parser.parse_args() args['fq_string'] = copy.copy(args['fq']) args['fq'] = {} q = GolrSearchQuery(term, user_agent=USER_AGENT, **args) results = q.autocomplete() return results #@ns.route('/entity/query/') #class BooleanQuery(Resource): # # @api.expect(adv_parser) # def get(self, search_term): # """ # Returns list of matches based on # """ # args = parser.parse_args() # # return []
Example #3
Source File: nodeinfo.py From treadmill with Apache License 2.0 | 6 votes |
def init(api, _cors, impl): """Configures REST handlers for allocation resource.""" namespace = webutils.namespace( api, __name__, 'Local nodeinfo redirect API.' ) @namespace.route('/<hostname>/<path:path>') class _NodeRedirect(restplus.Resource): """Redirects to local nodeinfo endpoint.""" def get(self, hostname, path): """Returns list of local instances.""" hostport = impl.get(hostname) if not hostport: return 'Host not found.', http_client.NOT_FOUND url = utils.encode_uri_parts(path) return flask.redirect('http://%s/%s' % (hostport, url), code=http_client.FOUND)
Example #4
Source File: trace.py From treadmill with Apache License 2.0 | 5 votes |
def init(api, cors, impl): """Configures REST handlers for state resource.""" namespace = webutils.namespace( api, __name__, 'Trace REST operations' ) model = { 'name': fields.String(description='Application name'), 'instances': fields.List( fields.String(description='Instance IDs') ), } trace_model = api.model( 'Trace', model ) @namespace.route('/<app_name>') @api.doc(params={'app_name': 'Application name'}) class _TraceAppResource(restplus.Resource): """Treadmill application trace information resource. """ @webutils.get_api(api, cors, marshal=api.marshal_with, resp_model=trace_model) def get(self, app_name): """Return trace information of a Treadmill application. """ trace_info = impl.get(app_name) if trace_info is None: raise exc.NotFoundError( 'No trace information available for {}'.format(app_name) ) return trace_info
Example #5
Source File: limit_test.py From treadmill with Apache License 2.0 | 5 votes |
def setUp(self): """Initialize the app with the corresponding limit logic.""" blueprint = flask.Blueprint('v1', __name__) self.api = restplus.Api(blueprint) self.app = flask.Flask(__name__) self.app.testing = True self.app.register_blueprint(blueprint) na = self.api.namespace( 'na', description='Request Rate Control REST API Test', ) @na.route('/foo') class _Foo(restplus.Resource): """Request rate control resource example""" def get(self): """Get resource implement""" return '' @na.route('/bar') class _Bar(restplus.Resource): """Request rate control resource example""" def get(self): """Get resource implement""" return '' nb = self.api.namespace( 'nb', description='Request Rate Control REST API Test', ) @nb.route('/baz') class _Baz(restplus.Resource): """Request rate control resource example""" def get(self): """Get resource implement""" return ''
Example #6
Source File: authzreq.py From treadmill with Apache License 2.0 | 5 votes |
def init(api, cors, impl): """Configures REST handlers for docker authz resource.""" del cors namespace = api.namespace( _URL, description='Docker authz plugin authz request call' ) # authz plugin does not accept tailing '/' @namespace.route('') class _Authz(restplus.Resource): """Treadmill App monitor resource""" def post(self): """Returns list of configured app monitors.""" status = http.client.OK payload = flask.request.get_json(force=True) (allow, msg) = impl.authzreq(payload) return flask.Response( json.dumps({'Allow': allow, 'Msg': msg}), status=status, mimetype='application/json' ) # return URL explicitly because there is '.' in URL return _URL
Example #7
Source File: authzres.py From treadmill with Apache License 2.0 | 5 votes |
def init(api, cors, impl): """Configures REST handlers for docker authz resource.""" del cors namespace = api.namespace( _URL, description='Docker authz plugin authz response call' ) # authz plugin does not accept tailing '/' @namespace.route('') class _Authz(restplus.Resource): """Treadmill App monitor resource""" def post(self): """Returns list of configured app monitors.""" status = http.client.OK payload = flask.request.get_json(force=True) (allow, msg) = impl.authzres(payload) return flask.Response( json.dumps({'allow': allow, 'msg': msg}), status=status, mimetype='application/json' ) # return URL explicitly because there is '.' in URL return _URL
Example #8
Source File: authz_base.py From treadmill with Apache License 2.0 | 5 votes |
def __init__(self, impl, api, *args, **kwargs): """ :param impl: custom authorizer which should implement a function with signature `authorize(user, action, resource, payload)`. :param api: reserved parameter for `restplus.Resource`. """ super(AuthzAPIBase, self).__init__(api, *args, **kwargs) self.impl = impl
Example #9
Source File: authz_base.py From treadmill with Apache License 2.0 | 5 votes |
def register_authz_resource(resource, api, description): """Register a resource for authz namespace. :param resource: sub-class inherited from AuthzAPIBase. :param api: reserved parameter for `restplus.Resource`. :param description: reserved parameter for `restplus.Resource`. """ namespace = webutils.namespace(api, '', description) namespace.add_resource(resource, _ROUTE)
Example #10
Source File: keytab_locker.py From treadmill with Apache License 2.0 | 5 votes |
def init(api, _cors, impl): """Configures REST handlers for keytab resource.""" namespace = webutils.namespace( api, __name__, 'Keytab Locker REST operations' ) @namespace.route('/') class _KeytabList(restplus.Resource): """Treadmill Keytab list resource""" def get(self): """Returns list of available keytabs.""" return impl.list()
Example #11
Source File: test_api_endpoints.py From indras_net with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.hello_world = HelloWorld(Resource) self.endpoints = Endpoints(Resource) self.model = Models(Resource) self.props = Props(Resource) self.model_menu = ModelMenu(Resource) self.run = RunModel(Resource) self.models = load_models(indra_dir)
Example #12
Source File: ontology_endpoint.py From biolink-api with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get(self, id): """ Returns graph of an ontology term """ args = graph_params.parse_args() graph_type = args['graph_type'] + "_json" # GOLR field names data = run_solr_on(ESOLR.GOLR, ESOLRDoc.ONTOLOGY, id, graph_type) # step required as these graphs are stringified in the json data[graph_type] = json.loads(data[graph_type]) return data # @ns.route('/term/<id>/ancestor') # class OntologyTermAncestor(Resource): # def get(self, id): # """ # Returns ancestors of an ontology term # """ # return None # @ns.route('/term/<id>/descendant') # class OntologyTermDescendant(Resource): # def get(self, id): # """ # Returns descendants of an ontology term # """ # ont = get_ontology("go") # print("ONT: ", ont) # print("GRAPH: ", ont.get_graph()) # return None
Example #13
Source File: app.py From lopocs with GNU Lesser General Public License v2.1 | 5 votes |
def validate_resource(resource): '''Resource is a table name with schema and column name combined as follow : schema.table.column ''' if resource.count('.') != 2: api.abort(404, "resource must be in the form schema.table.column") table = resource[:resource.rfind('.')] column = resource.split('.')[-1] return table, column
Example #14
Source File: endpoint.py From lost with MIT License | 5 votes |
def get(self): dbm = access.DBMan(LOST_CONFIG) identity = get_jwt_identity() user = dbm.get_user_by_id(identity) if not user.has_role(roles.ANNOTATOR): dbm.close_session() return "You need to be {} in order to perform this request.".format(roles.ANNOTATOR), 401 else: re = sia.finish(dbm, identity) dbm.close_session() return re # @namespace.route('/junk/<int:img_id>') # @namespace.param('img_id', 'The id of the image which should be junked.') # class Junk(Resource): # @jwt_required # def post(self,img_id): # dbm = access.DBMan(LOST_CONFIG) # identity = get_jwt_identity() # user = dbm.get_user_by_id(identity) # if not user.has_role(roles.ANNOTATOR): # dbm.close_session() # return "You need to be {} in order to perform this request.".format(roles.ANNOTATOR), 401 # else: # re = sia.get_prev(dbm, identity,img_id) # dbm.close_session() # return re
Example #15
Source File: server.py From treadmill with Apache License 2.0 | 4 votes |
def init(api, cors, impl): """Configures REST handlers for server resource.""" namespace = webutils.namespace(api, __name__, 'Server REST operations') req_parser = api.parser() req_parser.add_argument('cell', help='Cell', location='args', required=False) req_parser.add_argument('partition', help='Partition', location='args', required=False) @namespace.route('/',) class _ServerList(restplus.Resource): """Treadmill Server resource""" @webutils.get_api(api, cors, parser=req_parser) def get(self): """Returns list of configured servers.""" args = req_parser.parse_args() return impl.list(args.get('cell'), args.get('partition')) @namespace.route('/<server_id>') class _ServerResource(restplus.Resource): """Treadmill Server resource.""" @webutils.get_api(api, cors) def get(self, server_id): """Return Treadmill server configuration.""" return impl.get(server_id) @webutils.delete_api(api, cors) def delete(self, server_id): """Deletes Treadmill server.""" return impl.delete(server_id) @webutils.put_api(api, cors) def put(self, server_id): """Updates Treadmill server configuration.""" return impl.update(server_id, flask.request.json) @webutils.post_api(api, cors) def post(self, server_id): """Creates Treadmill server.""" return impl.create(server_id, flask.request.json)
Example #16
Source File: ticket_locker.py From treadmill with Apache License 2.0 | 4 votes |
def init(api, cors, impl): """Configures REST handlers for cell resource.""" namespace = webutils.namespace( api, __name__, 'Ticket Locker REST operations' ) model = { 'expires_at': fields.Integer(description='Ticket expiration time.'), } resp_model = api.model( 'Ticket', model ) @namespace.route('/') class _TicketsList(restplus.Resource): """Treadmill Ticket list resource""" def get(self): """Returns list of available tickets.""" return impl.list() @namespace.route('/@') class _TickeUserResource(restplus.Resource): """Treadmill Ticket resource.""" @webutils.get_api(api, cors, marshal=api.marshal_with, resp_model=resp_model) def get(self): """Return Treadmill Ticket details for the authenticated user.""" return impl.get(flask.g.get('user')) @namespace.route('/<principal>') @api.doc(params={'principal': 'Principal name'}) class _TicketResource(restplus.Resource): """Treadmill Ticket resource.""" @webutils.get_api(api, cors, marshal=api.marshal_with, resp_model=resp_model) def get(self, principal): """Return Treadmill Ticket details.""" return impl.get(principal)
Example #17
Source File: summary.py From biolink-api with BSD 3-Clause "New" or "Revised" License | 4 votes |
def get(self): """ Returns compact associations for a given input set """ args = parser.parse_args() M=GolrFields() subjects = args.get('subject') del args['subject'] results = search_associations( subjects=subjects, select_fields=[M.SUBJECT, M.RELATION, M.OBJECT], use_compact_associations=True, rows=MAX_ROWS, facet_fields=[], user_agent=USER_AGENT, **args ) return results #@ns.route('/DEPRECATEDhomologs/') #class EntitySetHomologsDEPRECATED(Resource): # # @api.expect(parser) # @api.marshal_list_with(association_results) # #@api.marshal_list_with(compact_association_set) # def get(self): # """ # Returns homology associations for a given input set of genes # """ # args = parser.parse_args() # # M=GolrFields() # rel = 'RO:0002434' # TODO; allow other types # results = search_associations(subjects=args.get('subject'), # select_fields=[M.SUBJECT, M.RELATION, M.OBJECT], # use_compact_associations=True, # relation=rel, # rows=MAX_ROWS, # facet_fields=[], # **args) # return results
Example #18
Source File: ontology_endpoint.py From biolink-api with BSD 3-Clause "New" or "Revised" License | 4 votes |
def get(self, id): """ Returns meta data of an ontology subset (slim) """ query = subset(self, id) results = run_sparql_on(query, EOntology.GO) return transformArray(results, []) # @ns.route('/term/<id>/related') # @api.doc(params={'id': 'CURIE identifier of a GO term, e.g. GO:0030182'}) # class OntologyTermsRelated(Resource): # @api.expect(related_params) # def get(self, id): # """ # Returns related ontology terms based on a given relationship type # """ # args = related_params.parse_args() # relationship = args['relationship_type'] # closure = relationship + "_closure" # closure_label = relationship + "_closure_label" # data = run_solr_on(ESOLR.GOLR, ESOLRDoc.ONTOLOGY, id, closure + "," + closure_label) # data = mergeWithLabels(data, closure, "goid", closure_label, "label") # # args = { # # "q": "*:*", # # "fq": "id:\"" + id + "\"", # # "url": "http://golr-aux.geneontology.io/solr/", # # "category": "ontology_class" # # } # # print(args) # # GolrSearchQuery(term=id, category="ontology_class", url="http://golr-aux.geneontology.io/solr/", fq="id:\"" + id + "\"") # # q = GolrSearchQuery(id, args) # # print("QUERY RESYLT: " , q.search()) # return data # @ns.route('/relation/<subject>/<object>') # @api.doc(params={'subject': 'CURIE identifier of a GO term, e.g. GO:0006259', # 'object': 'CURIE identifier of a GO term, e.g. GO:0046483' }) # class OntologyTermsRelation(Resource): # def get(self, subject, object): # """ # Returns relations between two ontology terms # """ # return None