From c0bcd4863774e4c1c1c1b1b39a4c129c140e49b0 Mon Sep 17 00:00:00 2001 From: Anjan Nath Date: Wed, 1 Nov 2023 13:40:46 +0530 Subject: [PATCH] mention about wrong proxy config via env variable in error msg when proxy config is picked up from the env variables this modifies the error message to inform user to check and correct the proxy urls in the env variables --- pkg/crc/network/httpproxy/proxy.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/crc/network/httpproxy/proxy.go b/pkg/crc/network/httpproxy/proxy.go index 42513d146c..f6eae3b0ce 100644 --- a/pkg/crc/network/httpproxy/proxy.go +++ b/pkg/crc/network/httpproxy/proxy.go @@ -29,6 +29,7 @@ type ProxyConfig struct { noProxy []string ProxyCACert string ProxyCAFile string + fromEnv bool } func (p *ProxyConfig) String() string { @@ -62,14 +63,17 @@ func NewProxyDefaults(httpProxy, httpsProxy, noProxy, proxyCAFile string) (*Prox HTTPSProxy: httpsProxy, ProxyCACert: proxyCAData, ProxyCAFile: proxyCAFile, + fromEnv: false, } envProxy := httpproxy.FromEnvironment() - if DefaultProxy.HTTPProxy == "" { + if DefaultProxy.HTTPProxy == "" && envProxy.HTTPProxy != "" { DefaultProxy.HTTPProxy = envProxy.HTTPProxy + DefaultProxy.fromEnv = true } - if DefaultProxy.HTTPSProxy == "" { + if DefaultProxy.HTTPSProxy == "" && envProxy.HTTPSProxy != "" { DefaultProxy.HTTPSProxy = envProxy.HTTPSProxy + DefaultProxy.fromEnv = true } if noProxy == "" { noProxy = envProxy.NoProxy @@ -87,6 +91,7 @@ func NewProxyConfig() (*ProxyConfig, error) { HTTPSProxy: DefaultProxy.HTTPSProxy, ProxyCACert: DefaultProxy.ProxyCACert, ProxyCAFile: DefaultProxy.ProxyCAFile, + fromEnv: DefaultProxy.fromEnv, } config.noProxy = defaultNoProxies @@ -96,11 +101,17 @@ func NewProxyConfig() (*ProxyConfig, error) { err := ValidateProxyURL(config.HTTPProxy, false) if err != nil { + if config.fromEnv { + return nil, fmt.Errorf("Please check HTTP_PROXY env variable: %w", err) + } return nil, err } err = ValidateProxyURL(config.HTTPSProxy, true) if err != nil { + if config.fromEnv { + return nil, fmt.Errorf("Please check HTTPS_PROXY env variable: %w", err) + } return nil, err }