@@ -53,9 +53,9 @@ def add_txt_record(self, domain: str, validation_name: str, validation: str):
5353 """
5454 Add a TXT record using the supplied information.
5555
56- :param domain: The zone dnsName .
57- :param validation_name: The record name.
58- :param validation: The record content.
56+ :param domain: The domain one level above the validation name .
57+ :param validation_name: The acme challenge record name.
58+ :param validation: The acme challenge record content.
5959 """
6060 zone_id = self ._get_zone_id (domain )
6161 rrset = self ._get_rrset (zone_id , validation_name )
@@ -137,16 +137,23 @@ def _get_zone_id(self, domain: str) -> str:
137137 :param domain: The domain (zone dnsName) for which the zone ID is needed.
138138 :return: The ID of the zone.
139139 """
140- res = requests .get (
141- f"{ self .base_url } /v1/projects/{ self .project_id } /zones?dnsName[eq]={ domain } &active[eq]=true" ,
142- headers = self .headers ,
143- )
144- if res .status_code != 200 or len (res .json ()["zones" ]) == 0 :
145- raise errors .PluginError (
146- f"Could not find zone id for domain { domain } , Response: { res .text } "
140+ parts = domain .split ('.' )
141+
142+ # we are searching for the best matching zone. We can do that by iterating over the parts of the domain
143+ # from left to right.
144+ for i in range (len (parts )):
145+ subdomain = '.' .join (parts [i :])
146+ res = requests .get (
147+ f"{ self .base_url } /v1/projects/{ self .project_id } /zones?dnsName[eq]={ subdomain } &active[eq]=true" ,
148+ headers = self .headers ,
147149 )
148150
149- return res .json ()["zones" ][0 ]["id" ]
151+ if res .status_code == 200 and len (res .json ()["zones" ]) > 0 :
152+ return res .json ()["zones" ][0 ]["id" ]
153+
154+ raise errors .PluginError (
155+ f"Could not find zone id for domain { domain } , Response: { res .text } "
156+ )
150157
151158 def _get_rrset (self , zone_id : str , validation_name : str ) -> Optional [RRSet ]:
152159 """
@@ -256,7 +263,7 @@ def _perform(self, domain: str, validation_name: str, validation: str):
256263 """
257264 Carry out a DNS update.
258265
259- :param domain: The domain where the DNS record will be added.
266+ :param domain: The domain where the DNS record will be added. Does not need to be the zone dns name but any domain.
260267 :param validation_name: The name of the DNS record.
261268 :param validation: The validation content to be added to the DNS record.
262269 """
0 commit comments