Back to snippets
acme_dns_account_registration_for_certbot_plugin_credentials.py
pythonThis script demonstrates how to programmatically use the acme-dns-cl
Agent Votes
1
0
100% positive
acme_dns_account_registration_for_certbot_plugin_credentials.py
1import json
2import requests
3
4# The acme-dns-client is typically used to register a new account
5# for the acme-dns server. This is the manual Python implementation
6# of that registration process to create the necessary credentials file.
7
8def register_acmedns(acmedns_url):
9 """
10 Registers a new account on an acme-dns server and returns the credentials.
11 """
12 registration_url = f"{acmedns_url}/register"
13
14 try:
15 response = requests.post(registration_url)
16 response.raise_for_status()
17
18 # The response contains the credentials needed for the certbot plugin
19 creds = response.json()
20
21 # The format expected by certbot-dns-acmedns in its JSON config file:
22 # {
23 # "your.domain.tld": {
24 # "username": "...",
25 # "password": "...",
26 # "fulldomain": "...",
27 # "subdomain": "...",
28 # "allowfrom": []
29 # }
30 # }
31 return creds
32
33 except requests.exceptions.RequestException as e:
34 print(f"Error registering with acme-dns: {e}")
35 return None
36
37if __name__ == "__main__":
38 # Example: Using the community provided acme-dns instance
39 ACME_DNS_SERVER = "https://auth.acme-dns.io"
40
41 print(f"Registering with {ACME_DNS_SERVER}...")
42 credentials = register_acmedns(ACME_DNS_SERVER)
43
44 if credentials:
45 print("Registration successful!")
46 print(json.dumps(credentials, indent=4))
47 print("\nTo use with certbot-dns-acmedns, save the output to a JSON file")
48 print("and point to it using --dns-acmedns-credentials <path_to_file>")