feat(dyndns): add additional secret and write dyndns script
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
@@ -21,6 +22,10 @@
|
||||
|
||||
systemd.services."dyndns" = {
|
||||
script = ''
|
||||
NC_CUSTOMER=${"$(cat " + config.age.secrets.nc_customer.path + ")"}
|
||||
NC_API_PASSWORD=${"$(cat " + config.age.secrets.nc_api_password.path + ")"}
|
||||
NC_API_KEY=${"$(cat " + config.age.secrets.nc_api_key.path + ")"}
|
||||
NC_DOMAIN=${"$(cat " + config.age.secrets.nc_domain.path + ")"}
|
||||
python3 -c "${builtins.readFile ./dyndns.py}"
|
||||
'';
|
||||
serviceConfig = {
|
||||
|
||||
+24
-2
@@ -1,3 +1,25 @@
|
||||
from nc_dnsapi import Client, DNSRecord
|
||||
from nc_dnsapi import Client
|
||||
import os, urllib3
|
||||
|
||||
pass
|
||||
customer = os.environ["NC_CUSTOMER"]
|
||||
api_password = os.environ["NC_API_PASSWORD"]
|
||||
api_key = os.environ["NC_API_KEY"]
|
||||
domain = os.environ["NC_DOMAIN"]
|
||||
|
||||
ip = str(urllib3.request("GET", "https://api.ipify.org").data)
|
||||
|
||||
with Client(customer, api_key, api_password) as api:
|
||||
to_be_updated = []
|
||||
records = api.dns_records(domain)
|
||||
|
||||
for record in records:
|
||||
if record.type in ["A", "AAAA"] and record.destination != ip:
|
||||
record.destination = ip
|
||||
to_be_updated.append(record)
|
||||
|
||||
|
||||
api.update_dns_records(domain, to_be_updated)
|
||||
|
||||
zone = api.dns_zone(domain)
|
||||
zone.ttl = 300
|
||||
api.update_dns_zone(domain, zone)
|
||||
|
||||
@@ -11,4 +11,8 @@
|
||||
file = ./nc_api_key.age;
|
||||
owner = "dyndns";
|
||||
};
|
||||
age.secrets.nc_domain = {
|
||||
file = ./nc_domain.age;
|
||||
owner = "dyndns";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
age-encryption.org/v1
|
||||
-> ssh-ed25519 RiiDcg JineodD1i5o56Z5gMieXLqfI31mltwwNYgW/F+Dyoy8
|
||||
mjASjjLWIjKcmZlZYAnLX5qewbz0xU798cBNeUtygjY
|
||||
-> ssh-rsa t41wew
|
||||
H/4HrD8Cw6A7NrXgslzYbm+okXjY5PslDFQXtchQ4J4ZDp7upOZVyiSOHDkT3/XU
|
||||
zjKXSPaS3HkM/OilwG+sFufS3UUKiFsSInmQyYieztBwLTrjBCnLfEsh+y/JM/DF
|
||||
EMiiuZ6dAMT0HbRamFYh0E5XMyrRuMgngvDrjkFnYsWWCGPwT5jzNjf19p+dAX6g
|
||||
7svxMaQEkAgA0jZU16MGG0i31L8SRKkSPadGh3EqoFMw/fg/ECjK27WVonj+UMM9
|
||||
SHq/Ahu6eYOIf69Ayk5P/iyi4hyDpNXXCBd2TigSZmedhkx6mH/PVR5LwAHYcNQQ
|
||||
VKroeDCHhO4C6lKQ0M0xvhj/lgoBMd+Tp03aL5RohqGnrkQNIppY5vsXcKWolcvB
|
||||
cC8OGu+fu2NBSDNALCDwbglzs3TLLk7GbqWYltqpzbzX7fi+CE5lxkG8ecsygMpY
|
||||
jXLggB2R5rgtjYti/56ux7DLuRVAY9FoYZOt9+PJRj45YnwS2Z1Er/A5TejC4TuL
|
||||
VcYMVyt8D8PjmbEefZWbvT4eYAWgZFqIUwGTGD+qKWY1iiA1kruebOoMeyUxM3ow
|
||||
9aZglWA378kwbSCRyGrMPjV8UzIPoQmrzqqjF5Ow6GGLvEuw3DRoLC2aTH3ZfY1k
|
||||
u9K8j29Nl3Sj/hBFPSnW0YR05diMZbWFrybhQQ9x3HM
|
||||
--- O4TEPeHph/lRMujfo8YPF6d6EjJpDd+BBNtlWGfQWQI
|
||||
_N¶[,`E�,ãÊFyÉT¶J"¼§bXCõFm€TËg&J5z æ�”Ĉ�ì␍¹£¢
|
||||
Reference in New Issue
Block a user