Feed error messages through a cors wrapper so that people on other domains can see what's happening.
This commit is contained in:
parent
4673f40dd2
commit
3b3d71bfd7
18 changed files with 162 additions and 129 deletions
|
@ -2,14 +2,13 @@ import json
|
|||
import logging
|
||||
|
||||
from flask import request, url_for
|
||||
from flask.ext.restful import abort
|
||||
from urllib import quote
|
||||
from urlparse import urlunparse
|
||||
|
||||
from app import app
|
||||
from endpoints.api import (RepositoryParamResource, nickname, resource, require_repo_admin,
|
||||
log_action, request_error, query_param, parse_args,
|
||||
validate_json_request, api)
|
||||
validate_json_request, api, Unauthorized, NotFound, InvalidRequest)
|
||||
from endpoints.api.build import build_status_view, trigger_view, RepositoryBuildStatus
|
||||
from endpoints.common import start_build
|
||||
from endpoints.trigger import (BuildTrigger, TriggerDeactivationException,
|
||||
|
@ -51,7 +50,7 @@ class BuildTrigger(RepositoryParamResource):
|
|||
try:
|
||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||
except model.InvalidBuildTriggerException:
|
||||
abort(404)
|
||||
raise NotFound()
|
||||
|
||||
return trigger_view(trigger)
|
||||
|
||||
|
@ -62,8 +61,7 @@ class BuildTrigger(RepositoryParamResource):
|
|||
try:
|
||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||
except model.InvalidBuildTriggerException:
|
||||
abort(404)
|
||||
return
|
||||
raise NotFound()
|
||||
|
||||
handler = BuildTrigger.get_trigger_for_service(trigger.service.name)
|
||||
config_dict = json.loads(trigger.config)
|
||||
|
@ -102,8 +100,7 @@ class BuildTriggerSubdirs(RepositoryParamResource):
|
|||
try:
|
||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||
except model.InvalidBuildTriggerException:
|
||||
abort(404)
|
||||
return
|
||||
raise NotFound()
|
||||
|
||||
handler = BuildTrigger.get_trigger_for_service(trigger.service.name)
|
||||
user_permission = UserPermission(trigger.connected_user.username)
|
||||
|
@ -122,7 +119,7 @@ class BuildTriggerSubdirs(RepositoryParamResource):
|
|||
'message': exc.msg
|
||||
}
|
||||
else:
|
||||
abort(403)
|
||||
raise Unauthorized()
|
||||
|
||||
|
||||
@resource('/v1/repository/<path:repository>/trigger/<trigger_uuid>/activate')
|
||||
|
@ -145,12 +142,12 @@ class BuildTriggerActivate(RepositoryParamResource):
|
|||
try:
|
||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||
except model.InvalidBuildTriggerException:
|
||||
abort(404)
|
||||
raise NotFound()
|
||||
|
||||
handler = BuildTrigger.get_trigger_for_service(trigger.service.name)
|
||||
existing_config_dict = json.loads(trigger.config)
|
||||
if handler.is_active(existing_config_dict):
|
||||
abort(400)
|
||||
raise InvalidRequest('Trigger config is not sufficient for activation.')
|
||||
|
||||
user_permission = UserPermission(trigger.connected_user.username)
|
||||
if user_permission.can():
|
||||
|
@ -173,7 +170,7 @@ class BuildTriggerActivate(RepositoryParamResource):
|
|||
trigger.auth_token, new_config_dict)
|
||||
except TriggerActivationException as exc:
|
||||
token.delete_instance()
|
||||
return request_error(message=exc.message)
|
||||
raise request_error(message=exc.message)
|
||||
|
||||
# Save the updated config.
|
||||
trigger.config = json.dumps(final_config)
|
||||
|
@ -189,7 +186,7 @@ class BuildTriggerActivate(RepositoryParamResource):
|
|||
|
||||
return trigger_view(trigger)
|
||||
else:
|
||||
abort(403)
|
||||
raise Unauthorized()
|
||||
|
||||
|
||||
@resource('/v1/repository/<path:repository>/trigger/<trigger_uuid>/start')
|
||||
|
@ -203,12 +200,12 @@ class ActivateBuildTrigger(RepositoryParamResource):
|
|||
try:
|
||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||
except model.InvalidBuildTriggerException:
|
||||
abort(404)
|
||||
raise NotFound()
|
||||
|
||||
handler = BuildTrigger.get_trigger_for_service(trigger.service.name)
|
||||
existing_config_dict = json.loads(trigger.config)
|
||||
if not handler.is_active(existing_config_dict):
|
||||
abort(400)
|
||||
raise InvalidRequest('Trigger is not active.')
|
||||
|
||||
specs = handler.manual_start(trigger.auth_token, json.loads(trigger.config))
|
||||
dockerfile_id, tags, name, subdir = specs
|
||||
|
@ -253,7 +250,7 @@ class BuildTriggerSources(RepositoryParamResource):
|
|||
try:
|
||||
trigger = model.get_build_trigger(namespace, repository, trigger_uuid)
|
||||
except model.InvalidBuildTriggerException:
|
||||
abort(404)
|
||||
raise NotFound()
|
||||
|
||||
user_permission = UserPermission(trigger.connected_user.username)
|
||||
if user_permission.can():
|
||||
|
@ -263,4 +260,4 @@ class BuildTriggerSources(RepositoryParamResource):
|
|||
'sources': trigger_handler.list_build_sources(trigger.auth_token)
|
||||
}
|
||||
else:
|
||||
abort(403)
|
||||
raise Unauthorized()
|
Reference in a new issue