Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor to attempt reconciliation code re-use between Azure & AWS integrations #47427

Merged
merged 8 commits into from
Oct 15, 2024
40 changes: 20 additions & 20 deletions lib/srv/discovery/fetchers/aws-sync/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ func MergeResources(results ...*Resources) *Resources {
}

func deduplicateResources(result *Resources) {
result.Users = deduplicateSlice(result.Users, usersUniqueKeyFunc)
result.UserInlinePolicies = deduplicateSlice(result.UserInlinePolicies, usersInlinePolicyUniqueKeyFunc)
result.UserAttachedPolicies = deduplicateSlice(result.UserAttachedPolicies, usersAttachedPoliciesUniqueKeyFunc)
result.UserGroups = deduplicateSlice(result.UserGroups, userGroupUniqueKeyFunc)
result.Groups = deduplicateSlice(result.Groups, groupUniqueKeyFunc)
result.GroupInlinePolicies = deduplicateSlice(result.GroupInlinePolicies, groupInlinePolicyUniqueKeyFunc)
result.GroupAttachedPolicies = deduplicateSlice(result.GroupAttachedPolicies, groupAttachedPolicyUniqueKeyFunc)
result.Instances = deduplicateSlice(result.Instances, instancesUniqueKeyFunc)
result.Policies = deduplicateSlice(result.Policies, policyUniqueKeyFunc)
result.S3Buckets = deduplicateSlice(result.S3Buckets, s3UniqueKeyFunc)
result.Roles = deduplicateSlice(result.Roles, roleUniqueKeyFunc)
result.RoleInlinePolicies = deduplicateSlice(result.RoleInlinePolicies, roleInlinePolicyUniqueKeyFunc)
result.RoleAttachedPolicies = deduplicateSlice(result.RoleAttachedPolicies, roleAttachedPoliciesUniqueKeyFunc)
result.InstanceProfiles = deduplicateSlice(result.InstanceProfiles, instanceProfileUniqueKeyFunc)
result.AssociatedAccessPolicies = deduplicateSlice(result.AssociatedAccessPolicies, associatedAccessPolicyUniqueKeyFunc)
result.EKSClusters = deduplicateSlice(result.EKSClusters, eksClusterUniqueKeyFunc)
result.AccessEntries = deduplicateSlice(result.AccessEntries, accessEntryUniqueKeyFunc)
result.RDSDatabases = deduplicateSlice(result.RDSDatabases, rdsUniqueKeyFunc)
result.SAMLProviders = deduplicateSlice(result.SAMLProviders, samlUniqueKeyFunc)
result.OIDCProviders = deduplicateSlice(result.OIDCProviders, oidcUniqueKeyFunc)
result.Users = deduplicateSlice(result.Users, usersKey)
result.UserInlinePolicies = deduplicateSlice(result.UserInlinePolicies, userInlinePolKey)
result.UserAttachedPolicies = deduplicateSlice(result.UserAttachedPolicies, userAttchPolKey)
result.UserGroups = deduplicateSlice(result.UserGroups, userGroupKey)
result.Groups = deduplicateSlice(result.Groups, groupKey)
result.GroupInlinePolicies = deduplicateSlice(result.GroupInlinePolicies, grpInlinePolKey)
result.GroupAttachedPolicies = deduplicateSlice(result.GroupAttachedPolicies, grpAttchPolKey)
result.Instances = deduplicateSlice(result.Instances, instanceKey)
result.Policies = deduplicateSlice(result.Policies, policyKey)
result.S3Buckets = deduplicateSlice(result.S3Buckets, s3bucketKey)
result.Roles = deduplicateSlice(result.Roles, roleKey)
result.RoleInlinePolicies = deduplicateSlice(result.RoleInlinePolicies, roleInlinePolKey)
result.RoleAttachedPolicies = deduplicateSlice(result.RoleAttachedPolicies, roleAttchPolKey)
result.InstanceProfiles = deduplicateSlice(result.InstanceProfiles, instanceProfKey)
result.AssociatedAccessPolicies = deduplicateSlice(result.AssociatedAccessPolicies, assocAccPolKey)
result.EKSClusters = deduplicateSlice(result.EKSClusters, eksClusterKey)
result.AccessEntries = deduplicateSlice(result.AccessEntries, accessEntryKey)
result.RDSDatabases = deduplicateSlice(result.RDSDatabases, rdsDbKey)
result.SAMLProviders = deduplicateSlice(result.SAMLProviders, samlProvKey)
result.OIDCProviders = deduplicateSlice(result.OIDCProviders, oidcProvKey)
}
6 changes: 3 additions & 3 deletions lib/srv/discovery/fetchers/aws-sync/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func TestMergeResources(t *testing.T) {

result := MergeResources(&oldResults, &newResults)
expected := Resources{
Users: deduplicateSlice(append(oldUsers, newUsers...), usersUniqueKeyFunc),
Roles: deduplicateSlice(append(oldRoles, newRoles...), roleUniqueKeyFunc),
Instances: deduplicateSlice(append(oldEC2, newEC2...), instancesUniqueKeyFunc),
Users: deduplicateSlice(append(oldUsers, newUsers...), usersKey),
Roles: deduplicateSlice(append(oldRoles, newRoles...), roleKey),
Instances: deduplicateSlice(append(oldEC2, newEC2...), instanceKey),
}
require.Empty(t, cmp.Diff(&expected, result, protocmp.Transform(), cmpopts.EquateEmpty()))
}
Expand Down
Loading
Loading