Content-Length: 503883 | pFad | https://github.com/python-gitlab/python-gitlab/commit/849301b830b0d4f76ab85ffa3f39b22a6e628df9

B6 fix(api): update CI/CD variable create and update attributes · python-gitlab/python-gitlab@849301b · GitHub
Skip to content

Commit 849301b

Browse files
fix(api): update CI/CD variable create and update attributes
Make `value` optional when updating CI/CD variables. Variables marked as `masked_and_hidden` have their value hidden by GitLab and cannot be retrieved, so `value` must not be required for updates. Add `masked_and_hidden` to optional create attributes for group and project variables (admin variables do not support this attribute). Also expand the optional attributes for all three variable managers (admin, group, project) to include `description`, `raw`, and `environment_scope` where applicable, aligning with the GitLab API. Add functional tests covering create, get, update, and delete of masked-and-hidden variables for both group and project scopes.
1 parent d72b378 commit 849301b

3 files changed

Lines changed: 87 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ docs/_build
1313
.tox
1414
.venv/
1515
venv/
16+
.mypy_cache/
1617

1718
# Include tracked hidden files and directories in search and diff tools
1819
!.dockerignore

gitlab/v4/objects/variables.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ class VariableManager(CRUDMixin[Variable]):
2727
_path = "/admin/ci/variables"
2828
_obj_cls = Variable
2929
_create_attrs = RequiredOptional(
30-
required=("key", "value"), optional=("protected", "variable_type", "masked")
30+
required=("key", "value"),
31+
optional=("description", "masked", "protected", "raw", "variable_type"),
3132
)
3233
_update_attrs = RequiredOptional(
33-
required=("key", "value"), optional=("protected", "variable_type", "masked")
34+
required=("key",),
35+
optional=(
36+
"description",
37+
"masked",
38+
"protected",
39+
"raw",
40+
"value",
41+
"variable_type",
42+
),
3443
)
3544

3645

@@ -43,10 +52,28 @@ class GroupVariableManager(CRUDMixin[GroupVariable]):
4352
_obj_cls = GroupVariable
4453
_from_parent_attrs = {"group_id": "id"}
4554
_create_attrs = RequiredOptional(
46-
required=("key", "value"), optional=("protected", "variable_type", "masked")
55+
required=("key", "value"),
56+
optional=(
57+
"description",
58+
"environment_scope",
59+
"masked",
60+
"masked_and_hidden",
61+
"protected",
62+
"raw",
63+
"variable_type",
64+
),
4765
)
4866
_update_attrs = RequiredOptional(
49-
required=("key", "value"), optional=("protected", "variable_type", "masked")
67+
required=("key",),
68+
optional=(
69+
"description",
70+
"environment_scope",
71+
"masked",
72+
"protected",
73+
"raw",
74+
"value",
75+
"variable_type",
76+
),
5077
)
5178

5279

@@ -60,9 +87,25 @@ class ProjectVariableManager(CRUDMixin[ProjectVariable]):
6087
_from_parent_attrs = {"project_id": "id"}
6188
_create_attrs = RequiredOptional(
6289
required=("key", "value"),
63-
optional=("protected", "variable_type", "masked", "environment_scope"),
90+
optional=(
91+
"description",
92+
"environment_scope",
93+
"masked",
94+
"masked_and_hidden",
95+
"protected",
96+
"raw",
97+
"variable_type",
98+
),
6499
)
65100
_update_attrs = RequiredOptional(
66-
required=("key", "value"),
67-
optional=("protected", "variable_type", "masked", "environment_scope"),
101+
required=("key",),
102+
optional=(
103+
"description",
104+
"environment_scope",
105+
"masked",
106+
"protected",
107+
"raw",
108+
"value",
109+
"variable_type",
110+
),
68111
)

tests/functional/api/test_variables.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,39 @@ def test_project_variables(project):
4343
assert variable.value == "new_value1"
4444

4545
variable.delete()
46+
47+
48+
def test_hidden_group_variables(group):
49+
variable = group.variables.create(
50+
{"key": "key1", "value": "secret_value", "masked_and_hidden": True}
51+
)
52+
53+
variable = group.variables.get(variable.key)
54+
assert variable.value is None
55+
assert variable.description is None
56+
assert variable in group.variables.list()
57+
58+
variable.description = "new_description"
59+
variable.save()
60+
variable = group.variables.get(variable.key)
61+
assert variable.description == "new_description"
62+
63+
variable.delete()
64+
65+
66+
def test_hidden_project_variables(project):
67+
variable = project.variables.create(
68+
{"key": "key1", "value": "secret_value", "masked_and_hidden": True}
69+
)
70+
71+
variable = project.variables.get(variable.key)
72+
assert variable.value is None
73+
assert variable.description is None
74+
assert variable in project.variables.list()
75+
76+
variable.description = "new_description"
77+
variable.save()
78+
variable = project.variables.get(variable.key)
79+
assert variable.description == "new_description"
80+
81+
variable.delete()

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python-gitlab/python-gitlab/commit/849301b830b0d4f76ab85ffa3f39b22a6e628df9

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy