@@ -30,6 +30,7 @@ use std::process;
30
30
31
31
use rabbitmq_http_client:: commons:: BindingDestinationType ;
32
32
use rabbitmq_http_client:: commons:: QueueType ;
33
+ use rabbitmq_http_client:: transformers:: TransformationChain ;
33
34
use rabbitmq_http_client:: { password_hashing, requests, responses} ;
34
35
35
36
type APIClient < ' a > = Client < & ' a str , & ' a str , & ' a str > ;
@@ -907,6 +908,52 @@ pub fn rebalance_queues(client: APIClient) -> ClientResult<()> {
907
908
pub fn export_cluster_wide_definitions (
908
909
client : APIClient ,
909
910
command_args : & ArgMatches ,
911
+ ) -> ClientResult < ( ) > {
912
+ let transformations = command_args
913
+ . get_many :: < String > ( "transformations" )
914
+ . unwrap_or_default ( ) ;
915
+
916
+ if transformations. len ( ) == 0 {
917
+ export_cluster_wide_definitions_without_transformations ( client, command_args)
918
+ } else {
919
+ let transformations = transformations
920
+ . into_iter ( )
921
+ . map ( String :: from)
922
+ . collect :: < Vec < _ > > ( ) ;
923
+ export_and_transform_cluster_wide_definitions ( client, command_args, transformations)
924
+ }
925
+ }
926
+
927
+ fn export_and_transform_cluster_wide_definitions (
928
+ client : APIClient ,
929
+ command_args : & ArgMatches ,
930
+ transformations : Vec < String > ,
931
+ ) -> ClientResult < ( ) > {
932
+ match client. export_cluster_wide_definitions_as_data ( ) {
933
+ Ok ( mut defs0) => {
934
+ let chain = TransformationChain :: from ( transformations) ;
935
+ let defs1 = chain. apply ( & mut defs0) ;
936
+ let json = serde_json:: to_string_pretty ( & defs1) . unwrap ( ) ;
937
+
938
+ let path = command_args. get_one :: < String > ( "file" ) . unwrap ( ) ;
939
+ match path. as_str ( ) {
940
+ "-" => {
941
+ println ! ( "{}" , & json) ;
942
+ Ok ( ( ) )
943
+ }
944
+ file => {
945
+ _ = fs:: write ( file, & json) ;
946
+ Ok ( ( ) )
947
+ }
948
+ }
949
+ }
950
+ Err ( err) => Err ( err) ,
951
+ }
952
+ }
953
+
954
+ fn export_cluster_wide_definitions_without_transformations (
955
+ client : APIClient ,
956
+ command_args : & ArgMatches ,
910
957
) -> ClientResult < ( ) > {
911
958
match client. export_cluster_wide_definitions ( ) {
912
959
Ok ( definitions) => {
0 commit comments