Compare commits
No commits in common. "cfeb253cacde6e11f95815b8920f6b604433809d" and "7b4a7c6f6d6c569d5f855ca59bdc1026dea6fb4c" have entirely different histories.
cfeb253cac
...
7b4a7c6f6d
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,10 +1,7 @@
|
|||||||
/result
|
result
|
||||||
|
config.json
|
||||||
|
log.txt
|
||||||
__pycache__/
|
__pycache__/
|
||||||
/.vscode/
|
.vscode/
|
||||||
/.direnv/
|
.direnv/
|
||||||
/.mypy_cache/
|
.mypy_cache/
|
||||||
|
|
||||||
/config.json
|
|
||||||
/log.txt
|
|
||||||
/api.key
|
|
@ -13,7 +13,7 @@ def loadSettings(path: str | None) -> dict:
|
|||||||
Load the settings file.
|
Load the settings file.
|
||||||
|
|
||||||
`path` Path to a 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:
|
if path is None:
|
||||||
@ -22,11 +22,6 @@ def loadSettings(path: str | None) -> dict:
|
|||||||
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):
|
|
||||||
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):
|
if not os.path.exists(path):
|
||||||
print(f"[ERROR] '{path}' does not exist.")
|
print(f"[ERROR] '{path}' does not exist.")
|
||||||
quit()
|
quit()
|
||||||
@ -57,7 +52,7 @@ def loadSettings(path: str | None) -> dict:
|
|||||||
|
|
||||||
def log(logline: str, path: str = './log.txt', stdout: bool = False) -> None:
|
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.
|
`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 (
|
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()))))
|
filter(lambda x: current_ip in x['rrset_values'], response.json()))))
|
||||||
|
|
||||||
if (records := records_to_renew[key][domain]) != []:
|
if records_to_renew[key][domain] != []:
|
||||||
log(f"[INFO][{','.join(records)}] Records need to be renewed")
|
log(f"[INFO][{','.join(records_to_renew)}] Record need to be renewed")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log(f"[ERROR][{domain}][{response.status_code}] {response.json()}")
|
log(f"[ERROR][{domain}][{response.status_code}] {response.json()}")
|
||||||
|
@ -21,6 +21,14 @@
|
|||||||
default = pkgs.${system}.poetry2nix.mkPoetryApplication {projectDir = self;};
|
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`
|
# `nix develop`
|
||||||
devShells = forAllSystems (system: {
|
devShells = forAllSystems (system: {
|
||||||
default = pkgs.${system}.mkShellNoCC {
|
default = pkgs.${system}.mkShellNoCC {
|
||||||
|
70
nix/hm-module.nix
Normal file
70
nix/hm-module.nix
Normal 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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -46,7 +46,7 @@ in {
|
|||||||
|
|
||||||
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 --config ${configFile}";
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
|
@ -11,7 +11,7 @@ python = "^3.10"
|
|||||||
requests = "2.29.0"
|
requests = "2.29.0"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
dyn-gandi = "dyn_gandi.main:main"
|
dyn_gandi = "dyn_gandi.main:main"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
Loading…
Reference in New Issue
Block a user