Skip to content

Commit

Permalink
use_proxy configuration now applies to more commands (#2256)
Browse files Browse the repository at this point in the history
* use_proxy configuration now applies to mirrord operator status, and mirrord ls

* add missing file
  • Loading branch information
aviramha authored Feb 22, 2024
1 parent ce7e55a commit e7a6f3a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/+use-proxy-applies-to-more.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use_proxy configuration now applies to mirrord operator status, and mirrord ls
8 changes: 2 additions & 6 deletions mirrord/cli/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
connection::{create_and_connect, AgentConnection, AGENT_CONNECT_INFO_ENV_KEY},
error::CliError,
extract::extract_library,
util::remove_proxy_env,
Result,
};

Expand Down Expand Up @@ -134,12 +135,7 @@ impl MirrordExecution {
let lib_path = extract_library(None, progress, true)?;

if !config.use_proxy {
for (key, _val) in std::env::vars() {
let lower_key = key.to_lowercase();
if lower_key == "http_proxy" || lower_key == "https_proxy" {
std::env::remove_var(key)
}
}
remove_proxy_env();
}

let (connect_info, mut connection) = create_and_connect(config, progress, analytics)
Expand Down
6 changes: 6 additions & 0 deletions mirrord/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ mod extract;
mod internal_proxy;
mod operator;
mod teams;
mod util;
mod verify_config;

pub(crate) use error::{CliError, Result};
use verify_config::verify_config;

use crate::util::remove_proxy_env;

async fn exec_process<P>(
config: LayerConfig,
args: &ExecArgs,
Expand Down Expand Up @@ -339,6 +342,9 @@ async fn print_pod_targets(args: &ListTargetArgs) -> Result<()> {
{
let mut cfg_context = ConfigContext::default();
let layer_config = LayerFileConfig::from_path(config)?.generate_config(&mut cfg_context)?;
if !layer_config.use_proxy {
remove_proxy_env();
}
(
layer_config.accept_invalid_certificates,
layer_config.kubeconfig,
Expand Down
4 changes: 4 additions & 0 deletions mirrord/cli/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use tracing::warn;
use crate::{
config::{OperatorArgs, OperatorCommand},
error::CliError,
util::remove_proxy_env,
Result,
};

Expand Down Expand Up @@ -111,6 +112,9 @@ async fn get_status_api(config: Option<String>) -> Result<Api<MirrordOperatorCrd
let kube_api = if let Some(config_path) = config {
let mut cfg_context = ConfigContext::default();
let config = LayerFileConfig::from_path(config_path)?.generate_config(&mut cfg_context)?;
if !config.use_proxy {
remove_proxy_env();
}
create_kube_api(
config.accept_invalid_certificates,
config.kubeconfig,
Expand Down
9 changes: 9 additions & 0 deletions mirrord/cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// Removes `HTTP_PROXY` and `https_proxy` from the environment
pub(crate) fn remove_proxy_env() {
for (key, _val) in std::env::vars() {
let lower_key = key.to_lowercase();
if lower_key == "http_proxy" || lower_key == "https_proxy" {
std::env::remove_var(key)
}
}
}

0 comments on commit e7a6f3a

Please sign in to comment.