summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-08-24 17:08:32 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-04 21:55:26 +0900
commit75130a41ba19b80ac7b2300721915787ac4681bf (patch)
treee00593f96e419a149e8e3a8c0817174c25a16e45 /lib/api
parent970af9964ea9404942818d8c3394d2903955ed69 (diff)
downloadgitlab-ce-75130a41ba19b80ac7b2300721915787ac4681bf.tar.gz
Remove CreateTriggerRequestService and forbit to save variables on Ci::TriggerRequest
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/triggers.rb8
-rw-r--r--lib/api/v3/triggers.rb31
2 files changed, 23 insertions, 16 deletions
diff --git a/lib/api/triggers.rb b/lib/api/triggers.rb
index dd6801664b1..276d3b5fb79 100644
--- a/lib/api/triggers.rb
+++ b/lib/api/triggers.rb
@@ -15,16 +15,16 @@ module API
optional :variables, type: Hash, desc: 'The list of variables to be injected into build'
end
post ":id/(ref/:ref/)trigger/pipeline", requirements: { ref: /.+/ } do
+ authenticate!
+ authorize! :admin_build, user_project
+
# validate variables
params[:variables] = params[:variables].to_h
unless params[:variables].all? { |key, value| key.is_a?(String) && value.is_a?(String) }
render_api_error!('variables needs to be a map of key-valued strings', 400)
end
- project = find_project(params[:id])
- not_found! unless project
-
- result = Ci::PipelineTriggerService.new(project, nil, params).execute
+ result = Ci::PipelineTriggerService.new(user_project, nil, params).execute
not_found! unless result
if result[:http_status]
diff --git a/lib/api/v3/triggers.rb b/lib/api/v3/triggers.rb
index e9d4c35307b..ffc1a38acbc 100644
--- a/lib/api/v3/triggers.rb
+++ b/lib/api/v3/triggers.rb
@@ -16,25 +16,32 @@ module API
optional :variables, type: Hash, desc: 'The list of variables to be injected into build'
end
post ":id/(ref/:ref/)trigger/builds", requirements: { ref: /.+/ } do
- project = find_project(params[:id])
- trigger = Ci::Trigger.find_by_token(params[:token].to_s)
- not_found! unless project && trigger
- unauthorized! unless trigger.project == project
+ authenticate!
+ authorize! :admin_build, user_project
# validate variables
- variables = params[:variables].to_h
- unless variables.all? { |key, value| key.is_a?(String) && value.is_a?(String) }
+ params[:variables] = params[:variables].to_h
+ unless params[:variables].all? { |key, value| key.is_a?(String) && value.is_a?(String) }
render_api_error!('variables needs to be a map of key-valued strings', 400)
end
- # create request and trigger builds
- result = Ci::CreateTriggerRequestService.execute(project, trigger, params[:ref].to_s, variables)
- pipeline = result.pipeline
+ result = Ci::PipelineTriggerService.new(user_project, nil, params).execute
+ not_found! unless result
- if pipeline.persisted?
- present result.trigger_request, with: ::API::V3::Entities::TriggerRequest
+ if result[:http_status]
+ render_api_error!(result[:message], result[:http_status])
else
- render_validation_error!(pipeline)
+ pipeline = result[:pipeline]
+ trigger_request = pipeline.trigger_request
+
+ # Ws swtiched to Ci::PipelineVariable from Ci::TriggerRequest.variables.
+ # Ci::TriggerRequest doesn't save variables anymore.
+ # Although, to prevent braking compatibility, copying variables and present it as Ci::TriggerRequest.
+ pipeline.variables.each do |variable|
+ trigger_request.variables << { key: variable.key, value: variable.value }
+ end
+
+ present trigger_request, with: ::API::V3::Entities::TriggerRequest
end
end