diff --git a/cliv2/cmd/cliv2/logheader.go b/cliv2/cmd/cliv2/logheader.go index b2891b4167..f4dc067b4c 100644 --- a/cliv2/cmd/cliv2/logheader.go +++ b/cliv2/cmd/cliv2/logheader.go @@ -80,6 +80,8 @@ func getFipsStatus(config configuration.Configuration) string { } func writeLogHeader(config configuration.Configuration, networkAccess networking.NetworkAccess) { + keys := []string{configuration.API_URL, configuration.AUTHENTICATION_TOKEN, configuration.AUTHENTICATION_BEARER_TOKEN, configuration.ORGANIZATION} + authorization, _, userAgent := logHeaderAuthorizationInfo(config, networkAccess) org := config.GetString(configuration.ORGANIZATION) @@ -116,4 +118,18 @@ func writeLogHeader(config configuration.Configuration, networkAccess networking tablePrint("Features", "") tablePrint(" preview", previewFeaturesEnabled) tablePrint(" fips", fipsEnabled) + tablePrint("Checks", "") + + checkCount := 0 + for _, key := range keys { + keysSpecified := config.GetAllKeysThatContainValues(key) + if len(keysSpecified) > 1 { + checkCount++ + tablePrint(" Configuration", fmt.Sprintf("Possible unexpected behavior, the following configuration values might override each other %s", strings.ToUpper(strings.Join(keysSpecified, ", ")))) + } + } + + if checkCount == 0 { + tablePrint(" Configuration", "all good") + } } diff --git a/cliv2/go.mod b/cliv2/go.mod index d5aec90343..c732d492b8 100644 --- a/cliv2/go.mod +++ b/cliv2/go.mod @@ -14,8 +14,8 @@ require ( github.com/snyk/cli-extension-iac-rules v0.0.0-20240422133948-ae17a4306672 github.com/snyk/cli-extension-sbom v0.0.0-20240722082449-69a631da39ad github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 - github.com/snyk/error-catalog-golang-public v0.0.0-20240715110939-a528e5c7d26d - github.com/snyk/go-application-framework v0.0.0-20240716082832-a722d639217c + github.com/snyk/error-catalog-golang-public v0.0.0-20240724122202-c7d3fb545c88 + github.com/snyk/go-application-framework v0.0.0-20240725135406-ef950283001b github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 github.com/snyk/snyk-iac-capture v0.6.5 github.com/snyk/snyk-ls v0.0.0-20240724110216-fff14d6d09e0 diff --git a/cliv2/go.sum b/cliv2/go.sum index 5d5c6e116e..378e0d7570 100644 --- a/cliv2/go.sum +++ b/cliv2/go.sum @@ -742,10 +742,10 @@ github.com/snyk/code-client-go v1.8.0 h1:6H883KAn7ybiSIxhvL2QR9yEyHgAwA2+9WVHMDN github.com/snyk/code-client-go v1.8.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s= github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1 h1:9RKY9NdX5DrJAoVXDP0JiqrXT+4Nb9NH8pjEcA0NsLA= github.com/snyk/container-cli v0.0.0-20240322120441-6d9b9482f9b1/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM= -github.com/snyk/error-catalog-golang-public v0.0.0-20240715110939-a528e5c7d26d h1:LtvOq6MD7Tei0xx0/41AMiDD5jfvjgJ7xGp7e9PL9fY= -github.com/snyk/error-catalog-golang-public v0.0.0-20240715110939-a528e5c7d26d/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4= -github.com/snyk/go-application-framework v0.0.0-20240716082832-a722d639217c h1:YFjWoOvvyBgOWrOrAFsB9A9LHbV0+S3c4gENWRS1p94= -github.com/snyk/go-application-framework v0.0.0-20240716082832-a722d639217c/go.mod h1:X7PyPo6Vuf+nlxkHmqvhg0suwHmx+I2quCNKFHdaHp4= +github.com/snyk/error-catalog-golang-public v0.0.0-20240724122202-c7d3fb545c88 h1:ZiFV5IDPI2p1wx1D3B2iSC/8nxTGvlKuyUekZlm1ptU= +github.com/snyk/error-catalog-golang-public v0.0.0-20240724122202-c7d3fb545c88/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4= +github.com/snyk/go-application-framework v0.0.0-20240725135406-ef950283001b h1:LOuM03NjJlUgz4pjV6OpvEPR0/94glwSfLkxF11wjF0= +github.com/snyk/go-application-framework v0.0.0-20240725135406-ef950283001b/go.mod h1:3DhXDHbBbGWRRZESbYVZyunyIDaet9SOtuOZCK7AC3g= github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk= github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg= github.com/snyk/policy-engine v0.30.11 h1:wUy5LMar2vccMbNM62MSBRdjAQAhAbIm7aNXXO+g2tk= diff --git a/test/jest/acceptance/snyk-config/snyk-config-environment.spec.ts b/test/jest/acceptance/snyk-config/snyk-config-environment.spec.ts index e56d820ec9..ef4aaf31b1 100644 --- a/test/jest/acceptance/snyk-config/snyk-config-environment.spec.ts +++ b/test/jest/acceptance/snyk-config/snyk-config-environment.spec.ts @@ -8,17 +8,27 @@ jest.setTimeout(1000 * 30); describe('snyk config environment', () => { let initialConfig: Record = {}; + const env = { ...process.env }; - beforeEach(async () => { + beforeAll(async () => { initialConfig = await getCliConfig(); + delete env.SNYK_TOKEN; + delete env.SNYK_API; + delete env.SNYK_CFG_ORG; }); - afterEach(async () => { + afterAll(async () => { await restoreCliConfig(initialConfig); }); + beforeEach(async () => { + await runSnykCLI(`config clear`); // start from a clean state + }); + it('successfully configure with a partial DNS name', async () => { - const { code, stderr } = await runSnykCLI(`config environment dev`); + const { code, stderr } = await runSnykCLI(`config environment dev`, { + env: env, + }); expect(stderr).toEqual(''); expect(code).toEqual(0); @@ -29,6 +39,9 @@ describe('snyk config environment', () => { it('successfully configure with a URL', async () => { const { code, stderr } = await runSnykCLI( `config environment https://api.dev.snyk.io`, + { + env: env, + }, ); expect(stderr).toEqual(''); expect(code).toEqual(0); @@ -38,10 +51,30 @@ describe('snyk config environment', () => { }); it('fail with an invalid env alias', async () => { + const { + code, + stderr, + } = await runSnykCLI(`config environment randomEnvName`, { env: env }); + expect(stderr).toEqual(''); + expect(code).toEqual(2); + }); + + it('fail with env var collision', async () => { + const { code, stderr } = await runSnykCLI(`config environment eu`, { + env: { ...env, SNYK_TOKEN: 'https://api.snyk.io' }, + }); + expect(stderr).toEqual(''); + expect(code).toEqual(2); + }); + + it('successfully configure by ignoring env var collisions', async () => { const { code, stderr } = await runSnykCLI( - `config environment randomEnvName`, + `config environment eu --no-check`, + { + env: { ...env, SNYK_TOKEN: 'https://api.snyk.io' }, + }, ); expect(stderr).toEqual(''); - expect(code).toEqual(2); + expect(code).toEqual(0); }); });