Skip to content

Commit b0dd690

Browse files
Introduce 'shovel disable_tls_peer_verification_for_all_source_uris'
1 parent 35ab698 commit b0dd690

File tree

4 files changed

+460
-3
lines changed

4 files changed

+460
-3
lines changed

src/cli.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ pub fn get_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 1] {
28922892
)].map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
28932893
}
28942894

2895-
pub fn shovel_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 5] {
2895+
pub fn shovel_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 6] {
28962896
let list_all_cmd = Command::new("list_all")
28972897
.long_about("Lists shovels in all virtual hosts")
28982898
.after_help(color_print::cformat!(
@@ -3041,12 +3041,29 @@ pub fn shovel_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 5
30413041
.required(true),
30423042
);
30433043

3044+
let disable_tls_peer_verification_cmd = Command::new("disable_tls_peer_verification_for_all_source_uris")
3045+
// shorter, displayed in the shovels group's help
3046+
.about(color_print::cstr!("<bold><red>Use only in emergency cases</red></bold>. Disables TLS peer verification for all shovels."))
3047+
// longer, displayed in the command's help
3048+
.long_about(color_print::cstr!("<bold><red>Use only in emergency cases</red></bold>. Disables TLS peer verification for all shovels by updating their source and destination URIs' 'verify' parameter."))
3049+
.after_help(color_print::cformat!(
3050+
r#"<bold>Doc guides</bold>:
3051+
3052+
* {}
3053+
* {}
3054+
* {}"#,
3055+
SHOVEL_GUIDE_URL,
3056+
TLS_GUIDE_URL,
3057+
"https://www.rabbitmq.com/docs/shovel#tls-connections"
3058+
));
3059+
30443060
[
30453061
list_all_cmd,
30463062
list_cmd,
30473063
declare_091_cmd,
30483064
declare_10_cmd,
30493065
delete_cmd,
3066+
disable_tls_peer_verification_cmd,
30503067
]
30513068
.map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
30523069
}
@@ -3387,9 +3404,9 @@ fn federation_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 7
33873404

33883405
let disable_tls_peer_verification_cmd = Command::new("disable_tls_peer_verification_for_all_upstreams")
33893406
// shorter, displayed in the federation group's help
3390-
.about(color_print::cstr!("<bold><red>Use only to undo incorrect URI changes</red></bold>. Disables TLS peer verification for all federation upstreams."))
3407+
.about(color_print::cstr!("<bold><red>Use only in emergency cases</red></bold>. Disables TLS peer verification for all federation upstreams."))
33913408
// longer, displayed in the command's help
3392-
.long_about(color_print::cstr!("<bold><red>Use only to undo incorrect URI changes</red></bold>. Disables TLS peer verification for all federation upstreams by updating their 'verify' parameter."))
3409+
.long_about(color_print::cstr!("<bold><red>Use only in emergency cases</red></bold>. Disables TLS peer verification for all federation upstreams by updating their 'verify' parameter."))
33933410

33943411
.after_help(color_print::cformat!(
33953412
r#"<bold>Doc guides</bold>:

src/commands.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rabbitmq_http_client::requests::{
3434
FEDERATION_UPSTREAM_COMPONENT, FederationResourceCleanupMode, FederationUpstreamParams,
3535
PolicyParams, QueueFederationParams, RuntimeParameterDefinition,
3636
};
37+
use rabbitmq_http_client::requests::shovels::OwnedShovelParams;
3738

3839
use rabbitmq_http_client::transformers::{TransformationChain, VirtualHostTransformationChain};
3940
use rabbitmq_http_client::{password_hashing, requests, responses};
@@ -732,6 +733,47 @@ pub fn disable_tls_peer_verification_for_all_federation_upstreams(
732733
Ok(())
733734
}
734735

736+
pub fn disable_tls_peer_verification_for_all_shovels(
737+
client: APIClient,
738+
) -> Result<(), CommandRunError> {
739+
// Get all runtime parameters of "shovel" component
740+
let all_params = client.list_runtime_parameters()?;
741+
let shovel_params: Vec<_> = all_params
742+
.into_iter()
743+
.filter(|p| p.component == "shovel")
744+
.collect();
745+
746+
for param in shovel_params {
747+
// Convert the runtime parameter to OwnedShovelParams for easier manipulation
748+
let owned_params = match OwnedShovelParams::try_from(param.clone()) {
749+
Ok(params) => params,
750+
Err(_) => continue, // Skip malformed shovel parameters
751+
};
752+
753+
let original_source_uri = &owned_params.source_uri;
754+
let original_destination_uri = &owned_params.destination_uri;
755+
756+
// Skip shovels with empty URIs
757+
if original_source_uri.is_empty() || original_destination_uri.is_empty() {
758+
continue;
759+
}
760+
761+
let updated_source_uri = disable_tls_peer_verification(original_source_uri)?;
762+
let updated_destination_uri = disable_tls_peer_verification(original_destination_uri)?;
763+
764+
if original_source_uri != &updated_source_uri || original_destination_uri != &updated_destination_uri {
765+
let mut updated_params = owned_params;
766+
updated_params.source_uri = updated_source_uri;
767+
updated_params.destination_uri = updated_destination_uri;
768+
769+
let param = RuntimeParameterDefinition::from(&updated_params);
770+
client.upsert_runtime_parameter(&param)?;
771+
}
772+
}
773+
774+
Ok(())
775+
}
776+
735777
//
736778
// Feature flags
737779
//

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,10 @@ fn dispatch_common_subcommand(
10711071
let result = commands::list_shovels_in(client, &vhost);
10721072
res_handler.tabular_result(result)
10731073
}
1074+
("shovels", "disable_tls_peer_verification_for_all_source_uris") => {
1075+
let result = commands::disable_tls_peer_verification_for_all_shovels(client);
1076+
res_handler.no_output_on_success(result);
1077+
}
10741078
("streams", "declare") => {
10751079
let result = commands::declare_stream(client, &vhost, second_level_args);
10761080
res_handler.no_output_on_success(result);

0 commit comments

Comments
 (0)