From e12129874243503c4e168fb57c370cd75eec6edc Mon Sep 17 00:00:00 2001 From: Manuel Sopena Ballesteros Date: Wed, 31 Jul 2024 00:22:49 +0200 Subject: [PATCH] feat: update mesa --- Cargo.toml | 2 +- src/common/config_ops.rs | 31 +++++++++++++++++++++++-------- src/main.rs | 7 +++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4421bdcc..6d4c0fc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ publish = false # cargo # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -mesa = "0.40.4" +mesa = "0.40.6" # mesa = { path = "../mesa" } # Only for development purposes strum = "0.25.0" strum_macros = "0.25" diff --git a/src/common/config_ops.rs b/src/common/config_ops.rs index 52b43b22..10feb726 100644 --- a/src/common/config_ops.rs +++ b/src/common/config_ops.rs @@ -12,7 +12,7 @@ use serde::Serialize; #[derive(Serialize)] pub struct Site { - socks5_proxy: String, + socks5_proxy: Option, shasta_base_url: String, k8s_api_url: String, vault_base_url: String, @@ -116,6 +116,7 @@ pub async fn get_config_file_path() -> config::File /// defiend, then environment variables takes preference pub async fn get_configuration() -> Config { // Get config file path + let config_file = get_config_file_path().await; // Process config file @@ -233,13 +234,27 @@ pub async fn create_new_config_file(config_file_path_opt: Option<&PathBuf>) { .interact_text() .unwrap(); - // Get the right socks5 proxy value based on if client can reach backend api or not - let socks5_proxy = Input::new() - .with_prompt("Note: If CSM backend API is not reacheable, then you may need a SOCKS5 proxy.\nPlease type socks5 proxy URL") - .with_initial_text("socks5h://127.0.0.1:1080".to_string()) - .allow_empty(true) - .interact_text() - .unwrap(); + println!("Testing connectivity to CSM backend, please wait ..."); + + let test_backend_api = + mesa::common::authentication::test_connectivity_to_backend(&shasta_base_url).await; + + let mut socks5_proxy = if test_backend_api { + println!("This machine can access CSM API, no need to setup SOCKS5 proxy"); + None + } else { + println!("This machine cannot access CSM API, configuring SOCKS5 proxy"); + + // Get the right socks5 proxy value based on if client can reach backend api or not + Some( + Input::new() + .with_prompt("Please type socks5 proxy URL") + .default("socks5h://127.0.0.1:1080".to_string()) + .allow_empty(true) + .interact_text() + .unwrap(), + ) + }; let site_details = Site { socks5_proxy, diff --git a/src/main.rs b/src/main.rs index efedd3de..64112efc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,8 +74,11 @@ async fn main() -> core::result::Result<(), Box> { log_ops::configure(log_level, audit_file_path.as_str()); // log4rs programatically configuration if let Some(socks_proxy) = site_detail_value.get("socks5_proxy") { - std::env::set_var("SOCKS5", socks_proxy.to_string()); - log::info!("SOCKS5 enabled: {:?}", std::env::var("SOCKS5")); + let socks_proxy = socks_proxy.to_string(); + if !socks_proxy.is_empty() { + std::env::set_var("SOCKS5", socks_proxy.to_string()); + log::info!("SOCKS5 enabled: {:?}", std::env::var("SOCKS5")); + } } let settings_hsm_group_name_opt = settings.get_string("hsm_group").ok();