diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2021-02-07 00:29:59 +0100 |
---|---|---|
committer | Nejc Habjan <hab.nejc@gmail.com> | 2021-02-07 16:05:05 +0100 |
commit | a5a48ad08577be70c6ca511d3b4803624e5c2043 (patch) | |
tree | c1b80daad6dbb6ea3b1a3498d70016ef77abf6b3 /gitlab/v4/objects/runners.py | |
parent | 9d6c1882d567116e16484f3e0a1036da4967c537 (diff) | |
download | gitlab-a5a48ad08577be70c6ca511d3b4803624e5c2043.tar.gz |
refactor(v4): split objects and managers per API resource
Diffstat (limited to 'gitlab/v4/objects/runners.py')
-rw-r--r-- | gitlab/v4/objects/runners.py | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/gitlab/v4/objects/runners.py b/gitlab/v4/objects/runners.py new file mode 100644 index 0000000..1ce5437 --- /dev/null +++ b/gitlab/v4/objects/runners.py @@ -0,0 +1,118 @@ +from gitlab import cli +from gitlab import exceptions as exc +from gitlab.base import * # noqa +from gitlab.mixins import * # noqa + + +class RunnerJob(RESTObject): + pass + + +class RunnerJobManager(ListMixin, RESTManager): + _path = "/runners/%(runner_id)s/jobs" + _obj_cls = RunnerJob + _from_parent_attrs = {"runner_id": "id"} + _list_filters = ("status",) + + +class Runner(SaveMixin, ObjectDeleteMixin, RESTObject): + _managers = (("jobs", "RunnerJobManager"),) + + +class RunnerManager(CRUDMixin, RESTManager): + _path = "/runners" + _obj_cls = Runner + _list_filters = ("scope",) + _create_attrs = ( + ("token",), + ( + "description", + "info", + "active", + "locked", + "run_untagged", + "tag_list", + "access_level", + "maximum_timeout", + ), + ) + _update_attrs = ( + tuple(), + ( + "description", + "active", + "tag_list", + "run_untagged", + "locked", + "access_level", + "maximum_timeout", + ), + ) + + @cli.register_custom_action("RunnerManager", tuple(), ("scope",)) + @exc.on_http_error(exc.GitlabListError) + def all(self, scope=None, **kwargs): + """List all the runners. + + Args: + scope (str): The scope of runners to show, one of: specific, + shared, active, paused, online + all (bool): If True, return all the items, without pagination + per_page (int): Number of items to retrieve per request + page (int): ID of the page to return (starts with page 1) + as_list (bool): If set to False and no pagination option is + defined, return a generator instead of a list + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabListError: If the server failed to perform the request + + Returns: + list(Runner): a list of runners matching the scope. + """ + path = "/runners/all" + query_data = {} + if scope is not None: + query_data["scope"] = scope + obj = self.gitlab.http_list(path, query_data, **kwargs) + return [self._obj_cls(self, item) for item in obj] + + @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 GroupRunner(ObjectDeleteMixin, RESTObject): + pass + + +class GroupRunnerManager(NoUpdateMixin, RESTManager): + _path = "/groups/%(group_id)s/runners" + _obj_cls = GroupRunner + _from_parent_attrs = {"group_id": "id"} + _create_attrs = (("runner_id",), tuple()) + + +class ProjectRunner(ObjectDeleteMixin, RESTObject): + pass + + +class ProjectRunnerManager(NoUpdateMixin, RESTManager): + _path = "/projects/%(project_id)s/runners" + _obj_cls = ProjectRunner + _from_parent_attrs = {"project_id": "id"} + _create_attrs = (("runner_id",), tuple()) |