diff --git a/docs/gl_objects/runners.rst b/docs/gl_objects/runners.rst index 726341b62..ceda32a2f 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 64f324374..6912e3388 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 bbd6c2478..071aafc89 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -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')