mirror of
https://github.com/tomasriveral/nixpkgs-notifier.git
synced 2026-08-11 18:28:38 +02:00
feat: expand env variables in config at runtime
This commit is contained in:
+27
-1
@@ -74,6 +74,32 @@ def load_config():
|
||||
print("Config file is broken. Using default config.")
|
||||
return DEFAULT_CONFIG
|
||||
|
||||
import re
|
||||
|
||||
def expand_env_vars(obj):
|
||||
if isinstance(obj, dict):
|
||||
return {
|
||||
key: expand_env_vars(value)
|
||||
for key, value in obj.items()
|
||||
}
|
||||
|
||||
elif isinstance(obj, list):
|
||||
return [
|
||||
expand_env_vars(item)
|
||||
for item in obj
|
||||
]
|
||||
|
||||
elif isinstance(obj, str):
|
||||
pattern = r"(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)"
|
||||
|
||||
def replace(match):
|
||||
var = match.group(1)
|
||||
return os.environ.get(var, match.group(0))
|
||||
|
||||
return re.sub(pattern, replace, obj)
|
||||
|
||||
return obj
|
||||
|
||||
def addTracker(PRnumber):
|
||||
result = fetchStatus(PRnumber)
|
||||
if result == "accepted":
|
||||
@@ -237,7 +263,7 @@ def fetchStatus(PRnumber):
|
||||
|
||||
def main():
|
||||
# fetch config
|
||||
cfg = load_config()
|
||||
cfg = expand_env_vars(load_config())
|
||||
|
||||
global configTime
|
||||
global configFetchTime
|
||||
|
||||
Reference in New Issue
Block a user