/// <summary> /// Upserts the given <paramref name="recordSet"/>. /// </summary> public static Task UpsertZoneRecordSetAsync(this IElementEndpoint <Zone> endpoint, RecordSet recordSet, CancellationToken cancellationToken = default) { recordSet.ChangeType = ChangeType.Replace; return(endpoint.PatchRecordSetAsync(recordSet, cancellationToken)); }
private static async Task UpdateRecord( AutoSpf.FlattenedInclude flattenedInclude, Config config, Zone zone, IElementEndpoint <Zone> zoneEndpoint ) { var name = flattenedInclude.DName.Replace(config.AutoSpfDomain, config.DestinationZone); var newValue = flattenedInclude.Value.Replace(config.AutoSpfDomain, config.DestinationZone); if (!newValue.EndsWith("\"")) { newValue += "\""; } if (!newValue.StartsWith("\"")) { newValue = "\"" + newValue; } var existingRecord = zone.RecordSets.FirstOrDefault(x => x.Name.Equals(name)); if (existingRecord != null) { var needsUpdate = existingRecord.Records.Count != 1 || existingRecord.Records[0].Content != newValue; if (needsUpdate) { Console.WriteLine($"Updating {name}"); Console.WriteLine($"{newValue}"); existingRecord.ChangeType = ChangeType.Replace; existingRecord.Records.Clear(); existingRecord.Records.Add(new Record(newValue)); await zoneEndpoint.PatchRecordSetAsync(existingRecord); Console.WriteLine("Done."); Console.WriteLine(); } else { Console.WriteLine($"{name} is already up-to-date"); } } else { Console.WriteLine($"Creating {name}"); Console.WriteLine($"{newValue}"); var record = new RecordSet { ChangeType = ChangeType.Replace, Name = name, Records = new List <Record> { new(newValue) },
public async Task PatchingRecordSetIdentifiesCorrectZoneName() { const string zoneName = "example.com."; var recordSet = new RecordSet("www.example.org", TimeSpan.FromSeconds(1)) { ChangeType = ChangeType.Replace }; var zone = new Zone(zoneName) { RecordSets = { recordSet } }; _endpointMock.SetupGet(x => x.Uri).Returns(new Uri($"http://localhost/api/v1/servers/localhost/zones/{zoneName}")); _endpointMock.Setup(x => x.MergeAsync(zone, CancellationToken.None)).ReturnsAsync(zone).Verifiable(); await _endpoint.PatchRecordSetAsync(recordSet); _endpointMock.Verify(); }