summaryrefslogtreecommitdiff
path: root/pkgs/increment-zone-serials/increment-zone-serials.py
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2025-04-19 10:48:15 -0600
committerAlejandro Soto <alejandro@34project.org>2025-04-24 14:27:38 -0600
commit1039d1d47a53be0c814a03608e94a9d0e8f4405b (patch)
treea6cf802896f0ad41742354499df8063d9065eb02 /pkgs/increment-zone-serials/increment-zone-serials.py
parentf4ed93ff7d01e659960b9cd3dc5bc3d6d6e27d01 (diff)
sys/ns: implement automatic PTR zones
Diffstat (limited to 'pkgs/increment-zone-serials/increment-zone-serials.py')
-rwxr-xr-xpkgs/increment-zone-serials/increment-zone-serials.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/pkgs/increment-zone-serials/increment-zone-serials.py b/pkgs/increment-zone-serials/increment-zone-serials.py
index 2d5753a..394075a 100755
--- a/pkgs/increment-zone-serials/increment-zone-serials.py
+++ b/pkgs/increment-zone-serials/increment-zone-serials.py
@@ -2,18 +2,14 @@
import datetime, json, os.path, sys
-base_dir = sys.argv[1]
+root_dir = sys.argv[1]
serial_num = lambda n: f'{today}{n:02}'
-today_str = datetime.datetime.utcnow().date().strftime('%Y%m%d')
-today = int(today_str)
+today_str = datetime.datetime.now(datetime.UTC).date().strftime('%Y%m%d')
+today = int(today_str)
-paths = []
-
-for zone, data in json.load(sys.stdin).items():
- expected_hash = data['expected']
-
- old_serial_int = data['serial']
+def update_serial(*, zone_class, name, expected, serial):
+ old_serial_int = serial
new_serial = serial_num(0)
if old_serial_int is not None:
@@ -28,17 +24,24 @@ for zone, data in json.load(sys.stdin).items():
if new_serial is None:
new_serial = str(old_serial_int + 1)
- path = os.path.join(base_dir, zone, 'serial.nix')
- with open(os.path.join(base_dir, zone, 'serial.nix'), 'w') as serial_file:
+ path = os.path.join(root_dir, zone_class, name, 'serial.nix')
+ with open(path, 'w') as serial_file:
print(f'''\
{{
config = {{
soa.serial = {new_serial};
- nullSerialHash = "{expected_hash}";
+ nullSerialHash = "{expected}";
}};
}}
''', file=serial_file)
- paths.append(path)
+
+ return path
+
+paths = []
+
+for zone_class, zones in json.load(sys.stdin).items():
+ for zone in zones.values():
+ paths.append(update_serial(**zone, zone_class=zone_class))
# Se imprime al final para evitar estados intermedios si algo tira excepción
for path in paths: