MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / build_proxy_env_vars

Method build_proxy_env_vars

src/docker/mod.rs:228–281  ·  view source on GitHub ↗

Build proxy environment variables for the container. When nested inside a TSK container, forwards env vars from the outer container. Otherwise, sets proxy env vars using the proxy config's container name and URL.

(
        &self,
        resolved: &crate::context::ResolvedConfig,
        proxy_config: &crate::context::ResolvedProxyConfig,
    )

Source from the content-addressed store, hash-verified

226 /// When nested inside a TSK container, forwards env vars from the outer container.
227 /// Otherwise, sets proxy env vars using the proxy config's container name and URL.
228 fn build_proxy_env_vars(
229 &self,
230 resolved: &crate::context::ResolvedConfig,
231 proxy_config: &crate::context::ResolvedProxyConfig,
232 ) -> Vec<String> {
233 if self.is_nested() {
234 // Forward proxy env vars from the outer container's environment.
235 // The outer TSK container already has network isolation via Docker.
236 let mut env = Vec::new();
237 for var in PROXY_ENV_VARS
238 .iter()
239 .copied()
240 .chain(["JAVA_TOOL_OPTIONS", "TSK_PROXY_HOST"])
241 {
242 if let Ok(val) = std::env::var(var) {
243 env.push(format!("{var}={val}"));
244 }
245 }
246 return env;
247 }
248
249 let proxy_url = proxy_config.proxy_url();
250 let proxy_container_name = proxy_config.proxy_container_name();
251 let mut env = vec![
252 format!("HTTP_PROXY={proxy_url}"),
253 format!("HTTPS_PROXY={proxy_url}"),
254 format!("http_proxy={proxy_url}"),
255 format!("https_proxy={proxy_url}"),
256 format!("NO_PROXY=localhost,127.0.0.1,{proxy_container_name}"),
257 format!("no_proxy=localhost,127.0.0.1,{proxy_container_name}"),
258 ];
259
260 // JVM proxy system properties via JAVA_TOOL_OPTIONS
261 // Maven and Gradle ignore HTTP_PROXY env vars, so this ensures all JVM
262 // processes route through the proxy. Harmless for non-Java containers.
263 env.push(format!(
264 "JAVA_TOOL_OPTIONS=-Dhttp.proxyHost={pcn} -Dhttp.proxyPort=3128 \
265 -Dhttps.proxyHost={pcn} -Dhttps.proxyPort=3128 \
266 -Dhttp.nonProxyHosts=localhost|127.0.0.1 \
267 -Dhttps.nonProxyHosts=localhost|127.0.0.1",
268 pcn = proxy_container_name
269 ));
270
271 // Always export the proxy container name so scripts (e.g. network
272 // isolation tests) can reach the proxy regardless of host_ports config.
273 env.push(format!("TSK_PROXY_HOST={proxy_container_name}"));
274
275 // Add host port environment variables if configured
276 if resolved.has_host_ports() {
277 env.push(format!("TSK_HOST_PORTS={}", resolved.host_ports_env()));
278 }
279
280 env
281 }
282
283 /// Remove a container with force option
284 async fn remove_container(&self, container_id: &str) -> Result<(), String> {

Callers 1

Calls 4

is_nestedMethod · 0.80
proxy_urlMethod · 0.80
proxy_container_nameMethod · 0.80
has_host_portsMethod · 0.80

Tested by

no test coverage detected