Skip to content

Commit

Permalink
feat: update mesa
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Sopena Ballesteros committed Jul 30, 2024
1 parent c583e0a commit e121298
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 23 additions & 8 deletions src/common/config_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::Serialize;

#[derive(Serialize)]
pub struct Site {
socks5_proxy: String,
socks5_proxy: Option<String>,
shasta_base_url: String,
k8s_api_url: String,
vault_base_url: String,
Expand Down Expand Up @@ -116,6 +116,7 @@ pub async fn get_config_file_path() -> config::File<FileSourceFile, FileFormat>
/// 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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ async fn main() -> core::result::Result<(), Box<dyn std::error::Error>> {
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();
Expand Down

0 comments on commit e121298

Please sign in to comment.