Skip to content

Commit 8d188fd

Browse files
authored
Command "services": Eliminate duplicate app names (#3663)
* in case of multiple service bindings per (service instance guid, app guid), eliminate duplicate app names in the "bound apps" section
1 parent afdc246 commit 8d188fd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

actor/v7action/service_instance_list.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ func buildPlanDetailsLookup(included ccv3.IncludedResources) map[string]planDeta
121121
}
122122

123123
func buildBoundAppsLookup(bindings []resources.ServiceCredentialBinding, spaceGUID string) map[string][]string {
124+
type bindingKey struct {
125+
appGUID string
126+
serviceInstanceGUID string
127+
}
128+
seenBindingKeys := make(map[bindingKey]struct{})
124129
appsBoundLookup := make(map[string][]string)
125130
for _, binding := range bindings {
126131
if binding.Type == resources.AppBinding && binding.AppSpaceGUID == spaceGUID {
127-
appsBoundLookup[binding.ServiceInstanceGUID] = append(appsBoundLookup[binding.ServiceInstanceGUID], binding.AppName)
132+
bk := bindingKey{appGUID: binding.AppGUID, serviceInstanceGUID: binding.ServiceInstanceGUID}
133+
// Prevent duplicate app names for the same service instance in case of duplicate bindings
134+
if _, exists := seenBindingKeys[bk]; !exists {
135+
appsBoundLookup[binding.ServiceInstanceGUID] = append(appsBoundLookup[binding.ServiceInstanceGUID], binding.AppName)
136+
seenBindingKeys[bk] = struct{}{}
137+
}
128138
}
129139
}
130140
return appsBoundLookup

actor/v7action/service_instance_list_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ var _ = Describe("Service Instance List Action", func() {
142142
)
143143
fakeCloudControllerClient.GetServiceCredentialBindingsReturns(
144144
[]resources.ServiceCredentialBinding{
145+
{Type: "app", ServiceInstanceGUID: "fake-guid-1", AppGUID: "app-1", AppName: "great-app-1", AppSpaceGUID: spaceGUID},
146+
// Duplicate binding for (app-1, fake-guid-1) pair to ensure app names are not duplicated
145147
{Type: "app", ServiceInstanceGUID: "fake-guid-1", AppGUID: "app-1", AppName: "great-app-1", AppSpaceGUID: spaceGUID},
146148
{Type: "app", ServiceInstanceGUID: "fake-guid-1", AppGUID: "app-2", AppName: "great-app-2", AppSpaceGUID: spaceGUID},
147149
{Type: "app", ServiceInstanceGUID: "fake-guid-2", AppGUID: "app-3", AppName: "great-app-3", AppSpaceGUID: spaceGUID},

0 commit comments

Comments
 (0)