Skip to content

Commit

Permalink
feat: option to add a helper to lookup token
Browse files Browse the repository at this point in the history
  • Loading branch information
klorenz committed Mar 6, 2021
1 parent aa13214 commit 8ecf559
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/cli-usage.rst
Expand Up @@ -48,7 +48,7 @@ example:
[elsewhere]
url = http://else.whe.re:8080
private_token = CkqsjqcQSFH5FQKDccu4
private_token = lookup: pass show path/to/password
timeout = 1
The ``default`` option of the ``[global]`` section defines the GitLab server to
Expand Down
11 changes: 11 additions & 0 deletions gitlab/config.py
Expand Up @@ -17,6 +17,7 @@

import os
import configparser
import subprocess
from typing import List, Optional, Union

from gitlab.const import USER_AGENT
Expand Down Expand Up @@ -150,6 +151,16 @@ def __init__(
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.api_version = "4"
try:
self.api_version = self._config.get("global", "api_version")
Expand Down

0 comments on commit 8ecf559

Please sign in to comment.