Exemplo n.º 1
0
        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
            });
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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;
 }