updated listing domains

alphons <alphons@heijden.com> 17 Dec 2025, 14:27
e8c5bd3fc2eec970f63f9c8a6759bb5729fce7a1
4 files changed
  • MijnHost/DnsApiClient.cs
  • MijnHost/MijnHost.csproj
  • MijnHost/Program.cs
  • MijnHost/Properties/launchSettings.json
diff --git a/MijnHost/DnsApiClient.cs b/MijnHost/DnsApiClient.cs
index 74f62af..84c2102 100644
--- a/MijnHost/DnsApiClient.cs
+++ b/MijnHost/DnsApiClient.cs
@@ -31,7 +31,26 @@ public class DnsApiClient : IDisposable
userAgent ?? "my-application/1.0.0");
}
- public async Task<DnsGetResponse> GetDomainRecordsAsync(
+ public async Task<DnsResponse<DnsDomains>> GetDomainsAsync(CancellationToken ct = default)
+ {
+ var response = await httpClient
+ .GetAsync("domains/", ct)
+ .ConfigureAwait(false);
+
+ var json = await response.Content.ReadAsStringAsync(ct);
+
+ if (!response.IsSuccessStatusCode)
+ {
+ var error = JsonSerializer.Deserialize<DnsApiErrorResponse>(json, JsonOptions)
+ ?? new DnsApiErrorResponse(-1, "Unknown error");
+
+ throw new DnsApiException(response.StatusCode, error.Status, error.StatusDescription, json);
+ }
+
+ return JsonSerializer.Deserialize<DnsResponse<DnsDomains>>(json, JsonOptions)!;
+ }
+
+ public async Task<DnsResponse<DnsRecords>> GetDomainRecordsAsync(
string domain,
CancellationToken ct = default)
{
@@ -49,7 +68,7 @@ public class DnsApiClient : IDisposable
throw new DnsApiException(response.StatusCode, error.Status, error.StatusDescription, json);
}
- return JsonSerializer.Deserialize<DnsGetResponse>(json, JsonOptions)!;
+ return JsonSerializer.Deserialize<DnsResponse<DnsRecords>>(json, JsonOptions)!;
}
public async Task<DnsApiResponse> UpdateDomainRecordsAsync(
@@ -118,12 +137,24 @@ public record DnsRecord(
string Value,
int Ttl = 900);
-public record DnsGetResponse(
+public record DnsResponse<T>(
int Status,
string StatusDescription,
- DnsGetData Data);
+ T Data);
+
+
+public record DnsDomains(
+ List<DnsDomain> Domains);
+
+public record DnsDomain(
+ int Id,
+ string Domain,
+ string Renewal_Date,
+ string Status,
+ int Status_Id,
+ List<string> Tags);
-public record DnsGetData(
+public record DnsRecords(
string Domain,
List<DnsRecord> Records);
diff --git a/MijnHost/MijnHost.csproj b/MijnHost/MijnHost.csproj
index a3ca575..db0b104 100644
--- a/MijnHost/MijnHost.csproj
+++ b/MijnHost/MijnHost.csproj
@@ -16,6 +16,9 @@
<None Update="appsettings-example.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Update="appsettings.json">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
</ItemGroup>
</Project>
diff --git a/MijnHost/Program.cs b/MijnHost/Program.cs
index 53c2af1..c3112f9 100644
--- a/MijnHost/Program.cs
+++ b/MijnHost/Program.cs
@@ -2,16 +2,17 @@
using MijnHost;
-if(args.Length < 2)
+if(args.Length < 1)
{
- Console.WriteLine("Usage: example.com 12345");
+ Console.WriteLine("Usage:");
+ Console.WriteLine("\t--list");
+ Console.WriteLine("\t--records example.com");
+ Console.WriteLine("\t--challenge example.com 12345");
Environment.Exit(1);
}
try
{
- var domain = args[0];
- var value = args[1];
var config = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
@@ -24,9 +25,33 @@ try
using var client = new DnsApiClient(apiKey, userAgent);
- DnsApiResponse result = await client.PatchDnsRecordAsync(domain, new DnsRecord($"_acme-challenge", "TXT", value, 60));
-
- Console.WriteLine($"Success: {result.Status} - {result.StatusDescription}");
+ switch (args[0])
+ {
+ case "--list":
+ DnsResponse<DnsDomains> dnsResponse = await client.GetDomainsAsync();
+ foreach(DnsDomain dom in dnsResponse.Data.Domains)
+ {
+ Console.WriteLine($"{dom.Domain}");
+ }
+ break;
+ case "--records":
+ DnsResponse<DnsRecords> dnsRecords = await client.GetDomainRecordsAsync(args[1]);
+ Console.WriteLine($"Records for domain: {dnsRecords.Data.Domain}");
+ foreach(DnsRecord record in dnsRecords.Data.Records)
+ {
+ Console.WriteLine($"{record.Name}\t\t{record.Ttl}\t{record.Type}\t\t{record.Value}");
+ }
+ break;
+ case "--challenge":
+ string domain = args[1];
+ string value = args[2];
+ var result = await client.PatchDnsRecordAsync(domain, new DnsRecord($"_acme-challenge", "TXT", value, 60));
+ Console.WriteLine($"Success: {result.Status} - {result.StatusDescription}");
+ break;
+ default:
+ Console.WriteLine("Onbekende opdracht.");
+ break;
+ }
}
catch (DnsApiException ex)
{
diff --git a/MijnHost/Properties/launchSettings.json b/MijnHost/Properties/launchSettings.json
index 9f12c30..45f28ed 100644
--- a/MijnHost/Properties/launchSettings.json
+++ b/MijnHost/Properties/launchSettings.json
@@ -2,7 +2,7 @@
"profiles": {
"MijnHost": {
"commandName": "Project",
- "commandLineArgs": "duofun.nl 123456"
+ "commandLineArgs": "--records lingerieke.nl"
}
}
}
\ No newline at end of file