diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-06-01 12:43:43 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-06-01 12:43:43 +0000 |
commit | afb2d667cae42b77e090b4b240848c4d4ddcaf2d (patch) | |
tree | 6cb66332f5ec2889bbc4e3dbd870a6b65fbe8aa1 /lib | |
parent | 709e8b263863c5a92959700b67462c2ebe4f1831 (diff) | |
parent | 5c6c184f70719c464690455abc02e777b3ba4b7b (diff) | |
download | gitlab-ce-afb2d667cae42b77e090b4b240848c4d4ddcaf2d.tar.gz |
Merge branch '46010-add-more-validations-for-runners-and-runner-type' into 'master'
Improve validations for Ci::Runner#runner_type
See merge request gitlab-org/gitlab-ce!18901
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/runner.rb | 16 | ||||
-rw-r--r-- | lib/api/runners.rb | 6 |
2 files changed, 11 insertions, 11 deletions
diff --git a/lib/api/runner.rb b/lib/api/runner.rb index 5b7ae89440c..e9886c76870 100644 --- a/lib/api/runner.rb +++ b/lib/api/runner.rb @@ -21,24 +21,26 @@ module API attributes = attributes_for_keys([:description, :active, :locked, :run_untagged, :tag_list, :maximum_timeout]) .merge(get_runner_details_from_request) - runner = + attributes = if runner_registration_token_valid? # Create shared runner. Requires admin access - Ci::Runner.create(attributes.merge(is_shared: true, runner_type: :instance_type)) + attributes.merge(is_shared: true, runner_type: :instance_type) elsif project = Project.find_by(runners_token: params[:token]) # Create a specific runner for the project - project.runners.create(attributes.merge(runner_type: :project_type)) + attributes.merge(is_shared: false, runner_type: :project_type, projects: [project]) elsif group = Group.find_by(runners_token: params[:token]) # Create a specific runner for the group - group.runners.create(attributes.merge(runner_type: :group_type)) + attributes.merge(is_shared: false, runner_type: :group_type, groups: [group]) + else + forbidden! end - break forbidden! unless runner + runner = Ci::Runner.create(attributes) - if runner.id + if runner.persisted? present runner, with: Entities::RunnerRegistrationDetails else - not_found! + render_validation_error!(runner) end end diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 5cb96d467c0..2b78075ddbf 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -133,12 +133,10 @@ module API runner = get_runner(params[:runner_id]) authenticate_enable_runner!(runner) - runner_project = runner.assign_to(user_project) - - if runner_project.persisted? + if runner.assign_to(user_project) present runner, with: Entities::Runner else - conflict!("Runner was already enabled for this project") + render_validation_error!(runner) end end |