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(cli): allow options from CLI args or environment variables#1296

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
JohnVillalovos merged 1 commit intomainfromfeat/merge-cli-env-file-config
Jan 2, 2022

Conversation

nejch
Copy link
Member

@nejchnejch commentedFeb 14, 2021
edited
Loading

Closes#960
Closes#893

Makes it easier to later introduce#715 hopefully, and maybe#1195.

BREAKING-CHANGE: The gitlab CLI will now accept CLI arguments
and environment variables for its global options in addition
to configuration file options. This may change behavior for
some workflows such as running inside GitLab CI and with
certain environment variables configured.

@codecov-io
Copy link

Codecov Report

Merging#1296 (cab343c) intomaster (9d6c188) willnot change coverage.
The diff coverage isn/a.

Impacted file tree graph

@@           Coverage Diff           @@##           master    #1296   +/-   ##=======================================  Coverage   78.26%   78.26%           =======================================  Files          12       12             Lines        2894     2894           =======================================  Hits         2265     2265             Misses        629      629
FlagCoverage Δ
unit78.26% <ø> (ø)

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


Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update9d6c188...cab343c. Read thecomment docs.

@nejchnejch mentioned this pull requestApr 25, 2021
@nejchnejch added this to thev3.0.0 milestoneApr 27, 2021
@nejchnejch mentioned this pull requestJun 14, 2021
15 tasks
@phillid
Copy link

phillid commentedJul 4, 2021
edited
Loading

We found this PR after we tried including gitlab-cli in a GitLab CI/CD pipeline job. This PR looks like it will achieve what we wanted to do (drive the GitLab API without creating a config file in each job) 🎉

One outstanding wishlist item we had was if the tool could look for the same environment variables that are set inside a GitLab CI/CD job, i.e. CI_JOB_TOKEN, CI_SERVER_URL and so on1. If the tool shared these varaibles, it could authenticate with the GitLab instance without any extra code written in CI/CD jobs - is that something that has already been considered?

@nejch
Copy link
MemberAuthor

We found this PR after we tried including gitlab-cli in a GitLab CI/CD pipeline job. This PR looks like it will achieve what we wanted to do (drive the GitLab API without creating a config file in each job) 🎉

One outstanding wishlist item we had was if the tool could look for the same environment variables that are set inside a GitLab CI/CD job, i.e. CI_JOB_TOKEN, CI_SERVER_URL and so on1. If the tool shared these varaibles, it could authenticate with the GitLab instance without any extra code written in CI/CD jobs - is that something that has already been considered?

Yes, part of this was meant to implement zero-config for CI jobs. But I need to maybe tweak and add tests to really check all scenarios (for some endpoints, a PAT is needed, so we should allow overriding in a sensible precedence between cli args/env/config files/CI env). Currently the precedence planned is:

1. Explicitly provided CLI arguments,
2. Environment variables,
3. Configuration files:
a. explicitly defined config files:
i. via the `--config-file` CLI argument,
ii. via the `PYTHON_GITLAB_CFG` environment variable,
b. user-specific config file,
c. system-level config file,
4. Environment variables always present in CI (CI_SERVER_URL, CI_JOB_TOKEN).

I'll try to get back to this PR in the coming days :)

@phillid
Copy link

Yes, part of this was meant to implement zero-config for CI jobs. But I need to maybe tweak and add tests to really check all scenarios (for some endpoints, a PAT is needed, so we should allow overriding in a sensible precedence between cli args/env/config files/CI env). Currently the precedence planned is:

1. Explicitly provided CLI arguments,
2. Environment variables,
3. Configuration files:
a. explicitly defined config files:
i. via the `--config-file` CLI argument,
ii. via the `PYTHON_GITLAB_CFG` environment variable,
b. user-specific config file,
c. system-level config file,
4. Environment variables always present in CI (CI_SERVER_URL, CI_JOB_TOKEN).

Aha. I'm blind 👀

That does indeed look like exactly the behaviour we wanted.

@codecov-commenter
Copy link

codecov-commenter commentedSep 12, 2021
edited
Loading

Codecov Report

Merging#1296 (13467c5) intomaster (ce4bc0d) willincrease coverage by0.03%.
The diff coverage is100.00%.

@@            Coverage Diff             @@##           master    #1296      +/-   ##==========================================+ Coverage   91.57%   91.61%   +0.03%==========================================  Files          74       74                Lines        4263     4281      +18     ==========================================+ Hits         3904     3922      +18  Misses        359      359
FlagCoverage Δ
cli_func_v481.63% <100.00%> (+0.07%)⬆️
py_func_v480.35% <26.31%> (-0.23%)⬇️
unit83.36% <84.21%> (+0.02%)⬆️

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

Impacted FilesCoverage Δ
gitlab/cli.py87.50% <100.00%> (+1.29%)⬆️
gitlab/client.py89.04% <100.00%> (+0.18%)⬆️

@nejchnejchforce-pushed thefeat/merge-cli-env-file-config branch from13467c5 toa998970CompareDecember 7, 2021 23:28
@JohnVillalovos
Copy link
Member

What do you think about usingargparse.ArgumentParser..add_mutually_exclusive_group() ?

For example:

private_token_group = parser.add_mutually_exclusive_group()private_token_group.add_argument(        "--private-token",        help=("GitLab private token"),        required=False,    )private_token_group.add_argument(        "--private-token-env-var",        help=("Name of environment variable containing GitLab private token"),        required=False,    )

But now that I look at the code I'm not sure where to do the processing to load the environment variable 😟

I'll just leave this comment anyway and maybe it gives you an idea 🤷‍♂️

@nejch
Copy link
MemberAuthor

nejch commentedDec 10, 2021
edited
Loading

.add_mutually_exclusive_group()

Thanks! Yes, I think it might be useful (not for arg/var exclusive I think but maybe for different types of tokens). But yes sometimes we want to validate those a bit later, because things like CI_JOB_TOKEN might always be present 🤦

I think we just need to write a bunch of tests for expected behaviors in all the possible combinations, and write the code based on that.

@nejchnejchforce-pushed thefeat/merge-cli-env-file-config branch 2 times, most recently froma6390bf toc60ae1fCompareDecember 14, 2021 00:45
@nejchnejchforce-pushed thefeat/merge-cli-env-file-config branch 5 times, most recently from14487b3 toc6de2f5CompareJanuary 2, 2022 17:09
@nejchnejch marked this pull request as ready for reviewJanuary 2, 2022 17:19
@nejch
Copy link
MemberAuthor

@JohnVillalovos took almost a year to get back to this, but ready for another look 😅

@nejchnejchforce-pushed thefeat/merge-cli-env-file-config branch fromc6de2f5 tofe964ddCompareJanuary 2, 2022 17:55
Copy link
Member

@JohnVillalovosJohnVillalovos left a comment

Choose a reason for hiding this comment

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

A few nits. But overall looks good to me. Thanks!

BREAKING-CHANGE: The gitlab CLI will now accept CLI argumentsand environment variables for its global options in additionto configuration file options. This may change behavior forsome workflows such as running inside GitLab CI and withcertain environment variables configured.
Copy link
Member

@JohnVillalovosJohnVillalovos left a comment

Choose a reason for hiding this comment

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

Thanks@nejch . Looks good.

@JohnVillalovosJohnVillalovos merged commitca58008 intomainJan 2, 2022
@JohnVillalovosJohnVillalovos deleted the feat/merge-cli-env-file-config branchJanuary 2, 2022 22:35
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@phillidphillidphillid left review comments

@JohnVillalovosJohnVillalovosJohnVillalovos approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.0.0
Development

Successfully merging this pull request may close these issues.

cli command line arguments for url and token CLI usage without configuration file
5 participants
@nejch@codecov-io@phillid@codecov-commenter@JohnVillalovos

[8]ページ先頭

©2009-2025 Movatter.jp