Skip to content

Commit 468e900

Browse files
fixed delete logic
1 parent 790018b commit 468e900

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

AcmeCaPlugin/Clients/DNS/InfobloxDnsProvider.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,28 @@ public async Task<bool> CreateRecordAsync(string recordName, string txtValue)
5151
{
5252
var cleanName = recordName.TrimEnd('.');
5353

54-
// Check if record already exists with the same value
55-
var searchUrl = $"record:txt?name={Uri.EscapeDataString(cleanName)}&text={Uri.EscapeDataString(txtValue)}";
54+
// Delete any existing records with the same name first to ensure only one record exists
55+
var searchUrl = $"record:txt?name={Uri.EscapeDataString(cleanName)}";
5656
var searchResponse = await _httpClient.GetAsync(searchUrl);
5757

5858
if (searchResponse.IsSuccessStatusCode)
5959
{
6060
var searchJson = await searchResponse.Content.ReadAsStringAsync();
6161
var records = JsonDocument.Parse(searchJson).RootElement;
6262

63-
if (records.GetArrayLength() > 0)
63+
// Delete all existing records with this name
64+
foreach (var record in records.EnumerateArray())
6465
{
65-
Console.WriteLine($"[Infoblox] TXT record already exists for {cleanName} with value {txtValue}. Skipping creation.");
66-
return true; // Record already exists, no need to create duplicate
66+
var recordRef = record.GetProperty("_ref").GetString();
67+
if (!string.IsNullOrEmpty(recordRef))
68+
{
69+
var deleteResponse = await _httpClient.DeleteAsync(recordRef);
70+
Console.WriteLine($"[Infoblox] Deleted existing TXT record {recordRef}: {deleteResponse.StatusCode}");
71+
}
6772
}
6873
}
6974

70-
// Create new record if it doesn't exist
75+
// Create new record
7176
var payload = new
7277
{
7378
name = cleanName,

0 commit comments

Comments
 (0)