Add internal API filtering.
This commit is contained in:
parent
5ca594b641
commit
60015f0ae0
6 changed files with 38 additions and 11 deletions
|
@ -3,7 +3,8 @@ import logging
|
|||
|
||||
from flask.ext.restful import reqparse
|
||||
|
||||
from endpoints.api import ApiResource, resource, method_metadata, nickname, truthy_bool
|
||||
from endpoints.api import (ApiResource, resource, method_metadata, nickname, truthy_bool,
|
||||
parse_args, query_param)
|
||||
from app import app
|
||||
from auth import scopes
|
||||
|
||||
|
@ -28,7 +29,7 @@ def fully_qualified_name(method_view_class):
|
|||
return '%s.%s' % (inst.__module__, inst.__class__.__name__)
|
||||
|
||||
|
||||
def swagger_route_data():
|
||||
def swagger_route_data(include_internal):
|
||||
apis = []
|
||||
models = {}
|
||||
for rule in app.url_map.iter_rules():
|
||||
|
@ -94,10 +95,15 @@ def swagger_route_data():
|
|||
scope = method_metadata(method, 'oauth2_scope')
|
||||
if scope:
|
||||
new_operation['authorizations'] = {
|
||||
'oauth2': [scope]
|
||||
'oauth2': [scope],
|
||||
}
|
||||
|
||||
operations.append(new_operation)
|
||||
internal = method_metadata(method, 'internal')
|
||||
if internal is not None:
|
||||
new_operation['internal'] = True
|
||||
|
||||
if not internal or (internal and include_internal):
|
||||
operations.append(new_operation)
|
||||
|
||||
swagger_path = PARAM_REGEX.sub(r'{\2}', rule.rule)
|
||||
new_resource = {
|
||||
|
@ -106,11 +112,17 @@ def swagger_route_data():
|
|||
'operations': operations,
|
||||
'name': fully_qualified_name(view_class),
|
||||
}
|
||||
|
||||
related_user_res = method_metadata(view_class, 'related_user_resource')
|
||||
if related_user_res is not None:
|
||||
new_resource['quayUserRelated'] = fully_qualified_name(related_user_res)
|
||||
|
||||
apis.append(new_resource)
|
||||
internal = method_metadata(view_class, 'internal')
|
||||
if internal is not None:
|
||||
new_resource['internal'] = True
|
||||
|
||||
if not internal or (internal and include_internal):
|
||||
apis.append(new_resource)
|
||||
|
||||
swagger_data = {
|
||||
'apiVersion': 'v1',
|
||||
|
@ -146,7 +158,9 @@ def swagger_route_data():
|
|||
@resource('/v1/discovery')
|
||||
class DiscoveryResource(ApiResource):
|
||||
"""Ability to inspect the API for usage information and documentation."""
|
||||
@parse_args
|
||||
@query_param('internal', 'Whether to include internal APIs.', type=truthy_bool, default=False)
|
||||
@nickname('discovery')
|
||||
def get(self):
|
||||
def get(self, args):
|
||||
""" List all of the API endpoints available in the swagger API format."""
|
||||
return swagger_route_data()
|
||||
return swagger_route_data(args['internal'])
|
||||
|
|
Reference in a new issue