Skip to content

Commit

Permalink
Added new configuration 'use_proxy' (metalbear-co#2076)
Browse files Browse the repository at this point in the history
* Added new configuration 'use_proxy' that lets user disable usage of http/s proxy by mirrord even when env is set

* config docs

* Update mirrord/config/src/lib.rs

Co-authored-by: Michał Smolarek <[email protected]>

* aa.

* ..

* f.

---------

Co-authored-by: Michał Smolarek <[email protected]>
  • Loading branch information
aviramha and Razz4780 authored Nov 23, 2023
1 parent bd42d0c commit 78ba20a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/+use_proxy.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added new configuration 'use_proxy' that lets user disable usage of http/s proxy by mirrord even when env is set
8 changes: 8 additions & 0 deletions mirrord-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@
"boolean",
"null"
]
},
"use_proxy": {
"title": "use_proxy {#root-use_proxy}",
"description": "When disabled, mirrord will remove `HTTP[S]_PROXY` env variables before doing any network requests. This is useful when the system sets a proxy but you don't want mirrord to use it. This also applies to the mirrord process (as it just removes the env). If the remote pod sets this env, the mirrord process will still use it.",
"type": [
"boolean",
"null"
]
}
},
"additionalProperties": false,
Expand Down
9 changes: 9 additions & 0 deletions mirrord/cli/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ 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)
}
}
}

let (connect_info, mut connection) = create_and_connect(config, progress, analytics)
.await
.inspect_err(|_| analytics.set_error(AnalyticsError::AgentConnection))?;
Expand Down
11 changes: 11 additions & 0 deletions mirrord/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ pub struct LayerConfig {
/// # internal_proxy {#root-internal_proxy}
#[config(nested)]
pub internal_proxy: InternalProxyConfig,

/// ## use_proxy {#root-use_proxy}
///
/// When disabled, mirrord will remove `HTTP[S]_PROXY` env variables before
/// doing any network requests. This is useful when the system sets a proxy
/// but you don't want mirrord to use it.
/// This also applies to the mirrord process (as it just removes the env).
/// If the remote pod sets this env, the mirrord process will still use it.
#[config(env = "MIRRORD_PROXY", default = true)]
pub use_proxy: bool,
}

impl LayerConfig {
Expand Down Expand Up @@ -744,6 +754,7 @@ mod tests {
sip_binaries: None,
kube_context: None,
internal_proxy: None,
use_proxy: None,
};

assert_eq!(config, expect);
Expand Down

0 comments on commit 78ba20a

Please sign in to comment.