github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv2/info.go (about)

     1  package ccv2
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
     6  )
     7  
     8  // APIInformation represents the information returned back from /v2/info
     9  type APIInformation struct {
    10  	APIVersion                   string `json:"api_version"`
    11  	AuthorizationEndpoint        string `json:"authorization_endpoint"`
    12  	DopplerEndpoint              string `json:"doppler_logging_endpoint"`
    13  	MinCLIVersion                string `json:"min_cli_version"`
    14  	MinimumRecommendedCLIVersion string `json:"min_recommended_cli_version"`
    15  	Name                         string `json:"name"`
    16  	RoutingEndpoint              string `json:"routing_endpoint"`
    17  	TokenEndpoint                string `json:"token_endpoint"`
    18  }
    19  
    20  // API returns the Cloud Controller API URL for the targeted Cloud Controller.
    21  func (client *Client) API() string {
    22  	return client.cloudControllerURL
    23  }
    24  
    25  // APIVersion returns Cloud Controller API Version for the targeted Cloud
    26  // Controller.
    27  func (client *Client) APIVersion() string {
    28  	return client.cloudControllerAPIVersion
    29  }
    30  
    31  // AuthorizationEndpoint returns the authorization endpoint for the targeted
    32  // Cloud Controller.
    33  func (client *Client) AuthorizationEndpoint() string {
    34  	return client.authorizationEndpoint
    35  }
    36  
    37  // DopplerEndpoint returns the Doppler endpoint for the targetd Cloud
    38  // Controller.
    39  func (client *Client) DopplerEndpoint() string {
    40  	return client.dopplerEndpoint
    41  }
    42  
    43  // MinCLIVersion returns the minimum CLI version required for the targeted
    44  // Cloud Controller
    45  func (client *Client) MinCLIVersion() string {
    46  	return client.minCLIVersion
    47  }
    48  
    49  // RoutingEndpoint returns the Routing endpoint for the targeted Cloud
    50  // Controller.
    51  func (client *Client) RoutingEndpoint() string {
    52  	return client.routingEndpoint
    53  }
    54  
    55  // TokenEndpoint returns the Token endpoint for the targeted Cloud Controller.
    56  func (client *Client) TokenEndpoint() string {
    57  	return client.tokenEndpoint
    58  }
    59  
    60  // Info returns back endpoint and API information from /v2/info.
    61  func (client *Client) Info() (APIInformation, Warnings, error) {
    62  	request, err := client.newHTTPRequest(requestOptions{
    63  		RequestName: internal.InfoRequest,
    64  	})
    65  	if err != nil {
    66  		return APIInformation{}, nil, err
    67  	}
    68  
    69  	var info APIInformation
    70  	response := cloudcontroller.Response{
    71  		Result: &info,
    72  	}
    73  
    74  	err = client.connection.Make(request, &response)
    75  	if _, ok := err.(cloudcontroller.NotFoundError); ok {
    76  		return APIInformation{}, nil, cloudcontroller.APINotFoundError{URL: client.cloudControllerURL}
    77  	}
    78  	return info, response.Warnings, err
    79  }