github.com/arunkumar7540/cli@v6.45.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 is the Doppler endpoint for the targeted Cloud Controller.
    22  	DopplerEndpoint string `json:"doppler_logging_endpoint"`
    23  
    24  	// MinCLIVersion is the minimum CLI version number required for the targeted
    25  	// Cloud Controller.
    26  	MinCLIVersion string `json:"min_cli_version"`
    27  
    28  	// MinimumRecommendedCLIVersion is the minimum CLI version number recommended
    29  	// for the targeted Cloud Controller.
    30  	MinimumRecommendedCLIVersion string `json:"min_recommended_cli_version"`
    31  
    32  	// Name is the name given to the targeted Cloud Controller.
    33  	Name string `json:"name"`
    34  
    35  	// RoutingEndpoint is the Routing endpoint for the targeted Cloud Controller.
    36  	RoutingEndpoint string `json:"routing_endpoint"`
    37  
    38  	// TokenEndpoint is the endpoint to retrieve a refresh token for the targeted
    39  	// Cloud Controller.
    40  	TokenEndpoint string `json:"token_endpoint"`
    41  }
    42  
    43  // API returns the Cloud Controller API URL for the targeted Cloud Controller.
    44  func (client *Client) API() string {
    45  	return client.cloudControllerURL
    46  }
    47  
    48  // APIVersion returns Cloud Controller API Version for the targeted Cloud
    49  // Controller.
    50  func (client *Client) APIVersion() string {
    51  	return client.cloudControllerAPIVersion
    52  }
    53  
    54  // AuthorizationEndpoint returns the authorization endpoint for the targeted
    55  // Cloud Controller.
    56  func (client *Client) AuthorizationEndpoint() string {
    57  	return client.authorizationEndpoint
    58  }
    59  
    60  // DopplerEndpoint returns the Doppler endpoint for the targetd Cloud
    61  // Controller.
    62  func (client *Client) DopplerEndpoint() string {
    63  	return client.dopplerEndpoint
    64  }
    65  
    66  // Info returns back endpoint and API information from /v2/info.
    67  func (client *Client) Info() (APIInformation, Warnings, error) {
    68  	request, err := client.newHTTPRequest(requestOptions{
    69  		RequestName: internal.GetInfoRequest,
    70  	})
    71  	if err != nil {
    72  		return APIInformation{}, nil, err
    73  	}
    74  
    75  	var info APIInformation
    76  	response := cloudcontroller.Response{
    77  		DecodeJSONResponseInto: &info,
    78  	}
    79  
    80  	err = client.connection.Make(request, &response)
    81  	if unknownSourceErr, ok := err.(ccerror.UnknownHTTPSourceError); ok && unknownSourceErr.StatusCode == http.StatusNotFound {
    82  		return APIInformation{}, nil, ccerror.APINotFoundError{URL: client.cloudControllerURL}
    83  	}
    84  	return info, response.Warnings, err
    85  }
    86  
    87  // MinCLIVersion returns the minimum CLI version required for the targeted
    88  // Cloud Controller
    89  func (client *Client) MinCLIVersion() string {
    90  	return client.minCLIVersion
    91  }
    92  
    93  // RoutingEndpoint returns the Routing endpoint for the targeted Cloud
    94  // Controller.
    95  func (client *Client) RoutingEndpoint() string {
    96  	return client.routingEndpoint
    97  }
    98  
    99  // TokenEndpoint returns the Token endpoint for the targeted Cloud Controller.
   100  func (client *Client) TokenEndpoint() string {
   101  	return client.tokenEndpoint
   102  }