create-deploy-user.py: .env neben dem Skript automatisch laden
This commit is contained in:
1 parent
faffee6410
commit
59cc0f8100
2 files changed
+17
-4
No files matched your search
@@ -14,6 +14,7 @@ import os
|
||||
import re
|
||||
import sys
|
||||
from getpass import getpass
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import authentik_client
|
||||
@@ -156,7 +157,20 @@ def make_username(repo_path: str) -> str:
|
||||
return name[:32].rstrip("_")
|
||||
|
||||
|
||||
def load_env_file(path: Path) -> None:
|
||||
"""Liest KEY=VALUE-Zeilen aus einer .env; bereits gesetzte Variablen haben Vorrang."""
|
||||
if not path.is_file():
|
||||
return
|
||||
for line in path.read_text().splitlines():
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
key, _, value = line.removeprefix("export ").partition("=")
|
||||
os.environ.setdefault(key.strip(), value.strip().strip("\"'"))
|
||||
|
||||
|
||||
def main() -> int:
|
||||
load_env_file(Path(__file__).resolve().parent / ".env")
|
||||
args = parse_args()
|
||||
|
||||
if not re.fullmatch(r"[A-Za-z0-9_-]+", args.server):
|
||||
|
||||
Reference in new issue
Block a user