Esempio n. 1
0
def wait_for_dns_change(change_id, account_number=None):
    """
    Checks the authoritative DNS Server to see if changes have propagated.

    :param change_id: tuple of domain/token
    :param account_number:
    :return:
    """
    _check_conf()
    domain, token = change_id
    number_of_attempts = 3
    zone = _get_zone_name(domain)
    nameserver = dnsutil.get_authoritative_nameserver(zone)
    record_found = False
    attempts = 0
    while attempts < number_of_attempts:
        txt_records = dnsutil.get_dns_records(domain, "TXT", nameserver)
        for txt_record in txt_records:
            if txt_record == token:
                record_found = True
                break
        if record_found:
            break
        time.sleep(5)
        attempts += 1
    function = inspect.currentframe().f_code.co_name
    log_data = {
        "function": function,
        "fqdn": domain,
        "status": record_found,
        "account": account_number,
        "message": "Record status on NS1 authoritative server",
    }
    current_app.logger.debug(log_data)
    if record_found:
        metrics.send(f"{function}.success",
                     "counter",
                     1,
                     metric_tags={
                         "fqdn": domain,
                         "txt_record": token
                     })
    else:
        metrics.send(f"{function}.fail",
                     "counter",
                     1,
                     metric_tags={
                         "fqdn": domain,
                         "txt_record": token
                     })
Esempio n. 2
0
def wait_for_dns_change(change_id, account_number=None):
    """
    Checks the authoritative DNS Server to see if changes have propagated.

    :param change_id: tuple of domain/token
    :param account_number:
    :return:
    """
    _check_conf()
    domain, token = change_id
    number_of_attempts = current_app.config.get("ACME_POWERDNS_RETRIES", 3)
    zone_name = _get_zone_name(domain, account_number)
    nameserver = dnsutil.get_authoritative_nameserver(zone_name)
    record_found = False
    for attempts in range(0, number_of_attempts):
        txt_records = dnsutil.get_dns_records(domain, "TXT", nameserver)
        for txt_record in txt_records:
            if txt_record == token:
                record_found = True
                break
        if record_found:
            break
        time.sleep(10)

    function = sys._getframe().f_code.co_name
    log_data = {
        "function": function,
        "fqdn": domain,
        "status": record_found,
        "message": "Record status on PowerDNS authoritative server"
    }
    current_app.logger.debug(log_data)

    if record_found:
        metrics.send(f"{function}.success",
                     "counter",
                     1,
                     metric_tags={
                         "fqdn": domain,
                         "txt_record": token
                     })
    else:
        metrics.send(f"{function}.fail",
                     "counter",
                     1,
                     metric_tags={
                         "fqdn": domain,
                         "txt_record": token
                     })