| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 193c5de commit 22be96c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,11 @@ Reference | |||
| 19 | 19 | Examples | |
| 20 | 20 | -------- | |
| 21 | 21 | ||
| 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:: | ||
| 23 | 27 | ||
| 24 | 28 | keys = gl.deploykeys.list() | |
| 25 | 29 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,13 @@ | |||
| 7 | 7 | from gitlab import cli | |
| 8 | 8 | from gitlab import exceptions as exc | |
| 9 | 9 | 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 | + ) | ||
| 11 | 17 | from gitlab.types import RequiredOptional | |
| 12 | 18 | ||
| 13 | 19 | __all__ = ["DeployKey", "DeployKeyManager", "ProjectKey", "ProjectKeyManager"] | |
@@ -17,9 +23,12 @@ class DeployKey(RESTObject): | |||
| 17 | 23 | pass | |
| 18 | 24 | ||
| 19 | 25 | ||
| 20 | - class DeployKeyManager(ListMixin[DeployKey]): | ||
| 26 | + class DeployKeyManager(CreateMixin[DeployKey], ListMixin[DeployKey]): | ||
| 21 | 27 | _path = "/deploy_keys" | |
| 22 | 28 | _obj_cls = DeployKey | |
| 29 | + _create_attrs = RequiredOptional( | ||
| 30 | + required=("title", "key"), optional=("expires_at",) | ||
| 31 | + ) | ||
| 23 | 32 | ||
| 24 | 33 | ||
| 25 | 34 | class ProjectKey(SaveMixin, ObjectDeleteMixin, RESTObject): | |
@@ -30,8 +39,10 @@ class ProjectKeyManager(CRUDMixin[ProjectKey]): | |||
| 30 | 39 | _path = "/projects/{project_id}/deploy_keys" | |
| 31 | 40 | _obj_cls = ProjectKey | |
| 32 | 41 | _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")) | ||
| 35 | 46 | ||
| 36 | 47 | @cli.register_custom_action( | |
| 37 | 48 | cls_names="ProjectKeyManager", | |
| Original file line number | Diff line number | Diff 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: | ||
| 2 | 11 | deploy_key = project.keys.create({"title": "foo@bar", "key": DEPLOY_KEY}) | |
| 3 | 12 | assert deploy_key in project.keys.list() | |
| 4 | 13 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments