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