Skip to content

Commit

Permalink
Implement runner token validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed May 29, 2018
1 parent 782875a commit 71368e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/gl_objects/runners.rst
Expand Up @@ -70,6 +70,14 @@ Remove a runner::
# or
runner.delete()

Verify a registered runner token::

try:
gl.runners.verify(runner_token)
print("Valid token")
except GitlabVerifyError:
print("Invalid token")

Project runners
===============

Expand Down
4 changes: 4 additions & 0 deletions gitlab/exceptions.py
Expand Up @@ -209,6 +209,10 @@ class GitlabMarkdownError(GitlabOperationError):
pass


class GitlabVerifyError(GitlabOperationError):
pass


def on_http_error(error):
"""Manage GitlabHttpError exceptions.
Expand Down
17 changes: 17 additions & 0 deletions gitlab/v4/objects.py
Expand Up @@ -3291,6 +3291,23 @@ def all(self, scope=None, **kwargs):
query_data['scope'] = scope
return self.gitlab.http_list(path, query_data, **kwargs)

@cli.register_custom_action('RunnerManager', ('token',))
@exc.on_http_error(exc.GitlabVerifyError)
def verify(self, token, **kwargs):
"""Validates authentication credentials for a registered Runner.
Args:
token (str): The runner's authentication token
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabVerifyError: If the server failed to verify the token
"""
path = '/runners/verify'
post_data = {'token': token}
self.gitlab.http_post(path, post_data=post_data, **kwargs)


class Todo(ObjectDeleteMixin, RESTObject):
@cli.register_custom_action('Todo')
Expand Down

0 comments on commit 71368e7

Please sign in to comment.