github.com/Thanhphan1147/cloudfoundry-cli@v7.1.0+incompatible/actor/v7action/feature_flag.go (about) 1 package v7action 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 7 ) 8 9 type FeatureFlag ccv3.FeatureFlag 10 11 // GetFeatureFlagByName returns a featureFlag with the provided name. 12 func (actor Actor) GetFeatureFlagByName(featureFlagName string) (FeatureFlag, Warnings, error) { 13 var ( 14 ccv3FeatureFlag ccv3.FeatureFlag 15 warnings ccv3.Warnings 16 err error 17 ) 18 ccv3FeatureFlag, warnings, err = actor.CloudControllerClient.GetFeatureFlag(featureFlagName) 19 20 if err != nil { 21 if _, ok := err.(ccerror.FeatureFlagNotFoundError); ok { 22 return FeatureFlag{}, Warnings(warnings), actionerror.FeatureFlagNotFoundError{FeatureFlagName: featureFlagName} 23 } 24 return FeatureFlag{}, Warnings(warnings), err 25 } 26 27 return FeatureFlag(ccv3FeatureFlag), Warnings(warnings), err 28 } 29 30 func (actor Actor) GetFeatureFlags() ([]FeatureFlag, Warnings, error) { 31 32 var ( 33 featureFlags []FeatureFlag 34 ) 35 ccv3FeatureFlags, warnings, err := actor.CloudControllerClient.GetFeatureFlags() 36 37 if err != nil { 38 return nil, Warnings(warnings), err 39 } 40 41 for _, flag := range ccv3FeatureFlags { 42 featureFlags = append(featureFlags, FeatureFlag(flag)) 43 } 44 45 return featureFlags, Warnings(warnings), nil 46 } 47 48 func (actor Actor) EnableFeatureFlag(flagName string) (Warnings, error) { 49 return actor.updateFeatureFlag(FeatureFlag{Name: flagName, Enabled: true}) 50 } 51 52 func (actor Actor) DisableFeatureFlag(flagName string) (Warnings, error) { 53 return actor.updateFeatureFlag(FeatureFlag{Name: flagName, Enabled: false}) 54 } 55 56 func (actor Actor) updateFeatureFlag(flag FeatureFlag) (Warnings, error) { 57 _, warnings, err := actor.CloudControllerClient.UpdateFeatureFlag(ccv3.FeatureFlag(flag)) 58 59 if _, ok := err.(ccerror.FeatureFlagNotFoundError); ok { 60 err = actionerror.FeatureFlagNotFoundError{FeatureFlagName: flag.Name} 61 } 62 return Warnings(warnings), err 63 }