Skip to content

Commit 4ba1b4f

Browse files
committed
refactor: move resolveRoutePolicyGUID to route_policy.go
The Get/UpdateRoutePolicyLabels wrappers in label.go follow the same convention as every other resource (GetRouteLabels, GetDomainLabels, etc.): the thin label wrapper stays in label.go and delegates GUID resolution to a helper in the resource's own file. Move the route-policy resolver alongside the other route-policy actor methods and drop the now-unused ccv3 import from label.go.
1 parent 6deeb07 commit 4ba1b4f

2 files changed

Lines changed: 35 additions & 37 deletions

File tree

actor/v7action/label.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package v7action
22

33
import (
44
"code.cloudfoundry.org/cli/v9/actor/actionerror"
5-
"code.cloudfoundry.org/cli/v9/api/cloudcontroller/ccv3"
65
"code.cloudfoundry.org/cli/v9/resources"
76
"code.cloudfoundry.org/cli/v9/types"
87
)
@@ -180,42 +179,6 @@ func (actor *Actor) updateResourceMetadata(resourceType string, resourceGUID str
180179
return warnings, nil
181180
}
182181

183-
// resolveRoutePolicyGUID finds the GUID of the route policy to operate on.
184-
// If source is non-empty, it finds the policy with that source.
185-
// If source is empty, it requires exactly one policy (returns ambiguity or not-found error).
186-
func (actor *Actor) resolveRoutePolicyGUID(routeURL, spaceGUID, source string) (string, *resources.Metadata, Warnings, error) {
187-
route, routeWarnings, err := actor.GetRoute(routeURL, spaceGUID)
188-
if err != nil {
189-
return "", nil, routeWarnings, err
190-
}
191-
192-
routePolicies, _, policyWarnings, err := actor.CloudControllerClient.GetRoutePolicies(
193-
ccv3.Query{Key: ccv3.RouteGUIDFilter, Values: []string{route.GUID}},
194-
)
195-
allWarnings := append(routeWarnings, Warnings(policyWarnings)...)
196-
if err != nil {
197-
return "", nil, allWarnings, err
198-
}
199-
200-
if source != "" {
201-
for _, p := range routePolicies {
202-
if p.Source == source {
203-
return p.GUID, p.Metadata, allWarnings, nil
204-
}
205-
}
206-
return "", nil, allWarnings, actionerror.RoutePolicyNotFoundError{Source: source}
207-
}
208-
209-
if len(routePolicies) == 0 {
210-
return "", nil, allWarnings, actionerror.RoutePolicyNotFoundError{Source: ""}
211-
}
212-
if len(routePolicies) > 1 {
213-
return "", nil, allWarnings, actionerror.RoutePolicyAmbiguityError{RouteURL: routeURL, Count: len(routePolicies)}
214-
}
215-
p := routePolicies[0]
216-
return p.GUID, p.Metadata, allWarnings, nil
217-
}
218-
219182
func (actor *Actor) GetRoutePolicyLabels(routeURL, spaceGUID, source string) (map[string]types.NullString, Warnings, error) {
220183
_, metadata, warnings, err := actor.resolveRoutePolicyGUID(routeURL, spaceGUID, source)
221184
if err != nil {

actor/v7action/route_policy.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,41 @@ func (actor Actor) DeleteRoutePolicyBySource(domainName, source, hostname, path
146146
return allWarnings, err
147147
}
148148

149+
// resolveRoutePolicyGUID finds the GUID of the route policy to operate on.
150+
// If source is non-empty, it finds the policy with that source.
151+
// If source is empty, it requires exactly one policy (returns ambiguity or not-found error).
152+
func (actor *Actor) resolveRoutePolicyGUID(routeURL, spaceGUID, source string) (string, *resources.Metadata, Warnings, error) {
153+
route, routeWarnings, err := actor.GetRoute(routeURL, spaceGUID)
154+
if err != nil {
155+
return "", nil, routeWarnings, err
156+
}
157+
158+
routePolicies, _, policyWarnings, err := actor.CloudControllerClient.GetRoutePolicies(
159+
ccv3.Query{Key: ccv3.RouteGUIDFilter, Values: []string{route.GUID}},
160+
)
161+
allWarnings := append(routeWarnings, Warnings(policyWarnings)...)
162+
if err != nil {
163+
return "", nil, allWarnings, err
164+
}
165+
166+
if source != "" {
167+
for _, p := range routePolicies {
168+
if p.Source == source {
169+
return p.GUID, p.Metadata, allWarnings, nil
170+
}
171+
}
172+
return "", nil, allWarnings, actionerror.RoutePolicyNotFoundError{Source: source}
173+
}
174+
175+
if len(routePolicies) == 0 {
176+
return "", nil, allWarnings, actionerror.RoutePolicyNotFoundError{Source: ""}
177+
}
178+
if len(routePolicies) > 1 {
179+
return "", nil, allWarnings, actionerror.RoutePolicyAmbiguityError{RouteURL: routeURL, Count: len(routePolicies)}
180+
}
181+
p := routePolicies[0]
182+
return p.GUID, p.Metadata, allWarnings, nil
183+
}
149184

150185
// RoutePolicyWithRoute combines a route policy with its associated route information
151186
type RoutePolicyWithRoute struct {

0 commit comments

Comments
 (0)