Skip to content

Commit

Permalink
Fallback resolver (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazet authored Jul 9, 2024
1 parent e5540d3 commit 1ea74a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app/src/resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dns.resolver

from common.config import Config

from .logging import build_logger


Expand All @@ -12,8 +14,12 @@ def resolve(self, *args, **kwargs): # type: ignore
last_exception = None
num_exceptions = 0

for _ in range(self.num_retries):
for i in range(self.num_retries):
try:
if i < self.num_retries - 1:
self.nameservers = Config.Network.NAMESERVERS
else:
self.nameservers = Config.Network.FALLBACK_NAMESERVERS
result = super().resolve(*args, **kwargs)
break
except Exception as e:
Expand Down
10 changes: 6 additions & 4 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ class Network:
APP_DOMAIN: Annotated[str, "The domain the site is running on."] = get_config("APP_DOMAIN")
NAMESERVERS: Annotated[
List[str],
"A comma-separated list of nameservers that will be used to resolve domains. If you want "
"to provide custom ones, remember to modify the ones provided to the Docker containers as well. "
"At CERT PL we use a separate ``docker-compose.yml`` file with additional configuration specific "
"to our instance.",
"A comma-separated list of nameservers that will be used to resolve domains.",
] = get_config("NAMESERVERS", default=gethostbyname("bind9"), cast=decouple.Csv(str))
FALLBACK_NAMESERVERS: Annotated[
List[str],
"A comma-separated list of nameservers that will be used to resolve domains if NAMESERVERS fail. This can "
"be used e.g. to use recursive nameservers as NAMESERVERS and nameservers such as e.g. 8.8.8.8 as FALLBACK_NAMESERVERS.",
] = get_config("FALLBACK_NAMESERVERS", default="8.8.8.8", cast=decouple.Csv(str))
SSL_PRIVATE_KEY_PATH: Annotated[
str,
"SSL private key path. Please refer to ``SSL_CERTIFICATE_PATH`` variable documentation to "
Expand Down

0 comments on commit 1ea74a0

Please sign in to comment.