github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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  
    39  // API returns the Cloud Controller API URL for the targeted Cloud Controller.
    40  func (client *Client) API() string {
    41  	return client.cloudControllerURL
    42  }
    43  
    44  // APIVersion returns Cloud Controller API Version for the targeted Cloud
    45  // Controller.
    46  func (client *Client) APIVersion() string {
    47  	return client.cloudControllerAPIVersion
    48  }
    49  
    50  // AuthorizationEndpoint returns the authorization endpoint for the targeted
    51  // Cloud Controller.
    52  func (client *Client) AuthorizationEndpoint() string {
    53  	return client.authorizationEndpoint
    54  }
    55  
    56  // DopplerEndpoint returns the Doppler endpoint for the targetd Cloud
    57  // Controller.
    58  func (client *Client) DopplerEndpoint() string {
    59  	return client.dopplerEndpoint
    60  }
    61  
    62  // Info returns back endpoint and API information from /v2/info.
    63  func (client *Client) Info() (APIInformation, Warnings, error) {
    64  	request, err := client.newHTTPRequest(requestOptions{
    65  		RequestName: internal.GetInfoRequest,
    66  	})
    67  	if err != nil {
    68  		return APIInformation{}, nil, err
    69  	}
    70  
    71  	var info APIInformation
    72  	response := cloudcontroller.Response{
    73  		DecodeJSONResponseInto: &info,
    74  	}
    75  
    76  	err = client.connection.Make(request, &response)
    77  	if unknownSourceErr, ok := err.(ccerror.UnknownHTTPSourceError); ok && unknownSourceErr.StatusCode == http.StatusNotFound {
    78  		return APIInformation{}, nil, ccerror.APINotFoundError{URL: client.cloudControllerURL}
    79  	}
    80  	return info, response.Warnings, err
    81  }
    82  
    83  // MinCLIVersion returns the minimum CLI version required for the targeted
    84  // Cloud Controller
    85  func (client *Client) MinCLIVersion() string {
    86  	return client.minCLIVersion
    87  }
    88  
    89  // RoutingEndpoint returns the Routing endpoint for the targeted Cloud
    90  // Controller.
    91  func (client *Client) RoutingEndpoint() string {
    92  	return client.routingEndpoint
    93  }