Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from

Conversation

klorenz
Copy link
Contributor

@klorenz klorenz commented Mar 6, 2021

I have found out, that it was not possible to use multiple comma-separated scopes from command line as documented. These changes fixes that issue.

@klorenz klorenz force-pushed the fix_impersonation_token branch from 2ee4155 to 426b9b5 Compare March 6, 2021 10:52
@JohnVillalovos
Copy link
Member

JohnVillalovos commented Mar 6, 2021

When I look at "Files changed" only one file is changed. Was that the intent? The second commit is a Merge commit which doesn't seem correct.

It seems like this patch was started before gitlab/v4/objects/init.py was split up into multiple files.

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this @klorenz I think some people have asked for this already and will be happy to see it fixed! I'll try to find related issues so we can close them if it fixes them.

When I look at "Files changed" only one file is changed. Was that the intent? The second commit is a Merge commit which doesn't seem correct.

It seems like this patch was started before gitlab/v4/objects/init.py was split up into multiple files.

I agree with @JohnVillalovos, looks like with your merge you lost the custom _types attributes. Could you re-add them in the split objects/ files? Also looks like you had an unrelated change in the initial commit, please submit that as a separate PR if you add it back ;)

Apart from John's comment see also my note on only overriding the right method.

And finally since I see from the other PR that you're comfortable with unit tests here could you add one to prove it fixes the issue? ;)

@klorenz
Copy link
Contributor Author

klorenz commented Mar 7, 2021 via email

@codecov-io
Copy link

codecov-io commented Mar 7, 2021

Codecov Report

Merging #1360 (7443cd8) into master (aa13214) will decrease coverage by 0.18%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1360      +/-   ##
==========================================
- Coverage   80.21%   80.03%   -0.19%     
==========================================
  Files          73       73              
  Lines        3801     4022     +221     
==========================================
+ Hits         3049     3219     +170     
- Misses        752      803      +51     
Flag Coverage Δ
unit 80.03% <91.66%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/types.py 90.62% <80.00%> (-1.97%) ⬇️
gitlab/v4/objects/applications.py 100.00% <100.00%> (ø)
gitlab/v4/objects/deploy_tokens.py 100.00% <100.00%> (ø)
gitlab/v4/objects/users.py 90.69% <100.00%> (+0.10%) ⬆️
gitlab/client.py 79.12% <0.00%> (-1.56%) ⬇️
gitlab/mixins.py 78.60% <0.00%> (-0.26%) ⬇️
gitlab/base.py 84.66% <0.00%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa13214...7443cd8. Read the comment docs.

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

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

Thanks for the added tests, looks good! I just left one small note.

@@ -561,11 +561,10 @@ def test_create_project_with_values_from_file(gitlab_cli, tmpdir):
assert description in ret.stdout


def test_create_project_deploy_token(gitlab_cli, project):
def do_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']"),
    ],
)
def test_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),
],
)
def test_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()
assert cp.user_agent == expected_agent

@nejch
Copy link
Member

nejch commented May 15, 2021

Hi @klorenz, coming back to this, I realized we've solved the same/similar problem in a more generic way in #1420 for all objects that need special list filters.

I just ran your functional tests on the current master branch and they're passing, so I just wanted to check what your original issue was so that we can see if this is still needed for any objects. Could you let me know what CLI commands you were trying before that did not work properly?

It seems like creating deploy tokens with scopes as a comma-delimited string (--scopes "read_registry,read_repository" works well with the current master branch.

@JohnVillalovos
Copy link
Member

Related PR which also fixes other issues we have with array variables passed to the GitLab API

#1699

@github-actions
Copy link

This Pull Request (PR) was marked stale because it has been open 90 days with no activity. Please remove the stale label or comment on this PR. Otherwise, it will be closed in 15 days.

@github-actions github-actions bot added the stale label Feb 19, 2022
@github-actions
Copy link

github-actions bot commented Mar 6, 2022

This PR was closed because it has been marked stale for 15 days with no activity. If this PR is still valid, please re-open.

@github-actions github-actions bot closed this Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants