Skip to content
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
31 changes: 19 additions & 12 deletions certbot_dns_stackit/stackit.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def add_txt_record(self, domain: str, validation_name: str, validation: str):
"""
Add a TXT record using the supplied information.

:param domain: The zone dnsName.
:param validation_name: The record name.
:param validation: The record content.
:param domain: The domain one level above the validation name.
:param validation_name: The acme challenge record name.
:param validation: The acme challenge record content.
"""
zone_id = self._get_zone_id(domain)
rrset = self._get_rrset(zone_id, validation_name)
Expand Down Expand Up @@ -137,16 +137,23 @@ def _get_zone_id(self, domain: str) -> str:
:param domain: The domain (zone dnsName) for which the zone ID is needed.
:return: The ID of the zone.
"""
res = requests.get(
f"{self.base_url}/v1/projects/{self.project_id}/zones?dnsName[eq]={domain}&active[eq]=true",
headers=self.headers,
)
if res.status_code != 200 or len(res.json()["zones"]) == 0:
raise errors.PluginError(
f"Could not find zone id for domain {domain}, Response: {res.text}"
parts = domain.split('.')

# we are searching for the best matching zone. We can do that by iterating over the parts of the domain
# from left to right.
for i in range(len(parts)):
subdomain = '.'.join(parts[i:])
res = requests.get(
f"{self.base_url}/v1/projects/{self.project_id}/zones?dnsName[eq]={subdomain}&active[eq]=true",
headers=self.headers,
)

return res.json()["zones"][0]["id"]
if res.status_code == 200 and len(res.json()["zones"]) > 0:
return res.json()["zones"][0]["id"]

raise errors.PluginError(
f"Could not find zone id for domain {domain}, Response: {res.text}"
)

def _get_rrset(self, zone_id: str, validation_name: str) -> Optional[RRSet]:
"""
Expand Down Expand Up @@ -256,7 +263,7 @@ def _perform(self, domain: str, validation_name: str, validation: str):
"""
Carry out a DNS update.

:param domain: The domain where the DNS record will be added.
:param domain: The domain where the DNS record will be added. Does not need to be the zone dns name but any domain.
:param validation_name: The name of the DNS record.
:param validation: The validation content to be added to the DNS record.
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import find_packages
import os

version = os.environ.get("PACKAGE_VERSION", "v0.1.0")
version = os.environ.get("PACKAGE_VERSION", "v0.1.1")

install_requires = [
"acme>=2.6.0",
Expand Down