Files
2026-05-21 00:11:20 +02:00

29 lines
1.0 KiB
Python
Executable File

#!/opt/ci/venv/bin/python
"""Store a CI credential in the file keyring for ci-runner (two-entry scheme).
Usage:
sudo -u ci-runner /opt/ci/venv/bin/python tools/ci-cred-set.py <target> [<username>]
Examples:
sudo -u ci-runner /opt/ci/venv/bin/python tools/ci-cred-set.py BuildVMGuest "WINBUILD-2025\\ci_build"
sudo -u ci-runner /opt/ci/venv/bin/python tools/ci-cred-set.py GiteaPAT ci-runner-linux
"""
import getpass
import sys
try:
import keyring
except ImportError:
sys.exit("keyring not installed")
target = sys.argv[1] if len(sys.argv) > 1 else "BuildVMGuest"
username = sys.argv[2] if len(sys.argv) > 2 else input(f"Username for {target}: ")
password = getpass.getpass(f"Password for {target}/{username}: ")
# Entry 1: password, keyed by (service=target, username=username)
keyring.set_password(target, username, password)
# Entry 2: username stored separately so get_credential(target, None) can find it
keyring.set_password(f"{target}:meta", "username", username)
print(f"Stored: service={target!r} username={username!r}")