Skip to content

Instantly share code, notes, and snippets.

@berkutta
Last active January 7, 2020 07:31
Show Gist options
  • Save berkutta/dc34857f01c6b0a63c7fabd1540513c7 to your computer and use it in GitHub Desktop.
Save berkutta/dc34857f01c6b0a63c7fabd1540513c7 to your computer and use it in GitHub Desktop.
certbot certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d *.mydomain.ch
#!/usr/bin/env python
import json
import os
import requests
import sys
from requests.auth import HTTPBasicAuth
# URL to acme-dns instance
ACMEDNS_URL = ""
ACMEDNS_DOMAIN = ""
ACMEDNS_USER = ""
ACMEDNS_PASS = ""
### DO NOT EDIT BELOW THIS POINT ###
### HERE BE DRAGONS ###
VALIDATION_TOKEN = os.environ["CERTBOT_VALIDATION"]
class AcmeDnsClient(object):
"""
Handles the communication with ACME-DNS API
"""
def __init__(self, acmedns_url):
self.acmedns_url = acmedns_url
def update_txt_record(self, txt):
"""Updates the TXT challenge record to ACME-DNS subdomain."""
print("Update TXT challenge to " + txt)
update = {"type": "TXT", "hostname": ACMEDNS_DOMAIN, "token": txt}
headers = {"Content-Type": "application/json"}
res = requests.post(self.acmedns_url+"/update",
headers=headers,
auth=(ACMEDNS_USER, ACMEDNS_PASS),
data=json.dumps(update))
if res.status_code == 200:
return
else:
sys.exit(1)
if __name__ == "__main__":
# Init
client = AcmeDnsClient(ACMEDNS_URL)
# Update the TXT record in acme-dns instance
client.update_txt_record(VALIDATION_TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment