diff options
author | Kay-Uwe (Kiwi) Lorenz <kiwi@moduleworks.com> | 2021-03-07 15:13:52 +0100 |
---|---|---|
committer | Kay-Uwe (Kiwi) Lorenz <kiwi@moduleworks.com> | 2021-03-07 15:13:52 +0100 |
commit | fc2798fc31a08997c049f609c19dd4ab8d75964e (patch) | |
tree | deeed2598ac9472810aad461a7bd9c50e5ad8fc1 /gitlab/config.py | |
parent | b04dd2c08b69619bb58832f40a4c4391e350a735 (diff) | |
download | gitlab-fc2798fc31a08997c049f609c19dd4ab8d75964e.tar.gz |
fix: make secret helper more user friendly
Diffstat (limited to 'gitlab/config.py')
-rw-r--r-- | gitlab/config.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/gitlab/config.py b/gitlab/config.py index a6f25ac..67f5082 100644 --- a/gitlab/config.py +++ b/gitlab/config.py @@ -34,6 +34,11 @@ _DEFAULT_FILES: List[str] = _env_config() + [ os.path.expanduser("~/.python-gitlab.cfg"), ] +HELPER_PREFIX = "helper:" + +HELPER_ATTRIBUTES = [ + "job_token", "http_password", "private_token", "oauth_token" +] class ConfigError(Exception): pass @@ -151,15 +156,7 @@ class GitlabConfigParser(object): except Exception: pass - for attr in ("job_token", "http_password", "private_token", "oauth_token"): - value = getattr(self, attr) - prefix = "lookup:" - if isinstance(value, str) and value.lower().strip().startswith(prefix): - helper = value[len(prefix) :].strip() - value = ( - subprocess.check_output(helper, shell=True).decode("utf-8").strip() - ) - setattr(self, attr, value) + self._get_values_from_helper() self.api_version = "4" try: @@ -203,3 +200,13 @@ class GitlabConfigParser(object): self.user_agent = self._config.get(self.gitlab_id, "user_agent") except Exception: pass + + def _get_values_from_helper(self): + """Update attributes, which may get values from an external helper program + """ + for attr in HELPER_ATTRIBUTES: + value = getattr(self, attr) + if isinstance(value, str) and value.lower().strip().startswith(HELPER_PREFIX): + helper = value[len(HELPER_PREFIX) :].strip() + value = subprocess.check_output([helper]).decode("utf-8").strip() + setattr(self, attr, value)
\ No newline at end of file |