Created
May 13, 2020 03:37
-
-
Save frasertweedale/ca42ff31d5f5b8d3c6d4d3a94f9fbd0e to your computer and use it in GitHub Desktop.
certbot-dns-ipa.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
from dns import resolver | |
from ipalib import api | |
from ipapython import dnsutil | |
certbot_domain = os.environ['CERTBOT_DOMAIN'] | |
certbot_validation = os.environ['CERTBOT_VALIDATION'] | |
if 'CERTBOT_AUTH_OUTPUT' in os.environ: | |
command = 'dnsrecord_del' | |
else: | |
command = 'dnsrecord_add' | |
validation_domain = f'_acme-challenge.{certbot_domain}' | |
fqdn = dnsutil.DNSName(validation_domain).make_absolute() | |
zone = dnsutil.DNSName(resolver.zone_for_name(fqdn)) | |
name = fqdn.relativize(zone) | |
api.bootstrap(context='cli') | |
api.finalize() | |
api.Backend.rpcclient.connect() | |
api.Command[command](zone, name, txtrecord=[certbot_validation], dnsttl=60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment