github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/api/cloudcontroller/ccv2/service_plan.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  // ServicePlan represents a predefined set of configurations for a Cloud
     9  // Controller service object.
    10  type ServicePlan struct {
    11  	//GUID is the unique identifier of the service plan.
    12  	GUID string
    13  
    14  	// Name is the name of the service plan.
    15  	Name string
    16  
    17  	// ServiceGUID is the unique identifier of the service that the service
    18  	// plan belongs to.
    19  	ServiceGUID string
    20  }
    21  
    22  // UnmarshalJSON helps unmarshal a Cloud Controller Service Plan response.
    23  func (servicePlan *ServicePlan) UnmarshalJSON(data []byte) error {
    24  	var ccServicePlan struct {
    25  		Metadata internal.Metadata
    26  		Entity   struct {
    27  			Name        string `json:"name"`
    28  			ServiceGUID string `json:"service_guid"`
    29  		}
    30  	}
    31  	err := cloudcontroller.DecodeJSON(data, &ccServicePlan)
    32  	if err != nil {
    33  		return err
    34  	}
    35  
    36  	servicePlan.GUID = ccServicePlan.Metadata.GUID
    37  	servicePlan.Name = ccServicePlan.Entity.Name
    38  	servicePlan.ServiceGUID = ccServicePlan.Entity.ServiceGUID
    39  	return nil
    40  }
    41  
    42  // GetServicePlan returns the service plan with the given GUID.
    43  func (client *Client) GetServicePlan(servicePlanGUID string) (ServicePlan, Warnings, error) {
    44  	request, err := client.newHTTPRequest(requestOptions{
    45  		RequestName: internal.GetServicePlanRequest,
    46  		URIParams:   Params{"service_plan_guid": servicePlanGUID},
    47  	})
    48  	if err != nil {
    49  		return ServicePlan{}, nil, err
    50  	}
    51  
    52  	var servicePlan ServicePlan
    53  	response := cloudcontroller.Response{
    54  		Result: &servicePlan,
    55  	}
    56  
    57  	err = client.connection.Make(request, &response)
    58  	return servicePlan, response.Warnings, err
    59  }