Adding initial files
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -138,3 +138,4 @@ dmypy.json
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
GandiAuthenticationHeader.py
|
||||
|
15
DnsRecordDeleter.py
Normal file
15
DnsRecordDeleter.py
Normal file
@ -0,0 +1,15 @@
|
||||
import requests
|
||||
from Logger import load_logger
|
||||
from GandiAuthenticationHeader import get_authentication_headers
|
||||
|
||||
logger = load_logger()
|
||||
headers = get_authentication_headers()
|
||||
LIVEDNS_API_URL = 'https://api.gandi.net/v5/livedns/domains'
|
||||
|
||||
def delete_dns_record(subdomain, domain):
|
||||
response = requests.delete(LIVEDNS_API_URL + '/' + domain
|
||||
+ '/records/' + subdomain, headers=headers)
|
||||
|
||||
if not response.ok:
|
||||
logger.error(response.raise_for_status())
|
||||
exit(1)
|
3
EnvironmentVariablesLoader.py
Normal file
3
EnvironmentVariablesLoader.py
Normal file
@ -0,0 +1,3 @@
|
||||
import os
|
||||
|
||||
email = os.environ['LOGGER_EMAIL']
|
12
Logger.py
Normal file
12
Logger.py
Normal file
@ -0,0 +1,12 @@
|
||||
import yaml
|
||||
import logging
|
||||
import logging.config
|
||||
import logging.handlers
|
||||
|
||||
def load_logger():
|
||||
with open('Python loggers.yaml') as cfg:
|
||||
config = yaml.safe_load(cfg)
|
||||
logging.config.dictConfig(config)
|
||||
|
||||
return logging.getLogger('Certbot-Gandi-Authenticator')
|
||||
|
23
Python loggers.yaml
Normal file
23
Python loggers.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
version: 1
|
||||
formatters:
|
||||
dateTimeFormatter:
|
||||
format: '%(name)s on %(asctime)s: [%(levelname)s] %(message)s'
|
||||
datefmt: '%Y-%m-%d %H:%M:%S'
|
||||
handlers:
|
||||
system:
|
||||
class: logging.handlers.SysLogHandler
|
||||
level: INFO
|
||||
formatter: dateTimeFormatter
|
||||
address: /dev/log
|
||||
email:
|
||||
class: logging.handlers.SMTPHandler
|
||||
formatter: dateTimeFormatter
|
||||
mailhost: localhost
|
||||
fromaddr: python3@pentilescu.com
|
||||
toaddrs: ext://EnvironmentVariablesLoader.email
|
||||
subject: Gandi authentication failure
|
||||
level: ERROR
|
||||
loggers:
|
||||
Certbot-Gandi-Authenticator:
|
||||
level: INFO
|
||||
handlers: [system, email]
|
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)
|
11
remove-dns-record.py
Executable file
11
remove-dns-record.py
Executable file
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
from DnsRecordDeleter import delete_dns_record
|
||||
|
||||
SUBDOMAIN = '_acme-challenge'
|
||||
domain = os.environ['CERTBOT_DOMAIN']
|
||||
|
||||
delete_dns_record(SUBDOMAIN, domain)
|
||||
|
||||
|
Reference in New Issue
Block a user