Updated logger to log a dictionary instead of a string
This commit is contained in:
parent
6bf920e66c
commit
3ba7fdbd49
|
@ -1,6 +1,7 @@
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from .ultradns_zone import Zone
|
from .ultradns_zone import Zone
|
||||||
from .ultradns_record import Record
|
from .ultradns_record import Record
|
||||||
|
|
||||||
|
@ -115,7 +116,14 @@ def wait_for_dns_change(change_id, account_number=None):
|
||||||
nameserver = get_authoritative_nameserver(fqdn)
|
nameserver = get_authoritative_nameserver(fqdn)
|
||||||
for attempts in range(0, number_of_attempts):
|
for attempts in range(0, number_of_attempts):
|
||||||
status = _has_dns_propagated(fqdn, token, nameserver)
|
status = _has_dns_propagated(fqdn, token, nameserver)
|
||||||
current_app.logger.debug("Record status on ultraDNS authoritative server for fqdn: {}: {}".format(fqdn, status))
|
function = sys._getframe().f_code.co_name
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"fqdn": fqdn,
|
||||||
|
"status": status,
|
||||||
|
"message": "Record status on ultraDNS authoritative server"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
if status:
|
if status:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
break
|
break
|
||||||
|
@ -123,7 +131,14 @@ def wait_for_dns_change(change_id, account_number=None):
|
||||||
if status:
|
if status:
|
||||||
for attempts in range(0, number_of_attempts):
|
for attempts in range(0, number_of_attempts):
|
||||||
status = _has_dns_propagated(fqdn, token, get_public_authoritative_nameserver())
|
status = _has_dns_propagated(fqdn, token, get_public_authoritative_nameserver())
|
||||||
current_app.logger.debug("Record status on Google DNS for fqdn: {}: {}".format(fqdn, status))
|
function = sys._getframe().f_code.co_name
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"fqdn": fqdn,
|
||||||
|
"status": status,
|
||||||
|
"message": "Record status on Public DNS"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
if status:
|
if status:
|
||||||
metrics.send("wait_for_dns_change_success", "counter", 1)
|
metrics.send("wait_for_dns_change_success", "counter", 1)
|
||||||
break
|
break
|
||||||
|
@ -196,15 +211,24 @@ def create_txt_record(domain, token, account_number):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_post(path, params)
|
_post(path, params)
|
||||||
current_app.logger.debug(
|
function = sys._getframe().f_code.co_name
|
||||||
"TXT record created: {0}, token: {1}".format(fqdn, token)
|
log_data = {
|
||||||
)
|
"function": function,
|
||||||
|
"fqdn": fqdn,
|
||||||
|
"token": token,
|
||||||
|
"message": "TXT record created"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.debug(
|
function = sys._getframe().f_code.co_name
|
||||||
"Unable to add record. Domain: {}. Token: {}. "
|
log_data = {
|
||||||
"Record already exists: {}".format(domain, token, e),
|
"function": function,
|
||||||
exc_info=True,
|
"domain": domain,
|
||||||
)
|
"token": token,
|
||||||
|
"Exception": e,
|
||||||
|
"message": "Unable to add record. Record already exists."
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
|
|
||||||
change_id = (fqdn, token)
|
change_id = (fqdn, token)
|
||||||
return change_id
|
return change_id
|
||||||
|
@ -222,7 +246,12 @@ def delete_txt_record(change_id, account_number, domain, token):
|
||||||
# has to be deleted.
|
# has to be deleted.
|
||||||
|
|
||||||
if not domain:
|
if not domain:
|
||||||
current_app.logger.debug("delete_txt_record: No domain passed")
|
function = sys._getframe().f_code.co_name
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"message": "No domain passed"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
zone_name = get_zone_name(domain, account_number)
|
zone_name = get_zone_name(domain, account_number)
|
||||||
|
@ -241,7 +270,13 @@ def delete_txt_record(change_id, account_number, domain, token):
|
||||||
# Remove the record from the RRSet locally
|
# Remove the record from the RRSet locally
|
||||||
record.rdata.remove("{}".format(token))
|
record.rdata.remove("{}".format(token))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
current_app.logger.debug("Token not found")
|
function = sys._getframe().f_code.co_name
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"token": token,
|
||||||
|
"message": "Token not found"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Delete the RRSet from UltraDNS
|
# Delete the RRSet from UltraDNS
|
||||||
|
@ -259,16 +294,23 @@ def delete_txt_record(change_id, account_number, domain, token):
|
||||||
def delete_acme_txt_records(domain):
|
def delete_acme_txt_records(domain):
|
||||||
|
|
||||||
if not domain:
|
if not domain:
|
||||||
current_app.logger.debug("delete_acme_txt_records: No domain passed")
|
function = sys._getframe().f_code.co_name
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"message": "No domain passed"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
return
|
return
|
||||||
acme_challenge_string = "_acme-challenge"
|
acme_challenge_string = "_acme-challenge"
|
||||||
if not domain.startswith(acme_challenge_string):
|
if not domain.startswith(acme_challenge_string):
|
||||||
current_app.logger.debug(
|
function = sys._getframe().f_code.co_name
|
||||||
"delete_acme_txt_records: Domain {} doesn't start with string {}. "
|
log_data = {
|
||||||
"Cowardly refusing to delete TXT records".format(
|
"function": function,
|
||||||
domain, acme_challenge_string
|
"domain": domain,
|
||||||
)
|
"acme_challenge_string": acme_challenge_string,
|
||||||
)
|
"message": "Domain does not start with the acme challenge string"
|
||||||
|
}
|
||||||
|
current_app.logger.debug(log_data)
|
||||||
return
|
return
|
||||||
|
|
||||||
zone_name = get_zone_name(domain)
|
zone_name = get_zone_name(domain)
|
||||||
|
|
Loading…
Reference in New Issue