diff options
author | Jeremy Cline <jcline@redhat.com> | 2020-04-14 15:27:51 -0400 |
---|---|---|
committer | Jeremy Cline <jcline@redhat.com> | 2020-04-16 19:01:32 -0400 |
commit | 401e702a9ff14bf4cc33b3ed3acf16f3c60c6945 (patch) | |
tree | da3e74f200b74f3fea6168c6597852391e7a00ca /gitlab/config.py | |
parent | c7c431af16f256f95a9553cf2e14925fa75f7d62 (diff) | |
download | gitlab-401e702a9ff14bf4cc33b3ed3acf16f3c60c6945.tar.gz |
feat: allow an environment variable to specify config location
It can be useful (especially in scripts) to specify a configuration
location via an environment variable. If the "PYTHON_GITLAB_CFG"
environment variable is defined, treat its value as the path to a
configuration file and include it in the set of default configuration
locations.
Diffstat (limited to 'gitlab/config.py')
-rw-r--r-- | gitlab/config.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gitlab/config.py b/gitlab/config.py index 1b665ed..fa2593b 100644 --- a/gitlab/config.py +++ b/gitlab/config.py @@ -18,7 +18,17 @@ import os import configparser -_DEFAULT_FILES = ["/etc/python-gitlab.cfg", os.path.expanduser("~/.python-gitlab.cfg")] + +def _env_config(): + if "PYTHON_GITLAB_CFG" in os.environ: + return [os.environ["PYTHON_GITLAB_CFG"]] + return [] + + +_DEFAULT_FILES = _env_config() + [ + "/etc/python-gitlab.cfg", + os.path.expanduser("~/.python-gitlab.cfg"), +] class ConfigError(Exception): |