public override async Task PersistsChallenge(DnsChallenge dnsChallenge) { List <TxtRecord> records = new List <TxtRecord>() { new TxtRecord() { Value = new[] { dnsChallenge.RecordValue } } }; var dnsClient = await ArmHelper.GetDnsManagementClient(this.environment); if ((await dnsClient.RecordSets.ListByTypeAsync(environment.ResourceGroupName, environment.ZoneName, RecordType.TXT)).Any()) { var existingRecords = await SafeGetExistingRecords(dnsChallenge); if (existingRecords != null) { if (existingRecords.TxtRecords.Any(s => s.Value.Contains(dnsChallenge.RecordValue))) { records = existingRecords.TxtRecords.ToList(); } else { records.AddRange(existingRecords.TxtRecords); } } } await dnsClient.RecordSets.CreateOrUpdateAsync(this.environment.ResourceGroupName, this.environment.ZoneName, GetRelativeRecordSetName(dnsChallenge), RecordType.TXT, new RecordSet() { TxtRecords = records, TTL = 60 }); }
public override async Task CleanupChallenge(DnsChallenge dnsChallenge) { var existingRecords = await SafeGetExistingRecords(dnsChallenge); var dnsClient = await ArmHelper.GetDnsManagementClient(this.environment); await dnsClient.RecordSets.DeleteAsync(this.environment.ResourceGroupName, this.environment.ZoneName, GetRelativeRecordSetName(dnsChallenge), RecordType.TXT); }
private async Task <RecordSet> SafeGetExistingRecords(DnsChallenge dnsChallenge) { try { var dnsClient = await ArmHelper.GetDnsManagementClient(this.environment); return(await dnsClient.RecordSets.GetAsync(environment.ResourceGroupName, environment.ZoneName, GetRelativeRecordSetName(dnsChallenge), RecordType.TXT)); } catch (CloudException cex) { if (!cex.Message.StartsWith("The resource record '_acme-challenge")) { throw; } } return(null); }
public AzureDnsAuthorizationChallengeProvider(IAzureDnsEnvironment azureDnsSettings) { this.dnsClient = ArmHelper.GetDnsManagementClient(azureDnsSettings); this.environment = azureDnsSettings; }