summaryrefslogtreecommitdiff
path: root/gitlab/config.py
diff options
context:
space:
mode:
authorJeremy Cline <jcline@redhat.com>2020-04-14 15:27:51 -0400
committerJeremy Cline <jcline@redhat.com>2020-04-16 19:01:32 -0400
commit401e702a9ff14bf4cc33b3ed3acf16f3c60c6945 (patch)
treeda3e74f200b74f3fea6168c6597852391e7a00ca /gitlab/config.py
parentc7c431af16f256f95a9553cf2e14925fa75f7d62 (diff)
downloadgitlab-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.py12
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):