Skip to content

Commit 4492fc4

Browse files
committed
feat(api): add support for instance variables
1 parent da8af6f commit 4492fc4

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

gitlab/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def __init__(
139139
self.pagesdomains = objects.PagesDomainManager(self)
140140
self.user_activities = objects.UserActivitiesManager(self)
141141
self.applications = objects.ApplicationManager(self)
142+
self.variables = objects.VariableManager(self)
142143

143144
def __enter__(self):
144145
return self

gitlab/v4/objects/__init__.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from gitlab.mixins import * # noqa
2424
from gitlab import types
2525
from gitlab import utils
26+
from gitlab.v4.objects.variables import *
27+
2628

2729
VISIBILITY_PRIVATE = "private"
2830
VISIBILITY_INTERNAL = "internal"
@@ -1366,18 +1368,6 @@ class GroupSubgroupManager(ListMixin, RESTManager):
13661368
)
13671369

13681370

1369-
class GroupVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
1370-
_id_attr = "key"
1371-
1372-
1373-
class GroupVariableManager(CRUDMixin, RESTManager):
1374-
_path = "/groups/%(group_id)s/variables"
1375-
_obj_cls = GroupVariable
1376-
_from_parent_attrs = {"group_id": "id"}
1377-
_create_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
1378-
_update_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
1379-
1380-
13811371
class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
13821372
_short_print_attr = "name"
13831373
_managers = (
@@ -4116,18 +4106,6 @@ class ProjectUserManager(ListMixin, RESTManager):
41164106
_list_filters = ("search",)
41174107

41184108

4119-
class ProjectVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
4120-
_id_attr = "key"
4121-
4122-
4123-
class ProjectVariableManager(CRUDMixin, RESTManager):
4124-
_path = "/projects/%(project_id)s/variables"
4125-
_obj_cls = ProjectVariable
4126-
_from_parent_attrs = {"project_id": "id"}
4127-
_create_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
4128-
_update_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
4129-
4130-
41314109
class ProjectService(SaveMixin, ObjectDeleteMixin, RESTObject):
41324110
pass
41334111

gitlab/v4/objects/variables.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
GitLab API:
3+
https://docs.gitlab.com/ee/api/instance_level_ci_variables.html
4+
https://docs.gitlab.com/ee/api/project_level_variables.html
5+
https://docs.gitlab.com/ee/api/group_level_variables.html
6+
"""
7+
from gitlab.base import * # noqa
8+
from gitlab.mixins import * # noqa
9+
10+
11+
class Variable(SaveMixin, ObjectDeleteMixin, RESTObject):
12+
_id_attr = "key"
13+
14+
15+
class VariableManager(CRUDMixin, RESTManager):
16+
_path = "/admin/ci/variables"
17+
_obj_cls = Variable
18+
_create_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
19+
_update_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
20+
21+
22+
class GroupVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
23+
_id_attr = "key"
24+
25+
26+
class GroupVariableManager(CRUDMixin, RESTManager):
27+
_path = "/groups/%(group_id)s/variables"
28+
_obj_cls = GroupVariable
29+
_from_parent_attrs = {"group_id": "id"}
30+
_create_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
31+
_update_attrs = (("key", "value"), ("protected", "variable_type", "masked"))
32+
33+
34+
class ProjectVariable(SaveMixin, ObjectDeleteMixin, RESTObject):
35+
_id_attr = "key"
36+
37+
38+
class ProjectVariableManager(CRUDMixin, RESTManager):
39+
_path = "/projects/%(project_id)s/variables"
40+
_obj_cls = ProjectVariable
41+
_from_parent_attrs = {"project_id": "id"}
42+
_create_attrs = (
43+
("key", "value"),
44+
("protected", "variable_type", "masked", "environment_scope"),
45+
)
46+
_update_attrs = (
47+
("key", "value"),
48+
("protected", "variable_type", "masked", "environment_scope"),
49+
)

0 commit comments

Comments
 (0)