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

Proposal: support for certificates for domains with zones in different Azure resource groups #4

Open
wants to merge 2 commits 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
24 changes: 19 additions & 5 deletions certbot_azure/dns_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from azure.mgmt.dns.models import RecordSet, TxtRecord
from msrestazure.azure_exceptions import CloudError


from certbot import errors
from certbot import interfaces
from certbot.plugins import dns_common
Expand Down Expand Up @@ -118,9 +117,11 @@ def add_txt_record(self, domain, record_content, record_ttl):
record = RecordSet(ttl=record_ttl,
txt_records=[TxtRecord(value=[record_content])])
zone = self._find_managed_zone(domain)
relative_record_name = ".".join(
domain.split('.')[0:-len(zone.split('.'))])
self.dns_client.record_sets.create_or_update(self.resource_group,
relative_record_name = ".".join(domain.split('.')[0:-len(zone.split('.'))])

resource_group = self._choose_group_for_zone(zone, self.resource_group)

self.dns_client.record_sets.create_or_update(resource_group,
zone,
relative_record_name,
'TXT',
Expand All @@ -141,13 +142,26 @@ def del_txt_record(self, domain):
zone = self._find_managed_zone(domain)
relative_record_name = ".".join(
domain.split('.')[0:-len(zone.split('.'))])
self.dns_client.record_sets.delete(self.resource_group,

resource_group = self._choose_group_for_zone(zone, self.resource_group)

self.dns_client.record_sets.delete(resource_group,
zone,
relative_record_name,
'TXT')
except (CloudError, errors.PluginError) as e:
logger.warning('Encountered error deleting TXT record: %s', e)

def _choose_group_for_zone(self, zone, comma_separated_resource_groups):
resource_groups = map(lambda group: group.strip(), comma_separated_resource_groups.split(","))

for resource_group in resource_groups:
for zone_in_group in self.dns_client.zones.list_by_resource_group(resource_group):
if zone_in_group.name == zone:
return resource_group

raise errors.PluginError('Error finding {0} zone in provided resource groups'.format(zone))

def _find_managed_zone(self, domain):
"""
Find the managed zone for a given domain.
Expand Down