From dfdc3faa571151af8826488701482e399a6cbee0 Mon Sep 17 00:00:00 2001 From: jakedt Date: Fri, 14 Mar 2014 16:09:16 -0400 Subject: [PATCH] Port the remaining APIs and fix some locations. --- endpoints/api/build.py | 36 ++++++++++++++++++++++++++++++++++-- endpoints/api/legacy.py | 2 ++ endpoints/api/robot.py | 8 ++++---- endpoints/api/trigger.py | 4 ++-- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/endpoints/api/build.py b/endpoints/api/build.py index ace627433..eed2d3325 100644 --- a/endpoints/api/build.py +++ b/endpoints/api/build.py @@ -6,7 +6,8 @@ from flask.ext.restful import abort from app import app from endpoints.api import (RepositoryParamResource, parse_args, query_param, nickname, resource, - require_repo_read, require_repo_write, validate_json_request) + require_repo_read, require_repo_write, validate_json_request, + ApiResource) from endpoints.common import start_build from data import model from auth.permissions import ModifyRepositoryPermission @@ -126,7 +127,7 @@ class RepositoryBuildStatus(RepositoryParamResource): return build_status_view(build, can_write) -@resource('/repository//build//logs') +@resource('/v1/repository//build//logs') class RepositoryBuildLogs(RepositoryParamResource): """ Resource for loading repository build logs. """ @require_repo_write @@ -148,3 +149,34 @@ class RepositoryBuildLogs(RepositoryParamResource): }) return response_obj + + +@resource('/v1/filedrop/') +class FileDropResource(ApiResource): + """ Custom verb for setting up a client side file transfer. """ + schemas = { + 'FileDropRequest': { + 'id': 'FileDropRequest', + 'type': 'object', + 'description': 'Description of the file that the user wishes to upload.', + 'required': True, + 'properties': { + 'mimeType': { + 'type': 'string', + 'description': 'Type of the file which is about to be uploaded', + 'required': True, + }, + }, + }, + } + + @nickname('getFiledropUrl') + @validate_json_request('FileDropRequest') + def post(self): + """ Request a URL to which a file may be uploaded. """ + mime_type = request.get_json()['mimeType'] + (url, file_id) = user_files.prepare_for_drop(mime_type) + return { + 'url': url, + 'file_id': file_id + } diff --git a/endpoints/api/legacy.py b/endpoints/api/legacy.py index 957affcca..58be6bf0f 100644 --- a/endpoints/api/legacy.py +++ b/endpoints/api/legacy.py @@ -117,6 +117,7 @@ def welcome(): return jsonify({'version': '0.5'}) +# Ported @api_bp.route('/plans/') def list_plans(): return jsonify({ @@ -1623,6 +1624,7 @@ def delete_build_trigger(namespace, repository, trigger_uuid): abort(403) # Permission denied +# Ported @api_bp.route('/filedrop/', methods=['POST']) @api_login_required @internal_api_call diff --git a/endpoints/api/robot.py b/endpoints/api/robot.py index 74e469245..d3c9d6642 100644 --- a/endpoints/api/robot.py +++ b/endpoints/api/robot.py @@ -14,7 +14,7 @@ def robot_view(name, token): } -@resource('/user/robots') +@resource('/v1/user/robots') class UserRobotList(ApiResource): """ Resource for listing user robots. """ @nickname('getUserRobots') @@ -27,7 +27,7 @@ class UserRobotList(ApiResource): } -@resource('/user/robots/') +@resource('/v1/user/robots/') class UserRobot(ApiResource): """ Resource for managing a user's robots. """ @nickname('createUserRobot') @@ -49,7 +49,7 @@ class UserRobot(ApiResource): return 'Deleted', 204 -@resource('/organization//robots') +@resource('/v1/organization//robots') class OrgRobotList(ApiResource): """ Resource for listing an organization's robots. """ @nickname('getOrgRobots') @@ -66,7 +66,7 @@ class OrgRobotList(ApiResource): abort(403) -@resource('/organization//robots/') +@resource('/v1/organization//robots/') class OrgRobot(ApiResource): """ Resource for managing an organization's robots. """ @nickname('createOrgRobot') diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index 640f27e9f..9c5ccc698 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -209,7 +209,7 @@ class BuildTriggerActivate(RepositoryParamResource): abort(403) -@resource('/repository//trigger//start') +@resource('/v1/repository//trigger//start') class ActivateBuildTrigger(RepositoryParamResource): """ Custom verb to manually activate a build trigger. """ @@ -260,7 +260,7 @@ class TriggerBuildList(RepositoryParamResource): } -@resource('/repository//trigger//sources') +@resource('/v1/repository//trigger//sources') class BuildTriggerSources(RepositoryParamResource): """ Custom verb to fetch the list of build sources for the trigger config. """ @require_repo_admin