Example #1
0
// GetServiceBindings returns back a list of Service Bindings based off of the
// provided queries.
func (client *CloudControllerClient) GetServiceBindings(queries []Query) ([]ServiceBinding, Warnings, error) {
	request := cloudcontroller.NewRequest(
		internal.ServiceBindingsRequest,
		nil,
		nil,
		FormatQueryParameters(queries),
	)

	allServiceBindingsList := []ServiceBinding{}
	allWarningsList := Warnings{}

	for {
		var serviceBindings []ServiceBinding
		wrapper := PaginatedWrapper{
			Resources: &serviceBindings,
		}
		response := cloudcontroller.Response{
			Result: &wrapper,
		}

		err := client.connection.Make(request, &response)
		allWarningsList = append(allWarningsList, response.Warnings...)
		if err != nil {
			return nil, allWarningsList, err
		}

		allServiceBindingsList = append(allServiceBindingsList, serviceBindings...)

		if wrapper.NextURL == "" {
			break
		}
		request = cloudcontroller.NewRequestFromURI(
			wrapper.NextURL,
			http.MethodGet,
			nil,
		)
	}

	return allServiceBindingsList, allWarningsList, nil
}
Example #2
0
// GetSpaceRoutes returns a list of Routes associated with the provided Space
// GUID, and filtered by the provided queries.
func (client *CloudControllerClient) GetSpaceRoutes(spaceGUID string, queryParams []Query) ([]Route, Warnings, error) {
	request := cloudcontroller.NewRequest(
		internal.RoutesFromSpaceRequest,
		map[string]string{"space_guid": spaceGUID},
		nil,
		FormatQueryParameters(queryParams),
	)

	fullRoutesList := []Route{}
	fullWarningsList := Warnings{}

	for {
		var routes []Route
		wrapper := PaginatedWrapper{
			Resources: &routes,
		}
		response := cloudcontroller.Response{
			Result: &wrapper,
		}

		err := client.connection.Make(request, &response)
		fullWarningsList = append(fullWarningsList, response.Warnings...)
		if err != nil {
			return nil, fullWarningsList, err
		}
		fullRoutesList = append(fullRoutesList, routes...)

		if wrapper.NextURL == "" {
			break
		}
		request = cloudcontroller.NewRequestFromURI(
			wrapper.NextURL,
			http.MethodGet,
			nil,
		)
	}

	return fullRoutesList, fullWarningsList, nil
}