diff options
author | Rémy Coutable <remy@rymai.me> | 2016-06-21 10:08:42 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-06-21 10:08:42 +0000 |
commit | f90c8c624d2bf0391a25ae07b1516d11948e1a81 (patch) | |
tree | fd07addffeec378dacf626d98e9ffbbb645dee1e /lib | |
parent | 027b07cab884d0edae16bc94ae10d604fb4d042c (diff) | |
parent | cdcbc8d7219a669c016aaba89a1d47faebdd2208 (diff) | |
download | gitlab-ce-f90c8c624d2bf0391a25ae07b1516d11948e1a81.tar.gz |
Merge branch 'feature/runner-lock-on-project' into 'master'
Make it possible to lock runner on a specific project
Make it possible to lock runner on a specific project.

----

----

Closes #3407
See merge request !4093
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/runners.rb | 12 | ||||
-rw-r--r-- | lib/ci/api/runners.rb | 9 |
3 files changed, 13 insertions, 9 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2e397643ed1..3fde7aa989f 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -423,6 +423,7 @@ module API class RunnerDetails < Runner expose :tag_list expose :run_untagged + expose :locked expose :version, :revision, :platform, :architecture expose :contacted_at expose :token, if: lambda { |runner, options| options[:current_user].is_admin? || !runner.is_shared? } diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 4faba9dc87b..ecc8f2fc5a2 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -49,7 +49,7 @@ module API runner = get_runner(params[:id]) authenticate_update_runner!(runner) - attrs = attributes_for_keys [:description, :active, :tag_list, :run_untagged] + attrs = attributes_for_keys [:description, :active, :tag_list, :run_untagged, :locked] if runner.update(attrs) present runner, with: Entities::RunnerDetails, current_user: current_user else @@ -96,9 +96,14 @@ module API runner = get_runner(params[:runner_id]) authenticate_enable_runner!(runner) - Ci::RunnerProject.create(runner: runner, project: user_project) - present runner, with: Entities::Runner + runner_project = runner.assign_to(user_project) + + if runner_project.persisted? + present runner, with: Entities::Runner + else + conflict!("Runner was already enabled for this project") + end end # Disable project's runner @@ -163,6 +168,7 @@ module API def authenticate_enable_runner!(runner) forbidden!("Runner is shared") if runner.is_shared? + forbidden!("Runner is locked") if runner.locked? return if current_user.is_admin? forbidden!("No access granted") unless user_can_access_runner?(runner) end diff --git a/lib/ci/api/runners.rb b/lib/ci/api/runners.rb index 0c41f22c7c5..bcc82969eb3 100644 --- a/lib/ci/api/runners.rb +++ b/lib/ci/api/runners.rb @@ -28,12 +28,9 @@ module Ci post "register" do required_attributes! [:token] - attributes = { description: params[:description], - tag_list: params[:tag_list] } - - unless params[:run_untagged].nil? - attributes[:run_untagged] = params[:run_untagged] - end + attributes = attributes_for_keys( + [:description, :tag_list, :run_untagged, :locked] + ) runner = if runner_registration_token_valid? |