Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing endpoints in Runners API #488

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions lib/gitlab/client/runners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,50 @@ def project_enable_runner(project_id, id)
def project_disable_runner(id, runner_id)
delete("/projects/#{url_encode id}/runners/#{runner_id}")
end

# Register a new Runner for the instance.
#
# @example
# Gitlab.register_runner('9142c16ea169eaaea3d752313a434a6e')
# Gitlab.register_runner('9142c16ea169eaaea3d752313a434a6e', description: 'Some Description', active: true, locked: false)
#
# @param [String] token Registration token.
# @param [Hash] options A customizable set of options.
# @option options [String] :description Runner description.
# @option options [Hash] :info Runner metadata.
# @option options [Boolean] :active Whether the Runner is active.
# @option options [Boolean] :locked Whether the Runner should be locked for current project.
# @option options [Boolean] :run_untagged Whether the Runner should handle untagged jobs.
# @option options [Array<String>] :tag_list List of Runner tags.
# @option options [Integer] :maximum_timeout Maximum timeout set when this Runner will handle the job.
# @return <Gitlab::ObjectifiedHash> Response against runner registration
def register_runner(token, options = {})
body = { token: token }.merge(options)
post('/runners', body: body)
end

# Deletes a registed Runner.
#
# @example
# Gitlab.delete_registered_runner('9142c16ea169eaaea3d752313a434a6e')
#
# @param [String] token Runner authentication token.
# @return [void] This API call returns an empty response body.
def delete_registered_runner(token)
body = { token: token }
delete('/runners', body: body)
end

# Validates authentication credentials for a registered Runner.
#
# @example
# Gitlab.verify_auth_registered_runner('9142c16ea169eaaea3d752313a434a6e')
#
# @param [String] token Runner authentication token.
# @return [void] This API call returns an empty response body.
def verify_auth_registered_runner(token)
body = { token: token }
post('/runners/verify', body: body)
end
end
end
4 changes: 4 additions & 0 deletions spec/fixtures/register_runner_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": "12345",
"token": "6337ff461c94fd3fa32ba3b1ff4125"
}
40 changes: 40 additions & 0 deletions spec/gitlab/client/runners_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,44 @@
expect(@runner.description).to eq('test-1-20150125')
end
end

describe '.register_runner' do
before do
stub_post('/runners', 'register_runner_response').with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125', description: 'Some Description', active: true, locked: false })
@register_runner_response = Gitlab.register_runner('6337ff461c94fd3fa32ba3b1ff4125', description: 'Some Description', active: true, locked: false)
end

it 'gets the correct resource' do
expect(a_post('/runners')
.with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125', description: 'Some Description', active: true, locked: false })).to have_been_made
end

it 'returns correct response for the runner registration' do
expect(@register_runner_response.token).to eq('6337ff461c94fd3fa32ba3b1ff4125')
end
end

describe '.delete_registered_runner' do
before do
stub_delete('/runners', 'empty').with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' })
Gitlab.delete_registered_runner('6337ff461c94fd3fa32ba3b1ff4125')
end

it 'gets the correct resource' do
expect(a_delete('/runners')
.with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' })).to have_been_made
end
end

describe '.verify_auth_registered_runner' do
before do
stub_post('/runners/verify', 'empty').with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' })
Gitlab.verify_auth_registered_runner('6337ff461c94fd3fa32ba3b1ff4125')
end

it 'gets the correct resource' do
expect(a_post('/runners/verify')
.with(body: { token: '6337ff461c94fd3fa32ba3b1ff4125' })).to have_been_made
end
end
end