Skip to content

Commit 52c19d4

Browse files
committed
Add configuration of access_level for runners on registration via API
Allow setting access_level of new runner to not_protected (default) or ref_protected Minor update to relevant docs and tests
1 parent 7a4b4cf commit 52c19d4

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Add option to set access_level of runners upon registration
3+
merge_request: 27490
4+
author: Zelin L
5+
type: added

doc/api/runners.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ POST /runners
486486
| `locked` | boolean| no | Whether the Runner should be locked for current project |
487487
| `run_untagged` | boolean | no | Whether the Runner should handle untagged jobs |
488488
| `tag_list` | Array[String] | no | List of Runner's tags |
489+
| `access_level` | string | no | The access_level of the runner; `not_protected` or `ref_protected` |
489490
| `maximum_timeout` | integer | no | Maximum timeout set when this Runner will handle the job |
490491

491492
```

lib/api/runner.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ class Runner < Grape::API
1515
optional :info, type: Hash, desc: %q(Runner's metadata)
1616
optional :active, type: Boolean, desc: 'Should Runner be active'
1717
optional :locked, type: Boolean, desc: 'Should Runner be locked for current project'
18+
optional :access_level, type: String, values: Ci::Runner.access_levels.keys,
19+
desc: 'The access_level of the runner'
1820
optional :run_untagged, type: Boolean, desc: 'Should Runner handle untagged jobs'
1921
optional :tag_list, type: Array[String], desc: %q(List of Runner's tags)
2022
optional :maximum_timeout, type: Integer, desc: 'Maximum timeout set when this Runner will handle the job'
2123
end
2224
post '/' do
23-
attributes = attributes_for_keys([:description, :active, :locked, :run_untagged, :tag_list, :maximum_timeout])
25+
attributes = attributes_for_keys([:description, :active, :locked, :run_untagged, :tag_list, :access_level, :maximum_timeout])
2426
.merge(get_runner_details_from_request)
2527

2628
attributes =

spec/requests/api/runner_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,32 @@
168168
end
169169
end
170170

171+
context 'when access_level is provided for Runner' do
172+
context 'when access_level is set to ref_protected' do
173+
it 'creates runner' do
174+
post api('/runners'), params: {
175+
token: registration_token,
176+
access_level: 'ref_protected'
177+
}
178+
179+
expect(response).to have_gitlab_http_status 201
180+
expect(Ci::Runner.first.ref_protected?).to be true
181+
end
182+
end
183+
184+
context 'when access_level is set to not_protected' do
185+
it 'creates runner' do
186+
post api('/runners'), params: {
187+
token: registration_token,
188+
access_level: 'not_protected'
189+
}
190+
191+
expect(response).to have_gitlab_http_status 201
192+
expect(Ci::Runner.first.ref_protected?).to be false
193+
end
194+
end
195+
end
196+
171197
context 'when maximum job timeout is specified' do
172198
it 'creates runner' do
173199
post api('/runners'), params: {

0 commit comments

Comments
 (0)