Skip to content

Commit

Permalink
added support for multilevel domains closes #69;
Browse files Browse the repository at this point in the history
removed incorrect ttl warning notice
  • Loading branch information
infinityofspace committed Sep 25, 2024
1 parent 207603a commit 8937848
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
36 changes: 17 additions & 19 deletions certbot_dns_porkbun/cert/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from certbot.plugins import dns_common
from dns import resolver
from pkb_client.client import PKBClient
from tldextract import tldextract

DEFAULT_PROPAGATION_SECONDS = 60

Expand Down Expand Up @@ -80,37 +81,34 @@ def _perform(self, domain: str, validation_name: str, validation: str) -> None:
:raise PluginError: if the TXT record can not be set or something goes wrong
"""

client = self._get_porkbun_client()

propagation_seconds = self.conf("propagation_seconds")
if propagation_seconds < 600:
logging.warning("The propagation time is less than Porkbun DNS TTL minimum of 600 seconds. Subsequent "
"challenges for same domain may fail. Try increasing the propagation time if you encounter "
"issues.")

# replace wildcard in domain
domain = domain.replace("*", "")
domain = f"{ACME_TXT_PREFIX}.{domain}"

propagation_seconds = self.conf("propagation_seconds")

try:
# follow all CNAME and DNAME records
canonical_name = resolver.canonical_name(domain)

if domain != canonical_name.to_text().rstrip('.') and propagation_seconds < 600:
logging.warning("Make sure your CNAME record is propagated to all DNS servers, "
"because the default CNAME TTL propagation time is 600 seconds "
f"and your certbot propagation time is only {propagation_seconds}.")

self._root_domain = canonical_name.split(3)[1].to_text().rstrip('.')

name = ".".join(canonical_name.to_text().split('.')[:-3])
except (resolver.NoAnswer, resolver.NXDOMAIN):
canonical_name = domain

self._root_domain = ".".join(canonical_name.split('.')[-2:])

name = ".".join(canonical_name.split('.')[:-2])
extract_result = tldextract.extract(canonical_name.to_text())
root_domain = f"{extract_result.domain}.{extract_result.suffix}"
name = extract_result.subdomain

try:
self.record_ids_to_root_domain[validation] = (self._get_porkbun_client().dns_create(self._root_domain,
"TXT",
validation,
name=name),
self._root_domain)
self.record_ids_to_root_domain[validation] = (client.dns_create(root_domain,
"TXT",
validation,
name=name),
root_domain)

except Exception as e:
raise errors.PluginError(e)
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
setuptools>=41.6.0
certbot>=1.18.0,<4.0
pkb_client>=1.1,<2.0
dnspython>=2.0.0,<3.0
dnspython>=2.0.0,<3.0
tldextract>=5.1.2,<6.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"setuptools>=41.6.0",
"certbot>=1.18.0,<4.0",
"pkb_client>=1.1,<2.0",
"dnspython>=2.0.0,<3.0"
"dnspython>=2.0.0,<3.0",
"tldextract>=5.1.2,<6.0"
],
entry_points={
"certbot.plugins": [
Expand Down

0 comments on commit 8937848

Please sign in to comment.