// Note on Except: The set difference of two sets is defined as the members of the first set that do not appear in the second set. // In other words, this will return all member objects in this object that are not found in target public List <FirewallObject> GetDelta(AddressGroupObject target) { if (DeepCompare(target)) { return(null); } return(MemberObjects.Except(target.MemberObjects).ToList()); }
// Could this be moved-up to parent? public bool DeepCompare(AddressGroupObject target) { if ((MemberObjects.Count != Members.Count) || (target.MemberObjects.Count != target.Members.Count)) { throw new ArgumentException("Attempt to call DeepCompare method on an object prior to inflating the membership"); } return(this.Equals(target) && this.MemberObjects.OrderBy(a => a.Name).SequenceEqual(target.MemberObjects.OrderBy(a => a.Name))); }
private void UpdateAddresses(AddressGroupObject adView, AddressGroupObject fwView) { var addressObjectsDetla = adView.GetDelta(fwView); if (addressObjectsDetla.Count > 0) { WriteVerbose("Address configuration drifted:"); foreach (var address in addressObjectsDetla) { addableRepository.Add(address); WriteVerbose($"Updating {address.Name}"); } } }
private void InflateAddressGroupMembers(AddressGroupObject fwView) { // Firewall Group may not exist if (fwView != null) { membershipRepository.InflateMembers <AddressObject, GetAllAddressesApiResponse>( addressSearchableRepository, fwView, ConfigTypes.Running); } else { WriteVerbose( $"Unable to find an Address Group by the name of {AddressGroupName}, new group will be created"); } }
private void UpdateGroup(AddressGroupObject adView, AddressGroupObject fwView) { // This is a shallow equal compare. // Only checking if member lists (strings) are the same, but this is sufficient for this stage, since we already compared/reconciled the underlying AddressObjects if (adView.Equals(fwView)) { // Nothing to do - groups are the same return; } if (fwView != null) { // Group already exist using Edit API membershipRepository.SetGroupMembership(adView); WriteVerbose($"Updating {AddressGroupName}"); } else { // Creating group brand new using Set API addableRepository.Add(adView); WriteVerbose($"Setting {AddressGroupName}"); } }