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

Added handling for 3rd level domains #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions certbot_dns_godaddy/dns_godaddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,31 @@ def _setup_credentials(self):
)

def _perform(self, domain, validation_name, validation):
self._get_client().add_record(domain, {
second_level_domain = self._get_second_level_domain(domain)
self._get_client().add_record(second_level_domain, {
'type': 'TXT',
'name': self._unsuffix(validation_name, f'.{domain}'),
'name': self._unsuffix(validation_name, f'.{second_level_domain}'),
'data': validation,
'ttl': self.ttl
})

def _cleanup(self, domain, validation_name, validation):
self._get_client().delete_records(domain, self._unsuffix(validation_name, f'.{domain}'), record_type='TXT')
second_level_domain = self._get_second_level_domain(domain)
self._get_client().delete_records(second_level_domain, self._unsuffix(validation_name, f'.{second_level_domain}'), record_type='TXT')

def _get_client(self) -> Client:
if not self._client:
account = Account(api_key=self.credentials.conf('key'), api_secret=self.credentials.conf('secret'))
self._client = Client(account)
return self._client

def _get_second_level_domain(self, domain):
"""
In case of a certificate for subdomain (a.b.com), GoDaddy would not find it - we have to change 2nd level domain (b.com)
This method returns only 2 top levels of given domain for godadddypy to work on.
"""
return '.'.join(domain.split('.')[-2:])

def _unsuffix(self, record: str, suffix: str):
""" GoDaddy wants to have only the first part of the domain record (so for a.b.com, for domain b.com,
only 'a'. """
Expand Down