Compare commits
5 Commits
7b4a7c6f6d
...
cfeb253cac
Author | SHA1 | Date | |
---|---|---|---|
cfeb253cac | |||
23214ff78f | |||
a72ccd4b26 | |||
f66c489fc6 | |||
115aa579ba |
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,7 +1,10 @@
|
||||
result
|
||||
config.json
|
||||
log.txt
|
||||
/result
|
||||
|
||||
__pycache__/
|
||||
.vscode/
|
||||
.direnv/
|
||||
.mypy_cache/
|
||||
/.vscode/
|
||||
/.direnv/
|
||||
/.mypy_cache/
|
||||
|
||||
/config.json
|
||||
/log.txt
|
||||
/api.key
|
||||
|
@ -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/dyn-gandi/config.json` and then `/etc/dyn-gandi.json`.
|
||||
By default the program will look for `$HOME/.config/dyn-gandi/config.json` and then `/etc/dyn-gandi.json`.
|
||||
'''
|
||||
|
||||
if path is None:
|
||||
@ -22,6 +22,11 @@ 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()
|
||||
@ -52,7 +57,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.
|
||||
|
||||
@ -125,8 +130,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_to_renew[key][domain] != []:
|
||||
log(f"[INFO][{','.join(records_to_renew)}] Record need to be renewed")
|
||||
if (records := records_to_renew[key][domain]) != []:
|
||||
log(f"[INFO][{','.join(records)}] Records need to be renewed")
|
||||
|
||||
else:
|
||||
log(f"[ERROR][{domain}][{response.status_code}] {response.json()}")
|
||||
|
@ -21,14 +21,6 @@
|
||||
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 {
|
||||
|
@ -1,70 +0,0 @@
|
||||
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
|
||||
!= null) {
|
||||
script = "${package}/bin/dyn_gandi --config ${configFile}";
|
||||
script = "${package}/bin/dyn-gandi --config ${configFile}";
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
|
@ -4,14 +4,14 @@ version = "0.1.0"
|
||||
description = "A DNS updater"
|
||||
authors = ["Kristian Krsnik <git@krsnik.at>"]
|
||||
readme = "README.md"
|
||||
packages = [{include = "dyn_gandi"}]
|
||||
packages = [{ include = "dyn_gandi" }]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
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"]
|
||||
|
Loading…
Reference in New Issue
Block a user