Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(objects): support getting project/group deploy tokens by id#1963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
max-wittig merged 1 commit intomainfromfeat/deploy-token-get
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsdocs/gl_objects/deploy_tokens.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,10 @@ List the deploy tokens for a project::

deploy_tokens = project.deploytokens.list()

Get a deploy token for a project by id::

deploy_token = project.deploytokens.get(deploy_token_id)

Create a new deploy token to access registry images of a project:

In addition to required parameters ``name`` and ``scopes``, this method accepts
Expand DownExpand Up@@ -107,6 +111,10 @@ List the deploy tokens for a group::

deploy_tokens = group.deploytokens.list()

Get a deploy token for a group by id::

deploy_token = group.deploytokens.get(deploy_token_id)

Create a new deploy token to access all repositories of all projects in a group:

In addition to required parameters ``name`` and ``scopes``, this method accepts
Expand Down
24 changes: 21 additions & 3 deletionsgitlab/v4/objects/deploy_tokens.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
from typing import Any, cast, Union

from gitlab import types
from gitlab.base import RequiredOptional, RESTManager, RESTObject
from gitlab.mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin
from gitlab.mixins import (
CreateMixin,
DeleteMixin,
ListMixin,
ObjectDeleteMixin,
RetrieveMixin,
)

__all__ = [
"DeployToken",
Expand All@@ -25,7 +33,7 @@ class GroupDeployToken(ObjectDeleteMixin, RESTObject):
pass


class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
class GroupDeployTokenManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/groups/{group_id}/deploy_tokens"
_from_parent_attrs = {"group_id": "id"}
_obj_cls = GroupDeployToken
Expand All@@ -41,12 +49,17 @@ class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
)
_types = {"scopes": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> GroupDeployToken:
return cast(GroupDeployToken, super().get(id=id, lazy=lazy, **kwargs))


class ProjectDeployToken(ObjectDeleteMixin, RESTObject):
pass


class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
class ProjectDeployTokenManager(RetrieveMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/projects/{project_id}/deploy_tokens"
_from_parent_attrs = {"project_id": "id"}
_obj_cls = ProjectDeployToken
Expand All@@ -61,3 +74,8 @@ class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager
),
)
_types = {"scopes": types.CommaSeparatedListAttribute}

def get(
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
) -> ProjectDeployToken:
return cast(ProjectDeployToken, super().get(id=id, lazy=lazy, **kwargs))
13 changes: 9 additions & 4 deletionstests/functional/api/test_deploy_tokens.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,10 +10,11 @@ def test_project_deploy_tokens(gl, project):
assert len(project.deploytokens.list()) == 1
assert gl.deploytokens.list() == project.deploytokens.list()

assert project.deploytokens.list()[0].name == "foo"
assert project.deploytokens.list()[0].expires_at == "2022-01-01T00:00:00.000Z"
assert project.deploytokens.list()[0].scopes == ["read_registry"]
assert project.deploytokens.list()[0].username == "bar"
deploy_token = project.deploytokens.get(deploy_token.id)
assert deploy_token.name == "foo"
assert deploy_token.expires_at == "2022-01-01T00:00:00.000Z"
assert deploy_token.scopes == ["read_registry"]
assert deploy_token.username == "bar"

deploy_token.delete()
assert len(project.deploytokens.list()) == 0
Expand All@@ -31,6 +32,10 @@ def test_group_deploy_tokens(gl, group):
assert len(group.deploytokens.list()) == 1
assert gl.deploytokens.list() == group.deploytokens.list()

deploy_token = group.deploytokens.get(deploy_token.id)
assert deploy_token.name == "foo"
assert deploy_token.scopes == ["read_registry"]

deploy_token.delete()
assert len(group.deploytokens.list()) == 0
assert len(gl.deploytokens.list()) == 0

[8]ページ先頭

©2009-2025 Movatter.jp