Compare commits

..

No commits in common. "cfeb253cacde6e11f95815b8920f6b604433809d" and "7b4a7c6f6d6c569d5f855ca59bdc1026dea6fb4c" have entirely different histories.

6 changed files with 91 additions and 21 deletions

15
.gitignore vendored
View File

@ -1,10 +1,7 @@
/result
result
config.json
log.txt
__pycache__/
/.vscode/
/.direnv/
/.mypy_cache/
/config.json
/log.txt
/api.key
.vscode/
.direnv/
.mypy_cache/

View File

@ -13,7 +13,7 @@ def loadSettings(path: str | None) -> dict:
Load the settings file.
`path` Path to a settings file.
By default the program will look for `$HOME/.config/dyn-gandi/config.json` and then `/etc/dyn-gandi.json`.
By default the program will look for `$HOME/dyn-gandi/config.json` and then `/etc/dyn-gandi.json`.
'''
if path is None:
@ -22,11 +22,6 @@ def loadSettings(path: str | None) -> dict:
if not os.path.exists(path):
path = '/etc/dyn-gandi.json'
if not os.path.exists(path):
print(
f"[ERROR] No config file found at '~/.config/dyn-gandi/config.json' or '/etc/dyn-gandi.json'")
quit()
if not os.path.exists(path):
print(f"[ERROR] '{path}' does not exist.")
quit()
@ -57,7 +52,7 @@ def loadSettings(path: str | None) -> dict:
def log(logline: str, path: str = './log.txt', stdout: bool = False) -> None:
'''
Appends `logline` at the end of the file file with a timestamp.
Appends logline at the end of the file file with a timestamp
`logline` The line to log.
@ -130,8 +125,8 @@ def checkRecords(api: dict[str, dict[str, list[str]]], current_ip: str, log: Cal
records_to_renew[key][domain] = list(set(records_to_renew[key][domain]) - set(record['rrset_name'] for record in (
filter(lambda x: current_ip in x['rrset_values'], response.json()))))
if (records := records_to_renew[key][domain]) != []:
log(f"[INFO][{','.join(records)}] Records need to be renewed")
if records_to_renew[key][domain] != []:
log(f"[INFO][{','.join(records_to_renew)}] Record need to be renewed")
else:
log(f"[ERROR][{domain}][{response.status_code}] {response.json()}")

View File

@ -21,6 +21,14 @@
default = pkgs.${system}.poetry2nix.mkPoetryApplication {projectDir = self;};
});
# `nix run`
apps = forAllSystems (system: {
default = {
program = "${self.packages.${system}.default}/bin/dyn_gandi";
type = "app";
};
});
# `nix develop`
devShells = forAllSystems (system: {
default = pkgs.${system}.mkShellNoCC {

70
nix/hm-module.nix Normal file
View File

@ -0,0 +1,70 @@
self: {
config,
lib,
pkgs,
...
}: let
cfg = config.dyn-gandi;
package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
inherit (lib) mkIf mkEnableOption mkOption types;
format = pkgs.formats.json {};
configFile = format.generate "config.json" cfg.settings;
in {
options.dyn-gandi = {
enable = mkEnableOption "dyn-gandi";
timer = lib.mkOption {
type = types.nullOr types.int;
default = null;
description = lib.mdDoc ''
The time intervall in seconds the script should be repeated.
'';
};
settings = mkOption {
type = with types; let
valueType = nullOr (oneOf [
# TODO: restrict type to actual config file structure
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
]);
in
valueType;
default = throw "Please specify dyn-gandi.settings";
};
};
config = mkIf cfg.enable {
home.packages = [package]; # TODO: make this architecture independent
systemd.user.services.dyn-gandi = mkIf (cfg.timer
!= null) {
Unit = {
After = ["network.target"];
};
Install = {WantedBy = ["default.target"];};
Service = {
Type = "oneshot";
ExecStart = "${package}/bin/dyn_gandi --config ${configFile}";
};
};
systemd.user.timers.dyn-gandi = mkIf (cfg.timer
!= null) {
Install = {WantedBy = ["timers.target"];};
Timer = {
OnBootSec = "0s";
OnUnitActiveSec = "${toString cfg.timer}s";
Unit = "dyn-gandi.service";
};
};
};
}

View File

@ -46,7 +46,7 @@ in {
systemd.services.dyn-gandi = mkIf (cfg.timer
!= null) {
script = "${package}/bin/dyn-gandi --config ${configFile}";
script = "${package}/bin/dyn_gandi --config ${configFile}";
serviceConfig = {
Type = "oneshot";

View File

@ -11,7 +11,7 @@ python = "^3.10"
requests = "2.29.0"
[tool.poetry.scripts]
dyn-gandi = "dyn_gandi.main:main"
dyn_gandi = "dyn_gandi.main:main"
[build-system]
requires = ["poetry-core"]