Skip to content

Commit 8ecf559

Browse files
committed
feat: option to add a helper to lookup token
1 parent aa13214 commit 8ecf559

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/cli-usage.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ example:
4848
4949
[elsewhere]
5050
url = http://else.whe.re:8080
51-
private_token = CkqsjqcQSFH5FQKDccu4
51+
private_token = lookup: pass show path/to/password
5252
timeout = 1
5353
5454
The ``default`` option of the ``[global]`` section defines the GitLab server to

gitlab/config.py

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import os
1919
import configparser
20+
import subprocess
2021
from typing import List, Optional, Union
2122

2223
from gitlab.const import USER_AGENT
@@ -150,6 +151,16 @@ def __init__(
150151
except Exception:
151152
pass
152153

154+
for attr in ("job_token", "http_password", "private_token", "oauth_token"):
155+
value = getattr(self, attr)
156+
prefix = "lookup:"
157+
if isinstance(value, str) and value.lower().strip().startswith(prefix):
158+
helper = value[len(prefix) :].strip()
159+
value = (
160+
subprocess.check_output(helper, shell=True).decode("utf-8").strip()
161+
)
162+
setattr(self, attr, value)
163+
153164
self.api_version = "4"
154165
try:
155166
self.api_version = self._config.get("global", "api_version")

0 commit comments

Comments
 (0)