github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/api/cloudcontroller/ccv2/info.go (about) 1 package ccv2 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 9 ) 10 11 // APIInformation represents the information returned back from /v2/info 12 type APIInformation struct { 13 14 // APIVersion is the Cloud Controller API version number. 15 APIVersion string `json:"api_version"` 16 17 // AuthorizationEndpoint is the authorization endpoint for the targeted Cloud 18 // Controller. 19 AuthorizationEndpoint string `json:"authorization_endpoint"` 20 21 DopplerEndpoint string `json:"doppler_logging_endpoint"` 22 23 LogCacheEndpoint string `json:"log_cache_endpoint"` 24 25 MinCLIVersion string `json:"min_cli_version"` 26 27 // MinimumRecommendedCLIVersion is the minimum CLI version number recommended 28 // for the targeted Cloud Controller. 29 MinimumRecommendedCLIVersion string `json:"min_recommended_cli_version"` 30 31 // Name is the name given to the targeted Cloud Controller. 32 Name string `json:"name"` 33 34 // RoutingEndpoint is the Routing endpoint for the targeted Cloud Controller. 35 RoutingEndpoint string `json:"routing_endpoint"` 36 } 37 38 // API returns the Cloud Controller API URL for the targeted Cloud Controller. 39 func (client *Client) API() string { 40 return client.cloudControllerURL 41 } 42 43 // APIVersion returns Cloud Controller API Version for the targeted Cloud 44 // Controller. 45 func (client *Client) APIVersion() string { 46 return client.cloudControllerAPIVersion 47 } 48 49 // AuthorizationEndpoint returns the authorization endpoint for the targeted 50 // Cloud Controller. 51 func (client *Client) AuthorizationEndpoint() string { 52 return client.authorizationEndpoint 53 } 54 55 // DopplerEndpoint returns the Doppler endpoint for the targetd Cloud 56 // Controller. 57 func (client *Client) DopplerEndpoint() string { 58 return client.dopplerEndpoint 59 } 60 61 func (client *Client) LogCacheEndpoint() string { 62 return client.logCacheEndpoint 63 } 64 65 // Info returns back endpoint and API information from /v2/info. 66 func (client *Client) Info() (APIInformation, Warnings, error) { 67 request, err := client.newHTTPRequest(requestOptions{ 68 RequestName: internal.GetInfoRequest, 69 }) 70 if err != nil { 71 return APIInformation{}, nil, err 72 } 73 74 var info APIInformation 75 response := cloudcontroller.Response{ 76 DecodeJSONResponseInto: &info, 77 } 78 79 err = client.connection.Make(request, &response) 80 if unknownSourceErr, ok := err.(ccerror.UnknownHTTPSourceError); ok && unknownSourceErr.StatusCode == http.StatusNotFound { 81 return APIInformation{}, nil, ccerror.APINotFoundError{URL: client.cloudControllerURL} 82 } 83 return info, response.Warnings, err 84 } 85 86 // MinCLIVersion returns the minimum CLI version required for the targeted 87 // Cloud Controller 88 func (client *Client) MinCLIVersion() string { 89 return client.minCLIVersion 90 } 91 92 // RoutingEndpoint returns the Routing endpoint for the targeted Cloud 93 // Controller. 94 func (client *Client) RoutingEndpoint() string { 95 return client.routingEndpoint 96 } 97 98 // Info represents a GET response from the '/' endpoint of the cloud 99 // controller API. 100 type Info struct { 101 // Links is a list of top level Cloud Controller APIs. 102 Links InfoLinks `json:"links"` 103 } 104 105 type InfoLinks struct { 106 LogCache APILink `json:"log_cache"` 107 } 108 109 // rootResponse returns the CC API root document. 110 func (client *Client) RootResponse() (Info, Warnings, error) { 111 request, err := client.newHTTPRequest(requestOptions{ 112 RequestName: internal.GetRootRequest, 113 }) 114 if err != nil { 115 return Info{}, nil, err 116 } 117 118 var rootResult Info 119 response := cloudcontroller.Response{ 120 DecodeJSONResponseInto: &rootResult, 121 } 122 123 err = client.connection.Make(request, &response) 124 if unknownSourceErr, ok := err.(ccerror.UnknownHTTPSourceError); ok && unknownSourceErr.StatusCode == http.StatusNotFound { 125 return Info{}, nil, ccerror.APINotFoundError{URL: client.cloudControllerURL} 126 } 127 return rootResult, response.Warnings, err 128 }