- Make the discovery information be preloaded via a bootstrap.js file before angular runs
- Have ApiService generate all the api methods specified by the API discovery information - Change all call sites (except for a select few when it does not make sense) to use ApiService
This commit is contained in:
parent
1904e6d0c8
commit
56bb46ffb2
6 changed files with 423 additions and 212 deletions
|
@ -69,6 +69,17 @@ def internal_api_call(f):
|
|||
return decorated_view
|
||||
|
||||
|
||||
def org_api_call(user_call_name):
|
||||
def internal_decorator(f):
|
||||
@wraps(f)
|
||||
def decorated_view(*args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
|
||||
decorated_view.__user_call = user_call_name
|
||||
return decorated_view
|
||||
|
||||
return internal_decorator
|
||||
|
||||
@app.errorhandler(model.DataModelException)
|
||||
def handle_dme(ex):
|
||||
return make_response(ex.message, 400)
|
||||
|
@ -79,6 +90,32 @@ def handle_dme_key_error(ex):
|
|||
return make_response(ex.message, 400)
|
||||
|
||||
|
||||
@app.route('/api/discovery')
|
||||
def discovery():
|
||||
routes = []
|
||||
for rule in app.url_map.iter_rules():
|
||||
if rule.rule.startswith('/api/'):
|
||||
endpoint_method = globals()[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,
|
||||
'methods': methods,
|
||||
'path': rule.rule,
|
||||
'parameters': list(rule.arguments)
|
||||
}
|
||||
|
||||
if is_org_api:
|
||||
route['user_method'] = endpoint_method.__user_call
|
||||
|
||||
routes.append(route)
|
||||
|
||||
return jsonify({
|
||||
'endpoints': routes
|
||||
})
|
||||
|
||||
@app.route('/api/')
|
||||
@internal_api_call
|
||||
def welcome():
|
||||
|
@ -438,6 +475,7 @@ def get_organization(orgname):
|
|||
|
||||
@app.route('/api/organization/<orgname>', methods=['PUT'])
|
||||
@api_login_required
|
||||
@org_api_call('change_user_details')
|
||||
def change_organization_details(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1466,6 +1504,7 @@ def get_user_card():
|
|||
@app.route('/api/organization/<orgname>/card', methods=['GET'])
|
||||
@api_login_required
|
||||
@internal_api_call
|
||||
@org_api_call('get_user_card')
|
||||
def get_org_card(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1488,6 +1527,7 @@ def set_user_card():
|
|||
|
||||
@app.route('/api/organization/<orgname>/card', methods=['POST'])
|
||||
@api_login_required
|
||||
@org_api_call('set_user_card')
|
||||
def set_org_card(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1642,6 +1682,7 @@ def list_user_invoices():
|
|||
|
||||
@app.route('/api/organization/<orgname>/invoices', methods=['GET'])
|
||||
@api_login_required
|
||||
@org_api_call('list_user_invoices')
|
||||
def list_org_invoices(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1679,6 +1720,7 @@ def get_invoices(customer_id):
|
|||
@app.route('/api/organization/<orgname>/plan', methods=['PUT'])
|
||||
@api_login_required
|
||||
@internal_api_call
|
||||
@org_api_call('update_user_subscription')
|
||||
def update_org_subscription(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1694,7 +1736,7 @@ def update_org_subscription(orgname):
|
|||
@app.route('/api/user/plan', methods=['GET'])
|
||||
@api_login_required
|
||||
@internal_api_call
|
||||
def get_subscription():
|
||||
def get_user_subscription():
|
||||
user = current_user.db_user()
|
||||
private_repos = model.get_private_repo_count(user.username)
|
||||
|
||||
|
@ -1713,6 +1755,7 @@ def get_subscription():
|
|||
@app.route('/api/organization/<orgname>/plan', methods=['GET'])
|
||||
@api_login_required
|
||||
@internal_api_call
|
||||
@org_api_call('get_user_subscription')
|
||||
def get_org_subscription(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1751,6 +1794,7 @@ def get_user_robots():
|
|||
|
||||
@app.route('/api/organization/<orgname>/robots', methods=['GET'])
|
||||
@api_login_required
|
||||
@org_api_call('get_user_robots')
|
||||
def get_org_robots(orgname):
|
||||
permission = OrganizationMemberPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1764,7 +1808,7 @@ def get_org_robots(orgname):
|
|||
|
||||
@app.route('/api/user/robots/<robot_shortname>', methods=['PUT'])
|
||||
@api_login_required
|
||||
def create_robot(robot_shortname):
|
||||
def create_user_robot(robot_shortname):
|
||||
parent = current_user.db_user()
|
||||
robot, password = model.create_robot(robot_shortname, parent)
|
||||
resp = jsonify(robot_view(robot.username, password))
|
||||
|
@ -1776,6 +1820,7 @@ def create_robot(robot_shortname):
|
|||
@app.route('/api/organization/<orgname>/robots/<robot_shortname>',
|
||||
methods=['PUT'])
|
||||
@api_login_required
|
||||
@org_api_call('create_user_robot')
|
||||
def create_org_robot(orgname, robot_shortname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1791,7 +1836,7 @@ def create_org_robot(orgname, robot_shortname):
|
|||
|
||||
@app.route('/api/user/robots/<robot_shortname>', methods=['DELETE'])
|
||||
@api_login_required
|
||||
def delete_robot(robot_shortname):
|
||||
def delete_user_robot(robot_shortname):
|
||||
parent = current_user.db_user()
|
||||
model.delete_robot(format_robot_username(parent.username, robot_shortname))
|
||||
log_action('delete_robot', parent.username, {'robot': robot_shortname})
|
||||
|
@ -1801,6 +1846,7 @@ def delete_robot(robot_shortname):
|
|||
@app.route('/api/organization/<orgname>/robots/<robot_shortname>',
|
||||
methods=['DELETE'])
|
||||
@api_login_required
|
||||
@org_api_call('delete_user_robot')
|
||||
def delete_org_robot(orgname, robot_shortname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
@ -1848,6 +1894,7 @@ def list_repo_logs(namespace, repository):
|
|||
|
||||
@app.route('/api/organization/<orgname>/logs', methods=['GET'])
|
||||
@api_login_required
|
||||
@org_api_call('list_user_logs')
|
||||
def list_org_logs(orgname):
|
||||
permission = AdministerOrganizationPermission(orgname)
|
||||
if permission.can():
|
||||
|
|
Reference in a new issue