Skip to content

Commit 2335f73

Browse files
Allow setting the route destination port via the CF CLI map-route command using a new app-port parameter (#3733)
Co-authored-by: Maurice Brinkmann <Maurice.Brinkmann@mail.schwarz>
1 parent 2ea181e commit 2335f73

File tree

17 files changed

+157
-76
lines changed

17 files changed

+157
-76
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ integration/assets/test_plugin/test_plugin
7070
.vscode
7171
.secrets
7272
.vars
73+
.patch

actor/v7action/cloud_controller_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type CloudControllerClient interface {
143143
GetUser(userGUID string) (resources.User, ccv3.Warnings, error)
144144
GetUsers(query ...ccv3.Query) ([]resources.User, ccv3.Warnings, error)
145145
MakeRequestSendReceiveRaw(Method string, URL string, headers http.Header, requestBody []byte) ([]byte, *http.Response, error)
146-
MapRoute(routeGUID string, appGUID string, destinationProtocol string) (ccv3.Warnings, error)
146+
MapRoute(routeGUID string, appGUID string, destinationProtocol string, destinationPort int) (ccv3.Warnings, error)
147147
MoveRoute(routeGUID string, spaceGUID string) (ccv3.Warnings, error)
148148
PollJob(jobURL ccv3.JobURL) (ccv3.Warnings, error)
149149
PollJobForState(jobURL ccv3.JobURL, state constant.JobState) (ccv3.Warnings, error)

actor/v7action/route.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type RouteSummary struct {
2121
resources.Route
2222
AppNames []string
2323
AppProtocols []string
24+
AppPorts []string
2425
DomainName string
2526
SpaceName string
2627
ServiceInstanceName string
@@ -279,9 +280,13 @@ func (actor Actor) GetRouteSummaries(routes []resources.Route) ([]RouteSummary,
279280
var appNames []string
280281

281282
protocolSet := map[string]bool{}
283+
portSet := map[int]bool{}
282284
for _, destination := range route.Destinations {
283285
appNames = append(appNames, appNamesByGUID[destination.App.GUID])
284286
protocolSet[destination.Protocol] = true
287+
if destination.Port > 0 {
288+
portSet[destination.Port] = true
289+
}
285290
}
286291

287292
var appProtocols []string
@@ -293,10 +298,20 @@ func (actor Actor) GetRouteSummaries(routes []resources.Route) ([]RouteSummary,
293298
sort.Strings(appProtocols)
294299
}
295300

301+
var appPorts []string
302+
if len(portSet) > 0 {
303+
appPorts = make([]string, 0, len(portSet))
304+
for key := range portSet {
305+
appPorts = append(appPorts, strconv.Itoa(key))
306+
}
307+
sort.Strings(appPorts)
308+
}
309+
296310
routeSummaries = append(routeSummaries, RouteSummary{
297311
Route: route,
298312
AppNames: appNames,
299313
AppProtocols: appProtocols,
314+
AppPorts: appPorts,
300315
SpaceName: spaceNamesByGUID[route.SpaceGUID],
301316
DomainName: getDomainName(route.URL, route.Host, route.Path, route.Port),
302317
ServiceInstanceName: serviceInstanceNameByRouteGUID[route.GUID],
@@ -397,8 +412,8 @@ func (actor Actor) GetRouteByAttributes(domain resources.Domain, hostname string
397412
return routes[0], Warnings(ccWarnings), nil
398413
}
399414

400-
func (actor Actor) MapRoute(routeGUID string, appGUID string, destinationProtocol string) (Warnings, error) {
401-
warnings, err := actor.CloudControllerClient.MapRoute(routeGUID, appGUID, destinationProtocol)
415+
func (actor Actor) MapRoute(routeGUID string, appGUID string, destinationProtocol string, destinationPort int) (Warnings, error) {
416+
warnings, err := actor.CloudControllerClient.MapRoute(routeGUID, appGUID, destinationProtocol, destinationPort)
402417
return Warnings(warnings), err
403418
}
404419

actor/v7action/route_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,19 +1581,21 @@ var _ = Describe("Route Actions", func() {
15811581
routeGUID string
15821582
appGUID string
15831583
destinationProtocol string
1584+
destinationPort int
15841585

15851586
executeErr error
15861587
warnings Warnings
15871588
)
15881589

15891590
JustBeforeEach(func() {
1590-
warnings, executeErr = actor.MapRoute(routeGUID, appGUID, destinationProtocol)
1591+
warnings, executeErr = actor.MapRoute(routeGUID, appGUID, destinationProtocol, destinationPort)
15911592
})
15921593

15931594
BeforeEach(func() {
15941595
routeGUID = "route-guid"
15951596
appGUID = "app-guid"
15961597
destinationProtocol = "http2"
1598+
destinationPort = 8080
15971599
})
15981600

15991601
When("the cloud controller client errors", func() {
@@ -1613,10 +1615,11 @@ var _ = Describe("Route Actions", func() {
16131615
})
16141616

16151617
It("calls the cloud controller client with the right arguments", func() {
1616-
actualRouteGUID, actualAppGUID, actualDestinationProtocol := fakeCloudControllerClient.MapRouteArgsForCall(0)
1618+
actualRouteGUID, actualAppGUID, actualDestinationProtocol, actualDestinationPort := fakeCloudControllerClient.MapRouteArgsForCall(0)
16171619
Expect(actualRouteGUID).To(Equal("route-guid"))
16181620
Expect(actualAppGUID).To(Equal("app-guid"))
16191621
Expect(actualDestinationProtocol).To(Equal("http2"))
1622+
Expect(actualDestinationPort).To(Equal(8080))
16201623
})
16211624

16221625
It("returns the error and warnings", func() {

actor/v7action/v7actionfakes/fake_cloud_controller_client.go

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actor/v7pushaction/v7_actor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type V7Actor interface {
2525
GetDomain(domainGUID string) (resources.Domain, v7action.Warnings, error)
2626
GetRouteByAttributes(domain resources.Domain, hostname, path string, port int) (resources.Route, v7action.Warnings, error)
2727
GetRouteDestinationByAppGUID(route resources.Route, appGUID string) (resources.RouteDestination, error)
28-
MapRoute(routeGUID string, appGUID string, destinationProtocol string) (v7action.Warnings, error)
28+
MapRoute(routeGUID string, appGUID string, destinationProtocol string, destinationPort int) (v7action.Warnings, error)
2929
PollBuild(buildGUID string, appName string) (resources.Droplet, v7action.Warnings, error)
3030
PollPackage(pkg resources.Package) (resources.Package, v7action.Warnings, error)
3131
PollStart(app resources.Application, noWait bool, handleProcessStats func(string)) (v7action.Warnings, error)

actor/v7pushaction/v7pushactionfakes/fake_v7actor.go

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/cloudcontroller/ccv3/route.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (client Client) UpdateRoute(routeGUID string, options map[string]*string) (
100100

101101
}
102102

103-
func (client Client) MapRoute(routeGUID string, appGUID string, destinationProtocol string) (Warnings, error) {
103+
func (client Client) MapRoute(routeGUID string, appGUID string, destinationProtocol string, destinationPort int) (Warnings, error) {
104104
type destinationProcess struct {
105105
ProcessType string `json:"process_type"`
106106
}
@@ -112,6 +112,7 @@ func (client Client) MapRoute(routeGUID string, appGUID string, destinationProto
112112
type destination struct {
113113
App destinationApp `json:"app"`
114114
Protocol string `json:"protocol,omitempty"`
115+
Port int `json:"port,omitempty"`
115116
}
116117

117118
type body struct {
@@ -128,6 +129,9 @@ func (client Client) MapRoute(routeGUID string, appGUID string, destinationProto
128129
if destinationProtocol != "" {
129130
requestBody.Destinations[0].Protocol = destinationProtocol
130131
}
132+
if destinationPort != 0 {
133+
requestBody.Destinations[0].Port = destinationPort
134+
}
131135

132136
_, warnings, err := client.MakeRequest(RequestParams{
133137
RequestName: internal.MapRouteRequest,

api/cloudcontroller/ccv3/route_test.go

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ var _ = Describe("Route", func() {
577577
routeGUID = "route-guid"
578578
appGUID = "app-guid"
579579
destinationProtocol string
580+
destinationPort int
580581
expectedBody string
581582
warnings Warnings
582583
executeErr error
@@ -591,24 +592,26 @@ var _ = Describe("Route", func() {
591592
RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"warning-1"}}),
592593
),
593594
)
594-
warnings, executeErr = client.MapRoute(routeGUID, appGUID, destinationProtocol)
595+
warnings, executeErr = client.MapRoute(routeGUID, appGUID, destinationProtocol, destinationPort)
595596
})
596597

597598
When("the request is successful", func() {
598599
BeforeEach(func() {
599600
destinationProtocol = "http2"
601+
destinationPort = 8080
600602
expectedBody = fmt.Sprintf(`
601-
{
602-
"destinations": [
603-
{
604-
"app": {
605-
"guid": "%s"
606-
},
607-
"protocol": "%s"
608-
}
609-
]
610-
}
611-
`, appGUID, destinationProtocol)
603+
{
604+
"destinations": [
605+
{
606+
"app": {
607+
"guid": "%s"
608+
},
609+
"protocol": "%s",
610+
"port": %d
611+
}
612+
]
613+
}
614+
`, appGUID, destinationProtocol, destinationPort)
612615
})
613616

614617
It("returns the warnings and no error", func() {
@@ -620,24 +623,48 @@ var _ = Describe("Route", func() {
620623
Context("when destination protocol is not provided", func() {
621624
BeforeEach(func() {
622625
destinationProtocol = ""
626+
destinationPort = 0
623627
expectedBody = fmt.Sprintf(`
624-
{
625-
"destinations": [
626-
{
627-
"app": {
628-
"guid": "%s"
629-
}
630-
}
631-
]
632-
}
633-
`, appGUID)
628+
{
629+
"destinations": [
630+
{
631+
"app": {
632+
"guid": "%s"
633+
}
634+
}
635+
]
636+
}
637+
`, appGUID)
634638
})
635639

636640
It("does not include it in the request", func() {
637641
Expect(executeErr).ToNot(HaveOccurred())
638642
})
639643
})
640644

645+
Context("when destination port is provided without protocol", func() {
646+
BeforeEach(func() {
647+
destinationProtocol = ""
648+
destinationPort = 9090
649+
expectedBody = fmt.Sprintf(`
650+
{
651+
"destinations": [
652+
{
653+
"app": {
654+
"guid": "%s"
655+
},
656+
"port": %d
657+
}
658+
]
659+
}
660+
`, appGUID, destinationPort)
661+
})
662+
663+
It("includes the port in the request", func() {
664+
Expect(executeErr).ToNot(HaveOccurred())
665+
})
666+
})
667+
641668
When("the cloud controller returns errors and warnings", func() {
642669
BeforeEach(func() {
643670
response := `{

command/v7/actor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ type Actor interface {
187187
GetUser(username, origin string) (resources.User, error)
188188
ListServiceAppBindings(params v7action.ListServiceAppBindingParams) ([]resources.ServiceCredentialBinding, v7action.Warnings, error)
189189
MakeCurlRequest(httpMethod string, path string, customHeaders []string, httpData string, failOnHTTPError bool) ([]byte, *http.Response, error)
190-
MapRoute(routeGUID string, appGUID string, destinationProtocol string) (v7action.Warnings, error)
190+
MapRoute(routeGUID string, appGUID string, destinationProtocol string, destinationPort int) (v7action.Warnings, error)
191191
Marketplace(filter v7action.MarketplaceFilter) ([]v7action.ServiceOfferingWithPlans, v7action.Warnings, error)
192192
MoveRoute(routeGUID string, spaceGUID string) (v7action.Warnings, error)
193193
ParseAccessToken(accessToken string) (jwt.JWT, error)

0 commit comments

Comments
 (0)