Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback resolver #88

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading