Skip to content

Commit

Permalink
Fixed verification using Google Cloud DNS was not working properly (#187
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shibayan authored Nov 10, 2020
1 parent c23ed9c commit b0c5f3e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
4 changes: 2 additions & 2 deletions KeyVault.Acmebot/KeyVault.Acmebot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<PackageReference Include="Azure.Security.KeyVault.Keys" Version="4.1.0" />
<PackageReference Include="DnsClient" Version="1.3.2" />
<PackageReference Include="DurableTask.TypedProxy" Version="2.1.0" />
<PackageReference Include="Google.Apis.Dns.v1" Version="1.49.0.2112" />
<PackageReference Include="Google.Apis.Dns.v1" Version="1.49.0.2120" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Dns" Version="3.0.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.3.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.9" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.10" />
<PackageReference Include="WebJobs.Extensions.HttpApi" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
Expand Down
13 changes: 6 additions & 7 deletions KeyVault.Acmebot/Providers/GoogleDnsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,31 @@ public GoogleDnsProvider(GoogleDnsOptions options)
private readonly DnsService _dnsService;
private readonly JsonCredentialParameters _credsParameters;

public int PropagationSeconds => 10;
public int PropagationSeconds => 60;

public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
{
var zones = await _dnsService.ManagedZones.List(_credsParameters.ProjectId).ExecuteAsync();

return zones.ManagedZones
.Select(managedZone => new DnsZone { Id = managedZone.Id.ToString(), Name = managedZone.DnsName.Remove(managedZone.DnsName.Length - 1) })
.Select(x => new DnsZone { Id = x.Name, Name = x.DnsName.TrimEnd('.') })
.ToArray();
}

public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
{
var recordName = $"{relativeRecordName}.{zone.Name}";
var recordName = $"{relativeRecordName}.{zone.Name}.";

var change = new Change
{
Additions = new[]
{
new ResourceRecordSet
{
Kind = "dns#resourceRecordSet",
Name = recordName,
Type = "TXT",
Ttl = 60,
Rrdatas = values.ToArray(),
Name = recordName
Rrdatas = values.ToArray()
}
}
};
Expand All @@ -64,7 +63,7 @@ public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName,

public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
{
var recordName = $"{relativeRecordName}.{zone.Name}";
var recordName = $"{relativeRecordName}.{zone.Name}.";

var request = _dnsService.ResourceRecordSets.List(_credsParameters.ProjectId, zone.Id);

Expand Down
32 changes: 15 additions & 17 deletions KeyVault.Acmebot/Providers/TransIpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,24 @@ public TransIpProvider(AcmebotOptions acmeOptions, TransIpOptions options, IAzur

public int PropagationSeconds => 360;

public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
{
var records = values.Select(value => new DnsEntry
{
Name = relativeRecordName,
Type = "TXT",
Expire = 60,
Content = value
});
var zones = await _transIpClient.ListZonesAsync();

foreach (var record in records)
return zones.Select(x => new DnsZone { Id = x.Name, Name = x.Name }).ToArray();
}

public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
{
foreach (var value in values)
{
await _transIpClient.AddRecordAsync(zone.Name, record);
await _transIpClient.AddRecordAsync(zone.Name, new DnsEntry
{
Name = relativeRecordName,
Type = "TXT",
Expire = 60,
Content = value
});
}
}

Expand All @@ -66,13 +71,6 @@ public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
}
}

public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
{
var zones = await _transIpClient.ListZonesAsync();

return zones.Select(d => new DnsZone { Id = d.Name, Name = d.Name }).ToArray();
}

private class TransIpClient
{
public TransIpClient(string customerName, CryptographyClient cryptoClient)
Expand Down

0 comments on commit b0c5f3e

Please sign in to comment.