Skip to content

Commit

Permalink
Fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
adferrand committed May 1, 2022
1 parent fb1314b commit da7c407
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/dnsrobocert/core/challenge.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Any, Dict, Optional

import dns.rdatatype
import dns.resolver
import tldextract
from dns.exception import Timeout
from dns.rdatatype import RdataType
from dns.resolver import get_default_resolver, NXDOMAIN, NoAnswer
from lexicon.client import Client
from lexicon.config import ConfigResolver

Expand Down Expand Up @@ -58,14 +59,14 @@ def txt_challenge(


def check_one_challenge(challenge: str, token: Optional[str]) -> bool:
resolver = dns.resolver.get_default_resolver() # type: ignore[attr-defined]
resolver = get_default_resolver()

try:
answers = resolver.query(challenge, "TXT")
except (resolver.NXDOMAIN, resolver.NoAnswer):
except (NXDOMAIN, NoAnswer):
print(f"TXT {challenge} does not exist.")
return False
except dns.exception.Timeout as e:
except Timeout as e:
print(f"Timeout while trying to check TXT {challenge}: {e}")
return False
else:
Expand All @@ -89,14 +90,14 @@ def check_one_challenge(challenge: str, token: Optional[str]) -> bool:


def resolve_canonical_challenge_name(name: str) -> str:
resolver = dns.resolver.get_default_resolver() # type: ignore[attr-defined]
resolver = get_default_resolver()
current_name = name
visited = [current_name]

while True:
try:
answer = resolver.resolve(
current_name, rdtype=dns.rdatatype.RdataType.CNAME
current_name, rdtype=RdataType.CNAME
)
current_name = str(answer[0].target)
if current_name in visited:
Expand All @@ -106,6 +107,6 @@ def resolve_canonical_challenge_name(name: str) -> str:
f"{resolution_map}"
)
visited.append(current_name)
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
except (NXDOMAIN, NoAnswer):
# No more CNAME in the chain, we have the final canonical_name
return current_name

0 comments on commit da7c407

Please sign in to comment.