Adding initial files
This commit is contained in:
48
generate-dns-record.py
Executable file
48
generate-dns-record.py
Executable file
@ -0,0 +1,48 @@
|
||||
#!/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'
|
||||
|
||||
response = requests.get(LIVEDNS_API_URL + '/' + domain + '/' +
|
||||
'records' + '/' + SUBDOMAIN, headers=headers)
|
||||
|
||||
#if len(response.json()) > 0 and 'rrset_type' in response.json()[0]:
|
||||
# logger.warning('Warning! Stale authentication token found!')
|
||||
# delete_dns_record(SUBDOMAIN, domain)
|
||||
|
||||
# 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)
|
||||
|
||||
time.sleep(30)
|
Reference in New Issue
Block a user