github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/feature_flag.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  func (client *Client) GetFeatureFlag(flagName string) (resources.FeatureFlag, Warnings, error) {
     9  	var responseBody resources.FeatureFlag
    10  
    11  	_, warnings, err := client.MakeRequest(RequestParams{
    12  		RequestName:  internal.GetFeatureFlagRequest,
    13  		URIParams:    internal.Params{"name": flagName},
    14  		ResponseBody: &responseBody,
    15  	})
    16  
    17  	return responseBody, warnings, err
    18  }
    19  
    20  // GetFeatureFlags lists feature flags.
    21  func (client *Client) GetFeatureFlags() ([]resources.FeatureFlag, Warnings, error) {
    22  	var featureFlags []resources.FeatureFlag
    23  
    24  	_, warnings, err := client.MakeListRequest(RequestParams{
    25  		RequestName:  internal.GetFeatureFlagsRequest,
    26  		ResponseBody: resources.FeatureFlag{},
    27  		AppendToList: func(item interface{}) error {
    28  			featureFlags = append(featureFlags, item.(resources.FeatureFlag))
    29  			return nil
    30  		},
    31  	})
    32  
    33  	return featureFlags, warnings, err
    34  }
    35  
    36  func (client *Client) UpdateFeatureFlag(flag resources.FeatureFlag) (resources.FeatureFlag, Warnings, error) {
    37  	var responseBody resources.FeatureFlag
    38  
    39  	_, warnings, err := client.MakeRequest(RequestParams{
    40  		RequestName:  internal.PatchFeatureFlagRequest,
    41  		URIParams:    internal.Params{"name": flag.Name},
    42  		RequestBody:  flag,
    43  		ResponseBody: &responseBody,
    44  	})
    45  
    46  	return responseBody, warnings, err
    47  }