diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-29 09:17:55 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2018-05-29 09:17:55 +0200 |
commit | 71368e7292b0e6d0f0dab9039983fa35689eeab0 (patch) | |
tree | 8b13bd0fd56285ea778a4a225234cec9db77ff71 | |
parent | 782875a4d04bf3ebd9a0ae43240aadcde02a24f5 (diff) | |
download | gitlab-71368e7292b0e6d0f0dab9039983fa35689eeab0.tar.gz |
Implement runner token validation
-rw-r--r-- | docs/gl_objects/runners.rst | 8 | ||||
-rw-r--r-- | gitlab/exceptions.py | 4 | ||||
-rw-r--r-- | gitlab/v4/objects.py | 17 |
3 files changed, 29 insertions, 0 deletions
diff --git a/docs/gl_objects/runners.rst b/docs/gl_objects/runners.rst index 726341b..ceda32a 100644 --- a/docs/gl_objects/runners.rst +++ b/docs/gl_objects/runners.rst @@ -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 =============== diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 64f3243..6912e33 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -209,6 +209,10 @@ class GitlabMarkdownError(GitlabOperationError): pass +class GitlabVerifyError(GitlabOperationError): + pass + + def on_http_error(error): """Manage GitlabHttpError exceptions. diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index bbd6c24..071aafc 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -3291,6 +3291,23 @@ class RunnerManager(CRUDMixin, RESTManager): 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') |