callbacks: add proper custom git callback

This commit is contained in:
Jimmy Zelinskie 2015-03-27 11:22:07 -04:00
parent da15eda2bf
commit fba61d96dc
4 changed files with 29 additions and 12 deletions

View file

@ -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/<repopath: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

View file

@ -277,3 +277,27 @@ def attach_github_build_trigger(namespace, repository):
return redirect(full_url)
abort(403)
@callback.route('/custom/callback/trigger/<path:repository>', methods=['GET'])
@callback.route('/custom/callback/trigger/<path:repository>/__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)

View file

@ -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;
}]);
}]);

View file

@ -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'; }