github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/route.go (about) 1 package ccv3 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 5 "code.cloudfoundry.org/cli/resources" 6 ) 7 8 func (client Client) CreateRoute(route resources.Route) (resources.Route, Warnings, error) { 9 var responseBody resources.Route 10 11 _, warnings, err := client.MakeRequest(RequestParams{ 12 RequestName: internal.PostRouteRequest, 13 RequestBody: route, 14 ResponseBody: &responseBody, 15 }) 16 17 return responseBody, warnings, err 18 } 19 20 func (client Client) DeleteOrphanedRoutes(spaceGUID string) (JobURL, Warnings, error) { 21 jobURL, warnings, err := client.MakeRequest(RequestParams{ 22 RequestName: internal.DeleteOrphanedRoutesRequest, 23 URIParams: internal.Params{"space_guid": spaceGUID}, 24 Query: []Query{{Key: UnmappedFilter, Values: []string{"true"}}}, 25 }) 26 27 return jobURL, warnings, err 28 } 29 30 func (client Client) DeleteRoute(routeGUID string) (JobURL, Warnings, error) { 31 jobURL, warnings, err := client.MakeRequest(RequestParams{ 32 RequestName: internal.DeleteRouteRequest, 33 URIParams: internal.Params{"route_guid": routeGUID}, 34 }) 35 36 return jobURL, warnings, err 37 } 38 39 func (client Client) GetApplicationRoutes(appGUID string) ([]resources.Route, Warnings, error) { 40 var routes []resources.Route 41 42 _, warnings, err := client.MakeListRequest(RequestParams{ 43 RequestName: internal.GetApplicationRoutesRequest, 44 URIParams: internal.Params{"app_guid": appGUID}, 45 ResponseBody: resources.Route{}, 46 AppendToList: func(item interface{}) error { 47 routes = append(routes, item.(resources.Route)) 48 return nil 49 }, 50 }) 51 52 return routes, warnings, err 53 } 54 55 func (client Client) GetRouteDestinations(routeGUID string) ([]resources.RouteDestination, Warnings, error) { 56 var responseBody struct { 57 Destinations []resources.RouteDestination `json:"destinations"` 58 } 59 60 _, warnings, err := client.MakeRequest(RequestParams{ 61 RequestName: internal.GetRouteDestinationsRequest, 62 URIParams: internal.Params{"route_guid": routeGUID}, 63 ResponseBody: &responseBody, 64 }) 65 66 return responseBody.Destinations, warnings, err 67 } 68 69 func (client Client) GetRoutes(query ...Query) ([]resources.Route, Warnings, error) { 70 var routes []resources.Route 71 72 _, warnings, err := client.MakeListRequest(RequestParams{ 73 RequestName: internal.GetRoutesRequest, 74 Query: query, 75 ResponseBody: resources.Route{}, 76 AppendToList: func(item interface{}) error { 77 routes = append(routes, item.(resources.Route)) 78 return nil 79 }, 80 }) 81 82 return routes, warnings, err 83 } 84 85 func (client Client) MapRoute(routeGUID string, appGUID string, destinationProtocol string) (Warnings, error) { 86 type destinationProcess struct { 87 ProcessType string `json:"process_type"` 88 } 89 90 type destinationApp struct { 91 GUID string `json:"guid"` 92 Process *destinationProcess `json:"process,omitempty"` 93 } 94 type destination struct { 95 App destinationApp `json:"app"` 96 Protocol string `json:"protocol,omitempty"` 97 } 98 99 type body struct { 100 Destinations []destination `json:"destinations"` 101 } 102 103 requestBody := body{ 104 Destinations: []destination{ 105 { 106 App: destinationApp{GUID: appGUID}, 107 }, 108 }, 109 } 110 if destinationProtocol != "" { 111 requestBody.Destinations[0].Protocol = destinationProtocol 112 } 113 114 _, warnings, err := client.MakeRequest(RequestParams{ 115 RequestName: internal.MapRouteRequest, 116 URIParams: internal.Params{"route_guid": routeGUID}, 117 RequestBody: &requestBody, 118 }) 119 120 return warnings, err 121 } 122 123 func (client Client) UnmapRoute(routeGUID string, destinationGUID string) (Warnings, error) { 124 var responseBody resources.Build 125 126 _, warnings, err := client.MakeRequest(RequestParams{ 127 RequestName: internal.UnmapRouteRequest, 128 URIParams: internal.Params{"route_guid": routeGUID, "destination_guid": destinationGUID}, 129 ResponseBody: &responseBody, 130 }) 131 132 return warnings, err 133 } 134 135 func (client Client) UnshareRoute(routeGUID string, spaceGUID string) (Warnings, error) { 136 var responseBody resources.Build 137 138 _, warnings, err := client.MakeRequest(RequestParams{ 139 RequestName: internal.UnshareRouteRequest, 140 URIParams: internal.Params{"route_guid": routeGUID, "space_guid": spaceGUID}, 141 ResponseBody: &responseBody, 142 }) 143 return warnings, err 144 } 145 146 func (client Client) UpdateDestination(routeGUID string, destinationGUID string, protocol string) (Warnings, error) { 147 type body struct { 148 Protocol string `json:"protocol"` 149 } 150 requestBody := body{ 151 Protocol: protocol, 152 } 153 var responseBody resources.Build 154 _, warnings, err := client.MakeRequest(RequestParams{ 155 RequestName: internal.PatchDestinationRequest, 156 URIParams: internal.Params{"route_guid": routeGUID, "destination_guid": destinationGUID}, 157 RequestBody: &requestBody, 158 ResponseBody: &responseBody, 159 }) 160 return warnings, err 161 } 162 163 func (client Client) ShareRoute(routeGUID string, spaceGUID string) (Warnings, error) { 164 type space struct { 165 GUID string `json:"guid"` 166 } 167 168 type body struct { 169 Data []space `json:"data"` 170 } 171 172 requestBody := body{ 173 Data: []space{ 174 {GUID: spaceGUID}, 175 }, 176 } 177 178 var responseBody resources.Build 179 _, warnings, err := client.MakeRequest(RequestParams{ 180 RequestName: internal.ShareRouteRequest, 181 URIParams: internal.Params{"route_guid": routeGUID}, 182 RequestBody: &requestBody, 183 ResponseBody: &responseBody, 184 }) 185 return warnings, err 186 } 187 188 func (client Client) MoveRoute(routeGUID string, spaceGUID string) (Warnings, error) { 189 type space struct { 190 GUID string `json:"guid"` 191 } 192 193 type body struct { 194 Data space `json:"data"` 195 } 196 197 requestBody := body{ 198 Data: space{ 199 GUID: spaceGUID, 200 }, 201 } 202 203 var responseBody resources.Build 204 _, warnings, err := client.MakeRequest(RequestParams{ 205 RequestName: internal.PatchMoveRouteRequest, 206 URIParams: internal.Params{"route_guid": routeGUID}, 207 RequestBody: &requestBody, 208 ResponseBody: &responseBody, 209 }) 210 return warnings, err 211 }