-
Notifications
You must be signed in to change notification settings - Fork 671
cli command line arguments for url and token #960
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
Comments
Good idea. |
Is this a duplicate of #893? |
@rrauenza if you'd be OK with env variables only, this can maybe be closed as a duplicate as Chris suggests and I can try and work on #893. Environment variables just make sense as CLI arguments would end up passing environment variables when used in CI systems anyway (which is probably what a lot of people do with this library, like your example). There are many issues open for CLI so maybe args can be a topic for when that gets reworked. |
Yeah, that sounds reasonable. |
I would need this feature now. Where would we implement the API token? As in: curl --silent --header "Authorization: Bearer $GITLAB_API_TOKEN" ... Aside, for clarification:
For simplicity, I'd prefer to have it like @rrauenza originally requested: A single gitlab --url https://$CI_SERVER_HOST --token $GITLAB_API_TOKEN ...
gitlab --username $CI_DEPLOY_USER --password ... I'll try to find out if we can read from the environment from within the |
Yeah, click would make a lot more sense for this, which is why this has kind of stalled. Lines 81 to 130 in 265dbbd
Then if those arguments are provided and valid you would need to override Line 223 in 265dbbd
Feel free to give it a shot :)
Different types of tokens send different headers to the API, so you need to distinguish this, see python-gitlab/gitlab/__init__.py Lines 357 to 375 in be0afdd
You can get away with combining oauth and PAT like as you suggested with the bearer header instead, but I don't think it'd work for job tokens, at least according to docs. But maybe it's just not documented, should be tested.
This and the upcoming group access tokens are basically just personal access tokens for project/group bot users. In the meantime, if you use this in CI, this workaround has worked well for me: before_script:
- pip install --quiet python-gitlab
- 'echo -e "[global]\ndefault=gitlab\n[gitlab]\nurl=$CI_SERVER_URL\nprivate_token=$API_TOKEN" > ~/.python-gitlab.cfg'
script:
- 'gitlab <args...> or if you're not in docker: before_script:
- pip install --quiet python-gitlab
- 'echo -e "[global]\ndefault=gitlab\n[gitlab]\nurl=$CI_SERVER_URL\nprivate_token=$API_TOKEN" > gitlab.cfg'
script:
- 'gitlab --config-file gitlab.cfg <args...> |
@bittner it does seem like there's some undocumented support for the bearer header with CI job tokens, but I wouldn't rely on it being a stable API, see below. But at least downloading job artifacts with a job token + bearer auth worked. So For more context on the matrix of different auth headers and allowed credentials they come with, you can scroll through this gitlab epic: https://gitlab.com/groups/gitlab-org/-/epics/3807 (specifically this note https://gitlab.com/groups/gitlab-org/-/epics/3807#note_374553902) |
(enhancement request)
What do you think of adding command line arguments to pass the url and token on the command line? This would make integration with gitlab ci easier,
gitlab --url https://$CI_SERVER_HOST --token $CI_JOB_TOKEN ...
Either that, or an option to read them from the environment (or default them from the environment?)
The text was updated successfully, but these errors were encountered: