From fba61d96dc7f60fbb158cf80f17628ec5e5e6098 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Fri, 27 Mar 2015 11:22:07 -0400 Subject: [PATCH] callbacks: add proper custom git callback --- endpoints/api/trigger.py | 10 ---------- endpoints/callbacks.py | 24 ++++++++++++++++++++++++ static/js/services/key-service.js | 3 ++- static/js/services/trigger-service.js | 4 +++- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/endpoints/api/trigger.py b/endpoints/api/trigger.py index e231c3e7e..8df544ea2 100644 --- a/endpoints/api/trigger.py +++ b/endpoints/api/trigger.py @@ -20,7 +20,6 @@ from data import model from auth.permissions import UserAdminPermission, AdministerOrganizationPermission, ReadRepositoryPermission from util.names import parse_robot_username from util.dockerfileparse import parse_dockerfile -from util.ssh import generate_ssh_keypair logger = logging.getLogger(__name__) @@ -509,12 +508,3 @@ class BuildTriggerSources(RepositoryParamResource): } else: raise Unauthorized() - -@resource('/v1/repository//trigger/redirect') -@path_param('repository', 'The full path of the repository. e.g. namespace/name') -@internal_only -class CustomBuildTriggerRedirect(RepositoryParamResource): - """ Custom verb to properly handle redirecting users using their own custom git hook. """ - @nickname('customTriggerRedirect') - def get(self, namespace, repository): - pass diff --git a/endpoints/callbacks.py b/endpoints/callbacks.py index cbe96f6e7..334374757 100644 --- a/endpoints/callbacks.py +++ b/endpoints/callbacks.py @@ -277,3 +277,27 @@ def attach_github_build_trigger(namespace, repository): return redirect(full_url) abort(403) + +@callback.route('/custom/callback/trigger/', methods=['GET']) +@callback.route('/custom/callback/trigger//__new', methods=['GET']) +@require_session_login +@parse_repository_name +def activate_custom_build_trigger(namespace, repository): + permission = AdministerRepositoryPermission(namespace, repository) + if permission.can(): + repo = model.get_repository(namespace, repository) + if not repo: + msg = 'Invalid repository: %s/%s' % (namespace, repository) + abort(404, message=msg) + + trigger = model.create_build_trigger(repo, 'custom', None, current_user.db_user()) + + # TODO(jschorr): Remove once the new layout is in place. + admin_path = '%s/%s/%s' % (namespace, repository, 'admin') + full_url = '%s%s%s' % (url_for('web.repository', path=admin_path), '?tab=trigger&new_trigger=', + trigger.uuid) + + logger.debug('Redirecting to full url: %s', full_url) + return redirect(full_url) + + abort(403) diff --git a/static/js/services/key-service.js b/static/js/services/key-service.js index 1ab153635..1c272f96e 100644 --- a/static/js/services/key-service.js +++ b/static/js/services/key-service.js @@ -14,6 +14,7 @@ angular.module('quay').factory('KeyService', ['$location', 'Config', function($l keyService['githubRedirectUri'] = Config.getUrl('/oauth2/github/callback'); keyService['googleRedirectUri'] = Config.getUrl('/oauth2/google/callback'); + keyService['customRedirectUri'] = Config.getUrl('/oauth2/custom/callback'); keyService['githubLoginUrl'] = oauth['GITHUB_LOGIN_CONFIG']['AUTHORIZE_ENDPOINT']; keyService['googleLoginUrl'] = oauth['GOOGLE_LOGIN_CONFIG']['AUTHORIZE_ENDPOINT']; @@ -60,4 +61,4 @@ angular.module('quay').factory('KeyService', ['$location', 'Config', function($l }; return keyService; -}]); \ No newline at end of file +}]); diff --git a/static/js/services/trigger-service.js b/static/js/services/trigger-service.js index f89c4f0e7..18d2a00fa 100644 --- a/static/js/services/trigger-service.js +++ b/static/js/services/trigger-service.js @@ -70,7 +70,9 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K 'name': 'commit_sha' } ], - 'get_redirect_url': function() {}, + 'get_redirect_url': function(namespace, repository) { + return KeyService['customRedirectUri'] + '/trigger/' + namespace + '/' + repository; + }, 'is_enabled': function() { return true; }, 'icon': 'fa-git', 'title': function() { return 'Custom Git Repository Push'; }