summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorvg <vgm+dev@devys.org>2019-05-21 15:35:48 +0200
committervg <vgm+dev@devys.org>2019-05-21 15:35:48 +0200
commit89f066b81671df29772be31804af3c531f58cec1 (patch)
tree93c403e3c4ab0141345362abe293485bd18f9439 /doc
downloadacme-dns-tiny-89f066b81671df29772be31804af3c531f58cec1.tar.gz
acme-dns-tiny-89f066b81671df29772be31804af3c531f58cec1.tar.bz2
acme-dns-tiny-89f066b81671df29772be31804af3c531f58cec1.zip
Initial commit
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/ssh_api_example/update-acme-challenge59
1 files changed, 59 insertions, 0 deletions
diff --git a/doc/ssh_api_example/update-acme-challenge b/doc/ssh_api_example/update-acme-challenge
new file mode 100755
index 0000000..39b90d0
--- /dev/null
+++ b/doc/ssh_api_example/update-acme-challenge
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+# Copyright 2019 vg
+# SPDX-License-Identifier: MIT
+
+'''\
+Takes json in stdin to modify a challenge in a zone txt record.
+
+Usage: update-acme-challenge --zones=ZONES
+
+Options:
+ --zones comma separated list of authorized zones to be changed
+
+Json format:
+{
+ "action": "add|delete",
+ "zone": "zone_name_to_modify",
+ "challenge": "mandatory only with add action: challenge",
+}
+'''
+
+
+import sys
+import json
+import subprocess
+import docopt
+
+
+def nsupdate(zone, challenge):
+ content = f'''
+ server ::1
+ del {zone} TXT
+ add {zone} TXT "{challenge}"
+ send
+ '''
+ subprocess.run(['nsupdate'], check=True, input=content)
+
+
+def main():
+ args = docopt.docopt(__doc__)
+
+ jsonmap = json.load(sys.stdin.read())
+
+ zones = [x.strip() for x in args['--zones'].split(',')]
+ zone = jsonmap.get('zone', '')
+ if zone not in zones:
+ raise ValueError(f'not permitted to modify zone {zone}')
+
+ action = jsonmap.get('action', '')
+ if action not in ('add', 'delete'):
+ raise ValueError(f'bad value for action content: {action}')
+
+ challenge = jsonmap.get('challenge', '')
+ if not all(x.isalnum() or x in ('+', '/') for x in challenge):
+ raise ValueError('bad format for challenge content')
+
+ nsupdate(zone, challenge if action == 'add' else '')
+
+
+main()