Skip to content

Commit

Permalink
Improved DNS Provider implementation (#388)
Browse files Browse the repository at this point in the history
* Fixed gandi option typo

* Fixed resharper xml documment warning

* Remove unnecessary async/await

* Adjust DNS provider name to standard
  • Loading branch information
shibayan authored Oct 28, 2021
1 parent 7f98608 commit 5b63060
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion KeyVault.Acmebot/Options/AcmebotOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AcmebotOptions

public DnsMadeEasyOptions DnsMadeEasy { get; set; }

public GandDnsOptions Gandi { get; set; }
public GandiOptions Gandi { get; set; }

public GoDaddyOptions GoDaddy { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace KeyVault.Acmebot.Options
{
public class GandDnsOptions
public class GandiOptions
{
public string ApiKey { get; set; }
}
Expand Down
8 changes: 4 additions & 4 deletions KeyVault.Acmebot/Providers/AzureDnsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
return zones;
}

public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
public Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
{
var resourceGroup = ExtractResourceGroup(zone.Id);

Expand All @@ -56,14 +56,14 @@ public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName,
recordSet.TxtRecords.Add(new TxtRecord { Value = { value } });
}

await _dnsManagementClient.RecordSets.CreateOrUpdateAsync(resourceGroup, zone.Name, relativeRecordName, RecordType.TXT, recordSet);
return _dnsManagementClient.RecordSets.CreateOrUpdateAsync(resourceGroup, zone.Name, relativeRecordName, RecordType.TXT, recordSet);
}

public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
public Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
{
var resourceGroup = ExtractResourceGroup(zone.Id);

await _dnsManagementClient.RecordSets.DeleteAsync(resourceGroup, zone.Name, relativeRecordName, RecordType.TXT);
return _dnsManagementClient.RecordSets.DeleteAsync(resourceGroup, zone.Name, relativeRecordName, RecordType.TXT);
}

private static string ExtractResourceGroup(string resourceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,40 @@

namespace KeyVault.Acmebot.Providers
{
public class GandiDnsProvider : IDnsProvider
public class GandiProvider : IDnsProvider
{
public GandiDnsProvider(GandDnsOptions options)
public GandiProvider(GandiOptions options)
{
_client = new GandiDnsClient(options.ApiKey);
_client = new GandiClient(options.ApiKey);
}

private readonly GandiDnsClient _client;
private readonly GandiClient _client;

public int PropagationSeconds => 300;

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

/**
* Do NOT include the PrimaryNameServer element from the DnsZone list for now,
* the return value from Gandi when returning zones is not the expected value when doing the intersect at the Dns01Precondition method
**/
// Do NOT include the PrimaryNameServer element from the DnsZone list for now,
// the return value from Gandi when returning zones is not the expected value when doing the intersect at the Dns01Precondition method

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

public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
public Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
{
await _client.AddRecordAsync(zone.Name, relativeRecordName, values);
return _client.AddRecordAsync(zone.Name, relativeRecordName, values);
}

public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
public Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
{
await _client.DeleteRecordAsync(zone.Name, relativeRecordName);
return _client.DeleteRecordAsync(zone.Name, relativeRecordName);
}

private class GandiDnsClient
private class GandiClient
{
public GandiDnsClient(string apiKey)
public GandiClient(string apiKey)
{
if (apiKey is null)
{
Expand Down
8 changes: 4 additions & 4 deletions KeyVault.Acmebot/Providers/GoDaddyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
return zones.Select(x => new DnsZone { Id = x.DomainId, Name = x.Domain, NameServers = x.NameServers }).ToArray();
}

public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
public Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName, IEnumerable<string> values)
{
var entries = new List<DnsEntry>();

Expand All @@ -46,12 +46,12 @@ public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName,
});
}

await _client.AddRecordAsync(zone.Name, entries);
return _client.AddRecordAsync(zone.Name, entries);
}

public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
public Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
{
await _client.DeleteRecordAsync(zone.Name, "TXT", relativeRecordName);
return _client.DeleteRecordAsync(zone.Name, "TXT", relativeRecordName);
}

private class GoDaddyClient
Expand Down
4 changes: 2 additions & 2 deletions KeyVault.Acmebot/Providers/GoogleDnsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
.ToArray();
}

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

Expand All @@ -58,7 +58,7 @@ public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName,
}
};

await _dnsService.Changes.Create(change, _credsParameters.ProjectId, zone.Id).ExecuteAsync();
return _dnsService.Changes.Create(change, _credsParameters.ProjectId, zone.Id).ExecuteAsync();
}

public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
Expand Down
4 changes: 2 additions & 2 deletions KeyVault.Acmebot/Providers/Route53Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<IReadOnlyList<DnsZone>> ListZonesAsync()
return zones.HostedZones.Select(x => new DnsZone { Id = x.Id, Name = x.Name.TrimEnd('.') }).ToArray();
}

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

Expand All @@ -49,7 +49,7 @@ public async Task CreateTxtRecordAsync(DnsZone zone, string relativeRecordName,

var request = new ChangeResourceRecordSetsRequest(zone.Id, new ChangeBatch(new List<Change> { change }));

await _amazonRoute53Client.ChangeResourceRecordSetsAsync(request);
return _amazonRoute53Client.ChangeResourceRecordSetsAsync(request);
}

public async Task DeleteTxtRecordAsync(DnsZone zone, string relativeRecordName)
Expand Down
2 changes: 1 addition & 1 deletion KeyVault.Acmebot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void Configure(IFunctionsHostBuilder builder)

if (options.Gandi != null)
{
return new GandiDnsProvider(options.Gandi);
return new GandiProvider(options.Gandi);
}

if (options.GoDaddy != null)
Expand Down

0 comments on commit 5b63060

Please sign in to comment.