@@ -24,7 +24,10 @@ use std::fmt;
2424
2525use crate :: error:: Error ;
2626use crate :: error:: Error :: { ClientErrorResponse , NotFound , ServerErrorResponse } ;
27- use crate :: responses:: { DeprecatedFeatureList , FeatureFlagList , MessageList } ;
27+ use crate :: responses:: {
28+ DeprecatedFeatureList , FeatureFlag , FeatureFlagList , FeatureFlagStability , FeatureFlagState ,
29+ MessageList ,
30+ } ;
2831use crate :: {
2932 commons:: { BindingDestinationType , UserLimitTarget , VirtualHostLimitTarget } ,
3033 path,
@@ -1176,12 +1179,52 @@ where
11761179 // Feature flags
11771180 //
11781181
1182+ /// Enables a feature flag.
1183+ /// This function is idempotent: enabling an already enabled feature flag
1184+ /// will succeed.
11791185 pub async fn list_feature_flags ( & self ) -> Result < FeatureFlagList > {
11801186 let response = self . http_get ( "feature-flags" , None , None ) . await ?;
11811187 let response = response. json ( ) . await ?;
11821188 Ok ( response)
11831189 }
11841190
1191+ /// Enables all stable feature flags.
1192+ /// This function is idempotent: enabling an already enabled feature flag
1193+ /// will succeed.
1194+ pub async fn enable_feature_flag ( & self , name : & str ) -> Result < ( ) > {
1195+ let body = serde_json:: json!( {
1196+ "name" : name
1197+ } ) ;
1198+ let _response = self
1199+ . http_put ( path ! ( "feature-flags" , name, "enable" ) , & body, None , None )
1200+ . await ?;
1201+ Ok ( ( ) )
1202+ }
1203+
1204+ /// Enables all stable feature flags.
1205+ /// This function is idempotent: enabling an already enabled feature flag
1206+ /// will succeed.
1207+ pub async fn enable_all_stable_feature_flags ( & self ) -> Result < ( ) > {
1208+ // PUT /api/feature-flags/{name}/enable does not support the special 'all' value like 'rabbitmqctl enable_feature_flag' does.
1209+ // Thus we do what management UI does: discover the stable disabled flags and enable
1210+ // them one by one.
1211+ let discovered_flags = self . list_feature_flags ( ) . await ?;
1212+ let flags_to_enable: Vec < & FeatureFlag > = discovered_flags
1213+ . 0
1214+ . iter ( )
1215+ . filter ( |& ff| {
1216+ ff. state == FeatureFlagState :: Disabled
1217+ && ff. stability == FeatureFlagStability :: Stable
1218+ } )
1219+ . collect ( ) ;
1220+
1221+ for ff in flags_to_enable {
1222+ self . enable_feature_flag ( & ff. name ) . await ?;
1223+ }
1224+
1225+ Ok ( ( ) )
1226+ }
1227+
11851228 //
11861229 // Deprecated Features
11871230 //
0 commit comments