Skip to content

Commit

Permalink
mention about wrong proxy config via env variable in error msg
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anjannath authored and praveenkumar committed Nov 7, 2023
1 parent da1d72e commit c0bcd48
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/crc/network/httpproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ProxyConfig struct {
noProxy []string
ProxyCACert string
ProxyCAFile string
fromEnv bool
}

func (p *ProxyConfig) String() string {
Expand Down Expand Up @@ -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
Expand All @@ -87,6 +91,7 @@ func NewProxyConfig() (*ProxyConfig, error) {
HTTPSProxy: DefaultProxy.HTTPSProxy,
ProxyCACert: DefaultProxy.ProxyCACert,
ProxyCAFile: DefaultProxy.ProxyCAFile,
fromEnv: DefaultProxy.fromEnv,
}

config.noProxy = defaultNoProxies
Expand All @@ -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
}

Expand Down

0 comments on commit c0bcd48

Please sign in to comment.