github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/api/cloudcontroller/ccv2/feature_flag.go (about) 1 package ccv2 2 3 import ( 4 "bytes" 5 "code.cloudfoundry.org/cli/api/cloudcontroller" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 7 "encoding/json" 8 ) 9 10 // FeatureFlag represents a Cloud Controller feature flag. 11 type FeatureFlag struct { 12 // Name is a string representation of the Cloud Controller 13 // feature flag's name. 14 Name string `json:"name"` 15 16 // Enabled is the status of the Cloud Controller feature 17 // flag. 18 Enabled bool `json:"enabled"` 19 } 20 21 // GetConfigFeatureFlags retrieves a list of FeatureFlag from the Cloud 22 // Controller. 23 func (client Client) GetConfigFeatureFlags() ([]FeatureFlag, Warnings, error) { 24 request, err := client.newHTTPRequest(requestOptions{ 25 RequestName: internal.GetConfigFeatureFlagsRequest, 26 }) 27 if err != nil { 28 return nil, nil, err 29 } 30 31 var featureFlags []FeatureFlag 32 response := cloudcontroller.Response{ 33 DecodeJSONResponseInto: &featureFlags, 34 } 35 36 err = client.connection.Make(request, &response) 37 return featureFlags, response.Warnings, err 38 } 39 40 // GetConfigFeatureFlags retrieves a list of FeatureFlag from the Cloud 41 // Controller. 42 func (client Client) SetConfigFeatureFlags(ff FeatureFlag) (Warnings, error) { 43 body, err := json.Marshal(struct { 44 Enabled bool `json:"enabled"` 45 }{ 46 Enabled: ff.Enabled, 47 }) 48 if err != nil { 49 return nil, err 50 } 51 request, err := client.newHTTPRequest(requestOptions{ 52 RequestName: internal.PutConfigFeatureFlagsRequest, 53 URIParams: Params{"name": ff.Name}, 54 Body: bytes.NewReader(body), 55 }) 56 if err != nil { 57 return nil, err 58 } 59 60 response := cloudcontroller.Response{ 61 } 62 63 err = client.connection.Make(request, &response) 64 return response.Warnings, err 65 }