From efde0b795936b2026bb5fcc95ad3896912abac75 Mon Sep 17 00:00:00 2001 From: Corentin PAPE Date: Tue, 8 Oct 2024 16:30:48 +0200 Subject: [PATCH] service route binding: migrate to ccv3 --- .../ccv3/internal/api_resources.go | 3 +- .../ccv3/internal/api_routes.go | 12 +++++-- api/cloudcontroller/ccv3/query.go | 4 +++ api/cloudcontroller/ccv3/route_binding.go | 36 +++++++++++++++++++ resources/route_binding.go | 23 ++++++++++++ 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 api/cloudcontroller/ccv3/route_binding.go create mode 100644 resources/route_binding.go diff --git a/api/cloudcontroller/ccv3/internal/api_resources.go b/api/cloudcontroller/ccv3/internal/api_resources.go index 30351f4030a..01c9aa6bc1c 100644 --- a/api/cloudcontroller/ccv3/internal/api_resources.go +++ b/api/cloudcontroller/ccv3/internal/api_resources.go @@ -23,7 +23,8 @@ const ( ServicePlansResource = "service_plans" - RoutesResource = "routes" + RoutesResource = "routes" + RouteBindingResource = "service_route_bindings" //v3 service credential binding ServiceCredentialBindingsResource = "service_credential_bindings" diff --git a/api/cloudcontroller/ccv3/internal/api_routes.go b/api/cloudcontroller/ccv3/internal/api_routes.go index 9a30873a50e..dacaeffd37c 100644 --- a/api/cloudcontroller/ccv3/internal/api_routes.go +++ b/api/cloudcontroller/ccv3/internal/api_routes.go @@ -88,9 +88,12 @@ const ( GetServicePlansRequest = "GetServicePlans" - PostRouteRequest = "PostRoute" - DeleteRouteRequest = "DeleteRouteRequest" - PatchRouteRequest = "PatchRoute" + PostRouteRequest = "PostRoute" + DeleteRouteRequest = "DeleteRouteRequest" + PatchRouteRequest = "PatchRoute" + PostRouteBindingRequest = "PostRouteBinding" + GetRouteBindingsRequest = "GetRouteBindings" + DeleteRouteBindingRequest = "DeleteRouteBinding" DeleteOrphanedRoutesRequest = "DeleteOrphanedRoutes" GetApplicationRoutesRequest = "GetApplicationRoutes" @@ -197,6 +200,9 @@ var APIRoutes = []Route{ {Resource: RoutesResource, Path: "/", Method: http.MethodPost, Name: PostRouteRequest}, {Resource: RoutesResource, Path: "/:route_guid", Method: http.MethodDelete, Name: DeleteRouteRequest}, {Resource: RoutesResource, Path: "/:route_guid", Method: http.MethodPatch, Name: PatchRouteRequest}, + {Resource: RouteBindingResource, Path: "/", Method: http.MethodPost, Name: PostRouteBindingRequest}, + {Resource: RouteBindingResource, Path: "/", Method: http.MethodGet, Name: GetRouteBindingsRequest}, + {Resource: RouteBindingResource, Path: "/:route_binding_guid", Method: http.MethodDelete, Name: DeleteRouteBindingRequest}, // v3 application feature {Resource: AppsResource, Path: "/:app_guid/ssh_enabled", Method: http.MethodGet, Name: GetSSHEnabled}, diff --git a/api/cloudcontroller/ccv3/query.go b/api/cloudcontroller/ccv3/query.go index 0c76152373a..7f37304d89b 100644 --- a/api/cloudcontroller/ccv3/query.go +++ b/api/cloudcontroller/ccv3/query.go @@ -29,6 +29,10 @@ const ( ServiceBrokerGUIDsFilter QueryKey = "service_broker_guids" // ServiceBrokerNamesFilter is a query parameter when getting plans or offerings according to the Service Brokers that it relates to ServiceBrokerNamesFilter QueryKey = "service_broker_names" + // ServiceInstanceGUIDFilter is a query parameter for listing objects by service instance GUID. + ServiceInstanceGUIDFilter QueryKey = "service_instance_guids" + // RouteGUIDFilter is a query parameter for listing objects by route GUID. + RouteGUIDFilter QueryKey = "route_guids" // StatesFilter is a query parameter when getting a package's droplets by state StatesFilter QueryKey = "states" // HostsFilter is a query param for listing objects by hostname diff --git a/api/cloudcontroller/ccv3/route_binding.go b/api/cloudcontroller/ccv3/route_binding.go new file mode 100644 index 00000000000..643479d628d --- /dev/null +++ b/api/cloudcontroller/ccv3/route_binding.go @@ -0,0 +1,36 @@ +package ccv3 + +import ( + "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" + "code.cloudfoundry.org/cli/resources" +) + +func (client *Client) CreateRouteBinding(binding resources.RouteBinding) (JobURL, Warnings, error) { + return client.MakeRequest(RequestParams{ + RequestName: internal.PostRouteBindingRequest, + RequestBody: binding, + }) +} + +func (client *Client) GetRouteBindings(query ...Query) ([]resources.RouteBinding, IncludedResources, Warnings, error) { + var result []resources.RouteBinding + + included, warnings, err := client.MakeListRequest(RequestParams{ + RequestName: internal.GetRouteBindingsRequest, + Query: query, + ResponseBody: resources.RouteBinding{}, + AppendToList: func(item interface{}) error { + result = append(result, item.(resources.RouteBinding)) + return nil + }, + }) + + return result, included, warnings, err +} + +func (client *Client) DeleteRouteBinding(guid string) (JobURL, Warnings, error) { + return client.MakeRequest(RequestParams{ + RequestName: internal.DeleteRouteBindingRequest, + URIParams: internal.Params{"route_binding_guid": guid}, + }) +} diff --git a/resources/route_binding.go b/resources/route_binding.go new file mode 100644 index 00000000000..cb71b99a025 --- /dev/null +++ b/resources/route_binding.go @@ -0,0 +1,23 @@ +package resources + +import ( + "code.cloudfoundry.org/cli/types" + "code.cloudfoundry.org/jsonry" +) + +type RouteBinding struct { + GUID string `jsonry:"guid,omitempty"` + RouteServiceURL string `jsonry:"route_service_url,omitempty"` + ServiceInstanceGUID string `jsonry:"relationships.service_instance.data.guid,omitempty"` + RouteGUID string `jsonry:"relationships.route.data.guid,omitempty"` + LastOperation LastOperation `jsonry:"last_operation"` + Parameters types.OptionalObject `jsonry:"parameters"` +} + +func (s RouteBinding) MarshalJSON() ([]byte, error) { + return jsonry.Marshal(s) +} + +func (s *RouteBinding) UnmarshalJSON(data []byte) error { + return jsonry.Unmarshal(data, s) +}