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

service route binding: migrate to ccv3 #10

Open
wants to merge 1 commit into
base: v0.0.11-complete-api
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/cloudcontroller/ccv3/internal/api_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const (

ServicePlansResource = "service_plans"

RoutesResource = "routes"
RoutesResource = "routes"
RouteBindingResource = "service_route_bindings"

//v3 service credential binding
ServiceCredentialBindingsResource = "service_credential_bindings"
Expand Down
12 changes: 9 additions & 3 deletions api/cloudcontroller/ccv3/internal/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
Expand Down
4 changes: 4 additions & 0 deletions api/cloudcontroller/ccv3/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions api/cloudcontroller/ccv3/route_binding.go
Original file line number Diff line number Diff line change
@@ -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},
})
}
23 changes: 23 additions & 0 deletions resources/route_binding.go
Original file line number Diff line number Diff line change
@@ -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)
}