-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertbot_auth.py
executable file
·45 lines (35 loc) · 1.1 KB
/
certbot_auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
"""Authenticator script for certbot using the porkbun API.
Example usage:
sudo certbot certonly \
--agree-tos --non-interactive --register-unsafely-without-email \
--authenticator manual \
--preferred-challenges=dns \
--manual-auth-hook certbot_auth.py \
--installer nginx \
-d "example.com"
"""
from porkbun import Porkbun, get_config
import os
import time
from pathlib import Path
# FIXME: hard-coded path for now
config_path = str(Path(__file__).parent) + '/config.toml'
# get environment variables
domain = os.environ['CERTBOT_DOMAIN']
certbot_validation = os.environ['CERTBOT_VALIDATION']
print('Domain : ' + domain)
print('Challenge: ' + certbot_validation)
# update record
porkbun = Porkbun(**get_config(config_path))
responses = porkbun.update_record(
domain=domain,
name=f'_acme-challenge',
type_='TXT',
content=certbot_validation,
ttl='120') # tll=120, as per the certbot wiki
print(f'Deletion response:\n{responses[0]}')
print(f'Creation response:\n{responses[1]}')
# wait to allow for changes to propagate
print('sleeping ...')
time.sleep(120)