40 lines
1.1 KiB
Python
Executable File
40 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Purpose of this script: to create a new TXT record
|
|
# on the Gandi DNS provider using the information
|
|
# supplied from the CERTBOT_VALIDATION and CERTBOT_DOMAIN
|
|
# environment variables (this was made to mainly work
|
|
# with certbot)
|
|
|
|
import os
|
|
import requests
|
|
import time
|
|
from DnsRecordDeleter import delete_dns_record
|
|
from Logger import load_logger
|
|
from GandiAuthenticationHeader import get_authentication_headers
|
|
|
|
headers = get_authentication_headers()
|
|
logger = load_logger()
|
|
|
|
validation_token = os.environ['CERTBOT_VALIDATION']
|
|
domain = os.environ['CERTBOT_DOMAIN']
|
|
|
|
SUBDOMAIN = '_acme-challenge'
|
|
LIVEDNS_API_URL = 'https://api.gandi.net/v5/livedns/domains'
|
|
|
|
# Create a new TXT record from scratch
|
|
record = {
|
|
"rrset_name": SUBDOMAIN,
|
|
"rrset_type": "TXT",
|
|
"rrset_ttl": 1800,
|
|
"rrset_values": [validation_token],
|
|
}
|
|
|
|
response = requests.post(LIVEDNS_API_URL + '/' + domain
|
|
+ '/records', headers=headers, json=record)
|
|
|
|
if not response.ok:
|
|
logger.error('Could not create proper DNS record for LETSENCRYPT')
|
|
logger.error(response.raise_for_status())
|
|
exit(1)
|