Skip to content

Commit

Permalink
Merge pull request #3351 from snyk/chore/cliv2_noproxy_filtering
Browse files Browse the repository at this point in the history
chore: override no_proxy from parent env before launching cliv1
  • Loading branch information
PeterSchafer authored Jun 22, 2022
2 parents 0b90441 + 5d72a8e commit d1a7702
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
16 changes: 16 additions & 0 deletions cliv2/internal/cliv2/cliv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const SNYK_INTEGRATION_NAME_ENV = "SNYK_INTEGRATION_NAME"
const SNYK_INTEGRATION_VERSION_ENV = "SNYK_INTEGRATION_VERSION"
const SNYK_HTTPS_PROXY_ENV = "HTTPS_PROXY"
const SNYK_HTTP_PROXY_ENV = "HTTP_PROXY"
const SNYK_HTTP_NO_PROXY_ENV = "NO_PROXY"
const SNYK_NPM_PROXY_ENV = "NPM_CONFIG_PROXY"
const SNYK_NPM_HTTPS_PROXY_ENV = "NPM_CONFIG_HTTPS_PROXY"
const SNYK_NPM_HTTP_PROXY_ENV = "NPM_CONFIG_HTTP_PROXY"
const SNYK_NPM_NO_PROXY_ENV = "NPM_CONFIG_NO_PROXY"
const SNYK_NPM_ALL_PROXY = "ALL_PROXY"
const SNYK_CA_CERTIFICATE_LOCATION_ENV = "NODE_EXTRA_CA_CERTS"

const (
Expand Down Expand Up @@ -159,6 +165,16 @@ func PrepareV1EnvironmentVariables(input []string, integrationName string, integ
inputAsMap[SNYK_HTTPS_PROXY_ENV] = proxyAddress
inputAsMap[SNYK_HTTP_PROXY_ENV] = proxyAddress
inputAsMap[SNYK_CA_CERTIFICATE_LOCATION_ENV] = caCertificateLocation

// ensure that no existing no_proxy or other configuration causes redirecting internal communication that is meant to stay between cliv1 and cliv2
inputAsMap[SNYK_HTTP_NO_PROXY_ENV] = ""
inputAsMap[SNYK_NPM_NO_PROXY_ENV] = ""
inputAsMap[SNYK_NPM_HTTPS_PROXY_ENV] = ""
inputAsMap[SNYK_NPM_HTTP_PROXY_ENV] = ""
inputAsMap[SNYK_NPM_PROXY_ENV] = ""
inputAsMap[SNYK_NPM_ALL_PROXY] = ""

inputAsMap = utils.RemoveEmptyValue(inputAsMap)
result = utils.ToSlice(inputAsMap, "=")
}

Expand Down
11 changes: 10 additions & 1 deletion cliv2/internal/cliv2/cliv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ import (

func Test_PrepareV1EnvironmentVariables_Fill(t *testing.T) {

input := []string{"something=1", "in=2", "here=3=2"}
input := []string{"something=1",
"in=2",
"here=3=2",
"NO_PROXY=something",
"NPM_CONFIG_PROXY=something",
"NPM_CONFIG_HTTPS_PROXY=something",
"NPM_CONFIG_HTTP_PROXY=something",
"NPM_CONFIG_NO_PROXY=something",
"ALL_PROXY=something",
}
expected := []string{"something=1", "in=2", "here=3=2", "SNYK_INTEGRATION_NAME=foo", "SNYK_INTEGRATION_VERSION=bar", "HTTP_PROXY=proxy", "HTTPS_PROXY=proxy", "NODE_EXTRA_CA_CERTS=cacertlocation"}

actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation")
Expand Down
12 changes: 12 additions & 0 deletions cliv2/internal/utils/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ func ToSlice(input map[string]string, combineBy string) []string {

return result
}

func RemoveEmptyValue(input map[string]string) map[string]string {
result := make(map[string]string)

for key, value := range input {
if len(value) > 0 {
result[key] = value
}
}

return result
}

0 comments on commit d1a7702

Please sign in to comment.