Skip to content

Commit 71368e7

Browse files
author
Gauvain Pocentek
committed
Implement runner token validation
1 parent 782875a commit 71368e7

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

docs/gl_objects/runners.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ Remove a runner::
7070
# or
7171
runner.delete()
7272

73+
Verify a registered runner token::
74+
75+
try:
76+
gl.runners.verify(runner_token)
77+
print("Valid token")
78+
except GitlabVerifyError:
79+
print("Invalid token")
80+
7381
Project runners
7482
===============
7583

gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ class GitlabMarkdownError(GitlabOperationError):
209209
pass
210210

211211

212+
class GitlabVerifyError(GitlabOperationError):
213+
pass
214+
215+
212216
def on_http_error(error):
213217
"""Manage GitlabHttpError exceptions.
214218

gitlab/v4/objects.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,6 +3291,23 @@ def all(self, scope=None, **kwargs):
32913291
query_data['scope'] = scope
32923292
return self.gitlab.http_list(path, query_data, **kwargs)
32933293

3294+
@cli.register_custom_action('RunnerManager', ('token',))
3295+
@exc.on_http_error(exc.GitlabVerifyError)
3296+
def verify(self, token, **kwargs):
3297+
"""Validates authentication credentials for a registered Runner.
3298+
3299+
Args:
3300+
token (str): The runner's authentication token
3301+
**kwargs: Extra options to send to the server (e.g. sudo)
3302+
3303+
Raises:
3304+
GitlabAuthenticationError: If authentication is not correct
3305+
GitlabVerifyError: If the server failed to verify the token
3306+
"""
3307+
path = '/runners/verify'
3308+
post_data = {'token': token}
3309+
self.gitlab.http_post(path, post_data=post_data, **kwargs)
3310+
32943311

32953312
class Todo(ObjectDeleteMixin, RESTObject):
32963313
@cli.register_custom_action('Todo')

0 commit comments

Comments
 (0)