Don't update data['name'] if root domain
This commit is contained in:
parent
e534284cde
commit
09c2f90bf5
|
@ -15,30 +15,32 @@ endpoint_ipv4 = 'https://api-ipv4.porkbun.com/api/json/v3/'
|
|||
parser = ArgumentParser()
|
||||
parser.add_argument('config', help='path to config file')
|
||||
args = parser.parse_args()
|
||||
config = load(open(args.config))
|
||||
if 'name' not in config:
|
||||
config['name'] = config['domain']
|
||||
data = load(open(args.config))
|
||||
if 'name' in data:
|
||||
domain = data['name'] + '.' + data['domain']
|
||||
else:
|
||||
domain = data['domain']
|
||||
|
||||
|
||||
def api(url):
|
||||
"""Make a request to the Porkbun API"""
|
||||
|
||||
return loads(post(url, dumps(config)).text)
|
||||
return loads(post(url, dumps(data)).text)
|
||||
|
||||
|
||||
def edit_record(id, ip):
|
||||
"""Edit a A or AAAA record to point to a new IP address"""
|
||||
|
||||
print('Updating ' + config['domain'] + ' to ' + str(ip))
|
||||
print('Updating ' + data['domain'] + ' to ' + str(ip))
|
||||
|
||||
config['type'] = 'A' if ip.version == 4 else 'AAAA'
|
||||
config['content'] = str(ip)
|
||||
return api(endpoint + 'dns/edit/' + config['domain'] + '/' + id)
|
||||
data['type'] = 'A' if ip.version == 4 else 'AAAA'
|
||||
data['content'] = str(ip)
|
||||
return api(endpoint + 'dns/edit/' + data['domain'] + '/' + id)
|
||||
|
||||
|
||||
# Update records
|
||||
for record in api(endpoint + 'dns/retrieve/' + config['domain'])['records']:
|
||||
if record['name'] == config['name'] and record['type'] in 'AAAA':
|
||||
for record in api(endpoint + 'dns/retrieve/' + data['domain'])['records']:
|
||||
if record['name'] == domain and record['type'] in 'AAAA':
|
||||
ip = ip_address(api((endpoint_ipv4 if record['type'] == 'A' else endpoint) + 'ping')['yourIp'])
|
||||
if not str(ip) == record['content']:
|
||||
print(edit_record(record['id'], ip))
|
||||
|
|
Loading…
Reference in a new issue