Compare commits

..

No commits in common. "84f4b11b9ceaa65f6599779fba6f30249627e59d" and "e6d487863643aff02b4bdbc08440c836e06d41e1" have entirely different histories.

3 changed files with 10 additions and 35 deletions

View File

@ -27,7 +27,7 @@ The script looks for a config file at `$HOME/.config/dyn-gandi/config.log` or `/
}, },
"/path/to/a/file/containing/api_key": { "/path/to/a/file/containing/api_key": {
"example.at": [ "sub1" ], "example.at": [ "sub1" ],
"example.au": [ "sub1", "sub2" ] "example.au": [ "sub1" "sub2" ]
} }
}, },
"resolvers": [ "resolvers": [

View File

@ -6,12 +6,11 @@ from datetime import datetime
from typing import Callable, Any from typing import Callable, Any
def loadSettings(path: str | None) -> dict: def loadSettings() -> dict:
if path is None: path = f"{os.path.expanduser('~')}/.config/dyn-gandi/config.json"
path = f"{os.path.expanduser('~')}/.config/dyn-gandi/config.json"
if not os.path.exists(path): if not os.path.exists(path):
path = '/etc/dyn-gandi.json' path = '/etc/dyn-gandi.json'
if not os.path.exists(path): if not os.path.exists(path):
quit() quit()
@ -100,29 +99,8 @@ def renewRecords(api: dict[str, dict[str, list[str]]], current_ip: str, log: Cal
log(f"[ERROR][{domain}][{record}][{response.status_code}] {response.json()}") log(f"[ERROR][{domain}][{record}][{response.status_code}] {response.json()}")
def parseArgv(argv: list[str]) -> dict[str, list[str]]:
cli_options = {}
buffer = None
for arg in argv:
if arg.startswith('--'):
cli_options[arg.removeprefix('--')] = []
buffer = arg.removeprefix('--')
else:
cli_options[buffer].append(arg)
return cli_options
def main(): def main():
argv = os.sys.argv settings = loadSettings()
options = {}
if len(argv) > 1:
options = parseArgv(argv[1:])
config_path = None
if 'config' in options:
config_path = options['config'][0]
settings = loadSettings(config_path)
log_path, ttl = settings['log_path'], settings['ttl'] log_path, ttl = settings['log_path'], settings['ttl']
def logger(x: str) -> Any: return log(x, log_path) def logger(x: str) -> Any: return log(x, log_path)

View File

@ -8,9 +8,6 @@ inputs: {
cfg = config.dyn-gandi; cfg = config.dyn-gandi;
package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default; package = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.default;
inherit (lib) mkIf mkEnableOption mkOption types; inherit (lib) mkIf mkEnableOption mkOption types;
format = pkgs.formats.json {};
configFile = format.generate "config.json" cfg.settings;
in { in {
options.dyn-gandi = { options.dyn-gandi = {
enable = mkEnableOption "dyn-gandi"; enable = mkEnableOption "dyn-gandi";
@ -45,14 +42,14 @@ in {
environment = { environment = {
systemPackages = [package]; systemPackages = [package];
# etc."dyn-gandi.json" = { etc."dyn-gandi.json" = {
# text = builtins.toJSON cfg.settings; text = builtins.toJSON cfg.settings;
# }; };
}; };
systemd.services.dyn-gandi = mkIf (cfg.timer systemd.services.dyn-gandi = mkIf (cfg.timer
!= null) { != null) {
script = "${package}/bin/dyn_gandi --config ${configFile}"; script = "${package}/bin/dyn_gandi"; # TODO: add config file via command line options
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";