Change ApiService to use the new swagger-backed discovery and the new /v1/ API endpoints. Also changes all other /api/ calls (the few that are still manually invoked)

This commit is contained in:
Joseph Schorr 2014-03-14 23:40:41 -04:00
parent 767ab1085a
commit e759066ae0
4 changed files with 87 additions and 79 deletions

View file

@ -12,6 +12,7 @@ from data import model
from data.queue import dockerfile_build_queue
from app import app, login_manager
from auth.permissions import QuayDeferredPermissionUser
from api.discovery import swagger_route_data
logger = logging.getLogger(__name__)
@ -24,29 +25,7 @@ def get_route_data():
if route_data:
return route_data
routes = []
for rule in app.url_map.iter_rules():
if rule.endpoint.startswith('api.'):
endpoint_method = app.view_functions[rule.endpoint]
is_internal = '__internal_call' in dir(endpoint_method)
is_org_api = '__user_call' in dir(endpoint_method)
methods = list(rule.methods.difference(['HEAD', 'OPTIONS']))
route = {
'name': rule.endpoint[4:],
'methods': methods,
'path': rule.rule,
'parameters': list(rule.arguments)
}
if is_org_api:
route['user_method'] = endpoint_method.__user_call
routes.append(route)
route_data = {
'endpoints': routes
}
route_data = swagger_route_data(include_internal=True, compact=True)
return route_data
@ -114,7 +93,7 @@ app.jinja_env.globals['csrf_token'] = generate_csrf_token
def render_page_template(name, **kwargs):
resp = make_response(render_template(name, route_data=get_route_data(),
resp = make_response(render_template(name, route_data=json.dumps(get_route_data()),
**kwargs))
resp.headers['X-FRAME-OPTIONS'] = 'DENY'
return resp
@ -160,4 +139,4 @@ def start_build(repository, dockerfile_id, tags, build_name, subdir, manual,
ip=request.remote_addr, metadata=metadata,
repository=repository)
return build_request
return build_request