Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge internal and external (user defined) no_proxy #4263

Merged
merged 1 commit into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cliv2/go.mod
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/uuid v1.3.0
github.com/pkg/errors v0.9.1
github.com/snyk/cli-extension-sbom v0.0.0-20221212093410-6b474ed1a42a
github.com/snyk/go-application-framework v0.0.0-20221215182111-b2d10cf1e146
github.com/snyk/go-application-framework v0.0.0-20221229122623-b3cc236e9f58
github.com/snyk/go-httpauth v0.0.0-20220915135832-0edf62cf8cdd
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Expand Up @@ -184,8 +184,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/snyk/cli-extension-sbom v0.0.0-20221212093410-6b474ed1a42a h1:kImXWA4kbwaREeC+kaJ8H0aOukWzpK8K/UzAsExj6MU=
github.com/snyk/cli-extension-sbom v0.0.0-20221212093410-6b474ed1a42a/go.mod h1:ohrrgC94Gx82/cgSiac02JQrsMjFtggvhAvXGuGjDGU=
github.com/snyk/go-application-framework v0.0.0-20221215182111-b2d10cf1e146 h1:V5kc8tSGVhyiPNuEXkZ9CVmwWiYlMmaQGpjRbORuqlU=
github.com/snyk/go-application-framework v0.0.0-20221215182111-b2d10cf1e146/go.mod h1:5hLGqObbxLWnZkhn3Xc5PblESjQOfjN509ucQ4dtqz8=
github.com/snyk/go-application-framework v0.0.0-20221229122623-b3cc236e9f58 h1:lRYloO4hulZTT3391WYezDJgpXj7uUb0vndFHqJCB68=
github.com/snyk/go-application-framework v0.0.0-20221229122623-b3cc236e9f58/go.mod h1:5hLGqObbxLWnZkhn3Xc5PblESjQOfjN509ucQ4dtqz8=
github.com/snyk/go-httpauth v0.0.0-20220915135832-0edf62cf8cdd h1:zjDhcQ642rIVI8aIjfG5uVcw+OGotQtX2l9VHe7IqCQ=
github.com/snyk/go-httpauth v0.0.0-20220915135832-0edf62cf8cdd/go.mod h1:v6t6wKizOcHXT3p4qKn6Bda7yNIjCQ54Xyl31NjgXkY=
github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw=
Expand Down
42 changes: 36 additions & 6 deletions cliv2/internal/cliv2/cliv2.go
Expand Up @@ -11,13 +11,14 @@ import (
"os"
"os/exec"
"path"
"regexp"
"strings"

"github.com/snyk/cli/cliv2/internal/constants"
"github.com/snyk/cli/cliv2/internal/embedded"
"github.com/snyk/cli/cliv2/internal/embedded/cliv1"
"github.com/snyk/cli/cliv2/internal/proxy"
"github.com/snyk/cli/cliv2/internal/utils"
"github.com/snyk/go-application-framework/pkg/utils"
)

type Handler int
Expand Down Expand Up @@ -249,7 +250,16 @@ func PrepareV1EnvironmentVariables(input []string, integrationName string, integ
inputAsMap[constants.SNYK_HTTPS_PROXY_ENV] = proxyAddress
inputAsMap[constants.SNYK_HTTP_PROXY_ENV] = proxyAddress
inputAsMap[constants.SNYK_CA_CERTIFICATE_LOCATION_ENV] = caCertificateLocation
inputAsMap[constants.SNYK_HTTP_NO_PROXY_ENV] = constants.SNYK_INTERNAL_NO_PROXY

// merge user defined (external) and internal no_proxy configuration
if len(inputAsMap[constants.SNYK_HTTP_NO_PROXY_ENV_SYSTEM]) > 0 {
internalNoProxy := strings.Split(constants.SNYK_INTERNAL_NO_PROXY, ",")
externalNoProxy := regexp.MustCompile("[,;]").Split(inputAsMap[constants.SNYK_HTTP_NO_PROXY_ENV_SYSTEM], -1)
mergedNoProxy := utils.Merge(internalNoProxy, externalNoProxy)
inputAsMap[constants.SNYK_HTTP_NO_PROXY_ENV] = strings.Join(mergedNoProxy, ",")
} else {
inputAsMap[constants.SNYK_HTTP_NO_PROXY_ENV] = constants.SNYK_INTERNAL_NO_PROXY
}

result = utils.ToSlice(inputAsMap, "=")
}
Expand All @@ -268,8 +278,6 @@ func PrepareV1Command(cmd string, args []string, proxyInfo *proxy.ProxyInfo, int
}

func (c *CLI) executeV1Default(proxyInfo *proxy.ProxyInfo, passthroughArgs []string) error {
c.DebugLogger.Println("launching snyk with path: ", c.v1BinaryLocation)
c.DebugLogger.Println("CertificateLocation:", proxyInfo.CertificateLocation)

snykCmd, err := PrepareV1Command(
c.v1BinaryLocation,
Expand All @@ -279,6 +287,30 @@ func (c *CLI) executeV1Default(proxyInfo *proxy.ProxyInfo, passthroughArgs []str
GetFullVersion(),
)

if c.DebugLogger.Writer() != io.Discard {
c.DebugLogger.Println("Launching: ")
c.DebugLogger.Println(" ", c.v1BinaryLocation)
c.DebugLogger.Println(" With Arguments:")
c.DebugLogger.Println(" ", strings.Join(passthroughArgs, ", "))
c.DebugLogger.Println(" With Environment: ")

variablesMap := utils.ToKeyValueMap(snykCmd.Env, "=")
listedEnvironmentVariables := []string{
constants.SNYK_CA_CERTIFICATE_LOCATION_ENV,
constants.SNYK_HTTPS_PROXY_ENV,
constants.SNYK_HTTP_PROXY_ENV,
constants.SNYK_HTTP_NO_PROXY_ENV,
constants.SNYK_HTTPS_PROXY_ENV_SYSTEM,
constants.SNYK_HTTP_PROXY_ENV_SYSTEM,
constants.SNYK_HTTP_NO_PROXY_ENV_SYSTEM,
}

for _, key := range listedEnvironmentVariables {
c.DebugLogger.Println(" ", key, "=", variablesMap[key])
}

}

snykCmd.Stdin = c.stdin
snykCmd.Stdout = c.stdout
snykCmd.Stderr = c.stderr
Expand All @@ -295,8 +327,6 @@ func (c *CLI) executeV1Default(proxyInfo *proxy.ProxyInfo, passthroughArgs []str
}

func (c *CLI) Execute(proxyInfo *proxy.ProxyInfo, passthroughArgs []string) error {
c.DebugLogger.Println("passthroughArgs", passthroughArgs)

var err error
handler := determineHandler(passthroughArgs)

Expand Down
4 changes: 2 additions & 2 deletions cliv2/internal/cliv2/cliv2_test.go
Expand Up @@ -41,7 +41,7 @@ func Test_PrepareV1EnvironmentVariables_Fill_and_Filter(t *testing.T) {
"SNYK_SYSTEM_NO_PROXY=noProxy",
"SNYK_SYSTEM_HTTP_PROXY=httpProxy",
"SNYK_SYSTEM_HTTPS_PROXY=httpsProxy",
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY,
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY + ",noProxy",
}

actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation")
Expand Down Expand Up @@ -93,7 +93,7 @@ func Test_PrepareV1EnvironmentVariables_OverrideProxyAndCerts(t *testing.T) {
"SNYK_SYSTEM_NO_PROXY=312123",
"SNYK_SYSTEM_HTTP_PROXY=exists",
"SNYK_SYSTEM_HTTPS_PROXY=already",
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY,
"NO_PROXY=" + constants.SNYK_INTERNAL_NO_PROXY + ",312123",
}

actual, err := cliv2.PrepareV1EnvironmentVariables(input, "foo", "bar", "proxy", "cacertlocation")
Expand Down
22 changes: 0 additions & 22 deletions cliv2/internal/utils/api_tokens.go

This file was deleted.

93 changes: 0 additions & 93 deletions cliv2/internal/utils/array.go

This file was deleted.

3 changes: 2 additions & 1 deletion cliv2/pkg/basic_workflows/legacycli.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/snyk/cli/cliv2/internal/proxy"
"github.com/snyk/cli/cliv2/internal/utils"
"github.com/snyk/go-application-framework/pkg/configuration"
pkg_utils "github.com/snyk/go-application-framework/pkg/utils"
"github.com/snyk/go-application-framework/pkg/workflow"
"github.com/snyk/go-httpauth/pkg/httpauth"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -38,7 +39,7 @@ func FilteredArgs(args []string) []string {
elementsToFilter := []string{"--" + PROXY_NOAUTH}
filteredArgs := args
for _, element := range elementsToFilter {
filteredArgs = utils.RemoveSimilar(filteredArgs, element)
filteredArgs = pkg_utils.RemoveSimilar(filteredArgs, element)
}
return filteredArgs
}
Expand Down