You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@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.
Do we technically need the distinction between the 3 types of token?
There is now also a project access token. Which one of the 3 tokens needs to be set in that case?
For simplicity, I'd prefer to have it like @rrauenza originally requested: A single --token option for everything, which overrides any value in configurations files. We probably also should cover --username and --password (with an optional value to allow interactive input), which as a side effect will make the container entry point unnecessary, e.g.
I'll try to find out if we can read from the environment from within the argparse setup code via the defaults. To my knowledge, there is not direct way to make argparse consider environment variables (unlike click).
Yeah, click would make a lot more sense for this, which is why this has kind of stalled.
To make it a global option you would probably want to add them to the base parser here:
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.
There is now also a project access token. Which one of the 3 tokens needs to be set in that case?
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:
@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 --token could possibly be a convenience option with no guarantees..
Activity
max-wittig commentedon Dec 9, 2019
Good idea.
chrisoldwood commentedon Jan 30, 2020
Is this a duplicate of #893?
nejch commentedon Feb 25, 2020
@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.
rrauenza commentedon Jul 9, 2020
Yeah, that sounds reasonable.
bittner commentedon Dec 17, 2020
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
--tokenoption for everything, which overrides any value in configurations files. We probably also should cover--usernameand--password(with an optional value to allow interactive input), which as a side effect will make the container entry point unnecessary, e.g.I'll try to find out if we can read from the environment from within the
argparsesetup code via the defaults. To my knowledge, there is not direct way to make argparse consider environment variables (unlike click).nejch commentedon Dec 17, 2020
Yeah, click would make a lot more sense for this, which is why this has kind of stalled.
To make it a global option you would probably want to add them to the base parser here:
python-gitlab/gitlab/cli.py
Lines 81 to 130 in 265dbbd
Then if those arguments are provided and valid you would need to override
from_config()in CLI and instantiate Gitlab with the args instead:python-gitlab/gitlab/cli.py
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:
or if you're not in docker:
nejch commentedon Dec 25, 2020
@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
--tokencould possibly be a convenience option with no guarantees..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)