Merge pull request 'clan: Fix dyndns module' (#2421) from Qubasa/clan-core:Qubasa-main into main

This commit is contained in:
clan-bot
2024-11-17 12:13:08 +00:00

View File

@@ -169,51 +169,57 @@ in
serviceConfig = serviceConfig =
let let
pyscript = pkgs.writers.writePyPy3Bin "test.py" { libraries = [ ]; } '' pyscript =
import json pkgs.writers.writePyPy3Bin "test.py"
from pathlib import Path {
import os libraries = [ ];
doCheck = false;
}
''
import json
from pathlib import Path
import os
cred_dir = Path(os.getenv("CREDENTIALS_DIRECTORY")) cred_dir = Path(os.getenv("CREDENTIALS_DIRECTORY"))
config_str = os.getenv("MYCONFIG") config_str = os.getenv("MYCONFIG")
def get_credential(name): def get_credential(name):
secret_p = cred_dir / name secret_p = cred_dir / name
with open(secret_p, 'r') as f: with open(secret_p, 'r') as f:
return f.read().strip() return f.read().strip()
config = json.loads(config_str) config = json.loads(config_str)
print(f"Config: {config}") print(f"Config: {config}")
for attrset in config["settings"]: for attrset in config["settings"]:
if "password" in attrset: if "password" in attrset:
attrset['password'] = get_credential(attrset['password']) attrset['password'] = get_credential(attrset['password'])
elif "token" in attrset: elif "token" in attrset:
attrset['token'] = get_credential(attrset['token']) attrset['token'] = get_credential(attrset['token'])
elif "api_key" in attrset: elif "api_key" in attrset:
attrset['api_key'] = get_credential(attrset['api_key']) attrset['api_key'] = get_credential(attrset['api_key'])
else: else:
raise ValueError(f"Missing secret field in {attrset}") raise ValueError(f"Missing secret field in {attrset}")
# create directory data if it does not exist # create directory data if it does not exist
data_dir = Path('data') data_dir = Path('data')
data_dir.mkdir(mode=0o770, exist_ok=True) data_dir.mkdir(mode=0o770, exist_ok=True)
# Write the config with secrets back # Write the config with secrets back
config_path = data_dir / 'config.json' config_path = data_dir / 'config.json'
with open(config_path, 'w') as f: with open(config_path, 'w') as f:
f.write(json.dumps(config, indent=4)) f.write(json.dumps(config, indent=4))
# Set file permissions to read and write # Set file permissions to read and write
# only by the user and group # only by the user and group
config_path.chmod(0o660) config_path.chmod(0o660)
# Set file permissions to read # Set file permissions to read
# and write only by the user and group # and write only by the user and group
for file in data_dir.iterdir(): for file in data_dir.iterdir():
file.chmod(0o660) file.chmod(0o660)
''; '';
in in
{ {
ExecStartPre = lib.getExe pyscript; ExecStartPre = lib.getExe pyscript;