Skip to content

Commit 22be96c

Browse files
nejchJohnVillalovos
authored andcommitted
feat(api): add support for adding instance deploy keys
1 parent 193c5de commit 22be96c

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

docs/gl_objects/deploy_keys.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Reference
1919
Examples
2020
--------
2121

22-
List the deploy keys::
22+
Add an instance-wide deploy key (requires admin access)::
23+
24+
keys = gl.deploykeys.create({'title': 'instance key', 'key': INSTANCE_KEY})
25+
26+
List all deploy keys::
2327

2428
keys = gl.deploykeys.list()
2529

gitlab/v4/objects/deploy_keys.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
from gitlab import cli
88
from gitlab import exceptions as exc
99
from gitlab.base import RESTObject
10-
from gitlab.mixins import CRUDMixin, ListMixin, ObjectDeleteMixin, SaveMixin
10+
from gitlab.mixins import (
11+
CreateMixin,
12+
CRUDMixin,
13+
ListMixin,
14+
ObjectDeleteMixin,
15+
SaveMixin,
16+
)
1117
from gitlab.types import RequiredOptional
1218

1319
__all__ = ["DeployKey", "DeployKeyManager", "ProjectKey", "ProjectKeyManager"]
@@ -17,9 +23,12 @@ class DeployKey(RESTObject):
1723
pass
1824

1925

20-
class DeployKeyManager(ListMixin[DeployKey]):
26+
class DeployKeyManager(CreateMixin[DeployKey], ListMixin[DeployKey]):
2127
_path = "/deploy_keys"
2228
_obj_cls = DeployKey
29+
_create_attrs = RequiredOptional(
30+
required=("title", "key"), optional=("expires_at",)
31+
)
2332

2433

2534
class ProjectKey(SaveMixin, ObjectDeleteMixin, RESTObject):
@@ -30,8 +39,10 @@ class ProjectKeyManager(CRUDMixin[ProjectKey]):
3039
_path = "/projects/{project_id}/deploy_keys"
3140
_obj_cls = ProjectKey
3241
_from_parent_attrs = {"project_id": "id"}
33-
_create_attrs = RequiredOptional(required=("title", "key"), optional=("can_push",))
34-
_update_attrs = RequiredOptional(optional=("title", "can_push"))
42+
_create_attrs = RequiredOptional(
43+
required=("title", "key"), optional=("can_push", "expires_at")
44+
)
45+
_update_attrs = RequiredOptional(optional=("title", "can_push", "expires_at"))
3546

3647
@cli.register_custom_action(
3748
cls_names="ProjectKeyManager",

tests/functional/api/test_deploy_keys.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
def test_project_deploy_keys(gl, project, DEPLOY_KEY):
1+
from gitlab import Gitlab
2+
from gitlab.v4.objects import Project
3+
4+
5+
def test_deploy_keys(gl: Gitlab, DEPLOY_KEY: str) -> None:
6+
deploy_key = gl.deploykeys.create({"title": "foo@bar", "key": DEPLOY_KEY})
7+
assert deploy_key in gl.deploykeys.list(get_all=False)
8+
9+
10+
def test_project_deploy_keys(gl: Gitlab, project: Project, DEPLOY_KEY: str) -> None:
211
deploy_key = project.keys.create({"title": "foo@bar", "key": DEPLOY_KEY})
312
assert deploy_key in project.keys.list()
413

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy