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

fix: make scopes work with multiple scope-names#1360

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

Closed
Closed
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
9 changes: 9 additions & 0 deletionsgitlab/types.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,15 @@ def get_for_api(self):
return ",".join(self._value)


class ScopesListAttribute(ListAttribute):
def get_for_api(self):
# scopes are expected to be a list of strings
if isinstance(self._value, str):
return [self._value]

return self._value


class LowercaseStringAttribute(GitlabAttribute):
def get_for_api(self):
return str(self._value).lower()
Expand Down
3 changes: 3 additions & 0 deletionsgitlab/v4/objects/applications.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin
from gitlab.types import ScopesListAttribute

__all__ = [
"Application",
Expand All@@ -16,3 +17,5 @@ class ApplicationManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/applications"
_obj_cls = Application
_create_attrs = (("name", "redirect_uri", "scopes"), ("confidential",))

_types = {"scopes": ScopesListAttribute}
4 changes: 3 additions & 1 deletiongitlab/v4/objects/deploy_tokens.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
from gitlab.base import RESTManager, RESTObject
from gitlab.mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin

from gitlab.types import ScopesListAttribute

__all__ = [
"DeployToken",
Expand DownExpand Up@@ -39,6 +39,7 @@ class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
"username",
),
)
_types = {"scopes": ScopesListAttribute}


class ProjectDeployToken(ObjectDeleteMixin, RESTObject):
Expand All@@ -59,3 +60,4 @@ class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager
"username",
),
)
_types = {"scopes": ScopesListAttribute}
2 changes: 2 additions & 0 deletionsgitlab/v4/objects/users.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
SaveMixin,
UpdateMixin,
)
from gitlab.types import ScopesListAttribute

from .custom_attributes import UserCustomAttributeManager
from .events import UserEventManager
Expand DownExpand Up@@ -406,6 +407,7 @@ class UserImpersonationTokenManager(NoUpdateMixin, RESTManager):
_from_parent_attrs = {"user_id": "id"}
_create_attrs = (("name", "scopes"), ("expires_at",))
_list_filters = ("state",)
_types = {"scopes": ScopesListAttribute}


class UserMembership(RESTObject):
Expand Down
17 changes: 14 additions & 3 deletionstools/functional/cli/test_cli_v4.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -561,11 +561,10 @@ def test_create_project_with_values_from_file(gitlab_cli, tmpdir):
assert description in ret.stdout


deftest_create_project_deploy_token(gitlab_cli, project):
defdo_test_create_project_deploy_token(gitlab_cli, project, scopes, expected_scopes):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

hint: you could keep a single test function here and parametrize the input/expected output with pytest:

@pytest.mark.parametrize("scopes,expected_scopes",    [        ("read_registry","['read_registry']"),        ("read_registry,read_repository","['read_repository', 'read_registry']"),    ],)deftest_create_project_deploy_token(gitlab_cli,project,scopes,expected_scopes):    ...

Then you don't need a custom helper function at all and it will be easy to add more edge cases later. See very similar example here:

@pytest.mark.parametrize(
"config_string,expected_agent",
[
(valid_config,USER_AGENT),
(custom_user_agent_config,custom_user_agent),
],
)
deftest_config_user_agent(m_open,path_exists,config_string,expected_agent):
fd=io.StringIO(config_string)
fd.close=mock.Mock(return_value=None)
m_open.return_value=fd
cp=config.GitlabConfigParser()
assertcp.user_agent==expected_agent

name = "project-token"
username = "root"
expires_at = "2021-09-09"
scopes = "read_registry"

cmd = [
"-v",
Expand All@@ -588,7 +587,19 @@ def test_create_project_deploy_token(gitlab_cli, project):
assert name in ret.stdout
assert username in ret.stdout
assert expires_at in ret.stdout
assert scopes in ret.stdout
assert expected_scopes in ret.stdout


def test_create_project_deploy_token_one_scope(gitlab_cli, project):
scopes = "read_registry"
expected_scopes = "['read_registry']"
do_test_create_project_deploy_token(gitlab_cli, project, scopes, expected_scopes)


def test_create_project_deploy_token_many_scopes(gitlab_cli, project):
scopes = "read_registry,read_repository"
expected_scopes = "['read_repository', 'read_registry']"
do_test_create_project_deploy_token(gitlab_cli, project, scopes, expected_scopes)


def test_list_all_deploy_tokens(gitlab_cli, deploy_token):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp