Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: snyk/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.931.0
Choose a base ref
...
head repository: snyk/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.932.0
Choose a head ref
  • 10 commits
  • 27 files changed
  • 6 contributors

Commits on May 13, 2022

  1. fix: allow endpoint to be modified when invalid

    Currently when an invalid endpoint is configured, `snyk config` (and any other command) will fail early and prevent changes.
    This is because config validation is done during module resolution rather than application flow.
    
    This fix avoids that by logging warnings instead of failing during module import. A more robust fix will require re-designing CLI's configuration flow.
    Jahed Ahmed committed May 13, 2022

    Unverified

    No user is associated with the committer email.
    Copy the full SHA
    a4bc484 View commit details

Commits on May 16, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    37db7e6 View commit details
  2. Merge pull request #3246 from snyk/update-driftctl-v0.30

    Bump driftctl version to v0.30.0
    sundowndev-snyk authored May 16, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    27369f7 View commit details
  3. fix: CLI output styling

    teodora-sandu committed May 16, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    teodora-sandu Teodora Sandu
    Copy the full SHA
    0e31b8e View commit details
  4. Merge pull request #3225 from snyk/fix/correct-iac-colours

    fix: new CLI output styling [CFG-1841]
    teodora-sandu authored May 16, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aaf9570 View commit details

Commits on May 17, 2022

  1. Merge pull request #3236 from snyk/fix/config-endpoint

    fix: allow endpoint to be modified when invalid
    Jahed Ahmed authored May 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b33122f View commit details

Commits on May 18, 2022

  1. chore(ci): split versioning from build

    Build job needs to be split, but we only want to version bump once.
    
    This change introduces a Makefile for CLIv1 which will gradually grow to include more build steps.
    Jahed Ahmed committed May 18, 2022

    Unverified

    No user is associated with the committer email.
    Copy the full SHA
    8b508bf View commit details
  2. Merge pull request #3249 from snyk/chore/ci-split-version

    chore(ci): split versioning from build
    Jahed Ahmed authored May 18, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b16aa64 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    ofekatr Ofek A
    Copy the full SHA
    4f0276b View commit details
  4. Merge pull request #3250 from snyk/chore/add-new-output-env-var

    chore: Add a temporary `IAC_OUTPUT_V2` configuration for New CLI Output
    ofekatr authored May 18, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    403d2d1 View commit details
Showing with 358 additions and 352 deletions.
  1. +24 −5 .circleci/config.yml
  2. +20 −0 Makefile
  3. +2 −3 release-scripts/make-binaries.sh
  4. +16 −0 release-scripts/next-version.sh
  5. +2 −11 release-scripts/prepare-packages-for-release.sh
  6. +5 −5 src/cli/commands/test/iac/index.ts
  7. +8 −5 src/cli/commands/test/iac/local-execution/rules.ts
  8. +4 −2 src/lib/config.ts
  9. +0 −10 src/lib/errors/invalid-endpoint-config-error.ts
  10. +2 −1 src/lib/formatters/iac-output/index.ts
  11. +4 −3 src/lib/formatters/iac-output/v2/failures/list.ts
  12. +2 −2 src/lib/formatters/iac-output/v2/failures/tip.ts
  13. +2 −1 src/lib/formatters/iac-output/v2/index.ts
  14. +3 −3 src/lib/formatters/iac-output/v2/issues-list/index.ts
  15. +13 −9 src/lib/formatters/iac-output/v2/issues-list/issue.ts
  16. +1 −1 src/lib/formatters/iac-output/v2/share-results.ts
  17. +1 −1 src/lib/formatters/iac-output/v2/test-summary.ts
  18. +11 −4 src/lib/formatters/iac-output/v2/user-messages.ts
  19. +10 −6 src/lib/formatters/iac-output/v2/{color-utils.ts → utils.ts}
  20. +11 −11 src/lib/iac/drift/driftctl.ts
  21. +22 −27 test/jest/acceptance/iac/iac-output.spec.ts
  22. +73 −0 test/jest/acceptance/snyk-config/snyk-config-endpoint.spec.ts
  23. +40 −41 test/jest/unit/lib/formatters/iac-output/v2/failures/list.spec.ts
  24. +80 −80 test/jest/unit/lib/formatters/iac-output/v2/issues-list/index.spec.ts
  25. +1 −1 test/jest/unit/lib/formatters/iac-output/v2/share-results.spec.ts
  26. +1 −1 test/jest/unit/lib/formatters/iac-output/v2/test-summary.spec.ts
  27. +0 −119 test/tap/endpoint-config.test.ts
29 changes: 24 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -277,6 +277,20 @@ jobs:
- dist/
- packages/*/dist
- pysrc
version:
executor: docker-node
steps:
- checkout
- attach_workspace:
at: .
- setup_npm
- run:
name: Deciding version
command: make binary-releases/version
- persist_to_workspace:
root: .
paths:
- binary-releases/version
regression-test:
parameters:
test_snyk_command:
@@ -764,19 +778,24 @@ workflows:
context: nodejs-install
requires:
- Build
- build-artifacts:
name: Build Artifacts
context:
- snyk-cli-pgp-signing
- version:
name: Version
requires:
- Build
- Install
filters:
branches:
only:
- /^chore\/.+$/
- /^.*test.*$/
- /^.*v2.*$/
- master
- build-artifacts:
name: Build Artifacts
context:
- snyk-cli-pgp-signing
requires:
- Build
- Version
- test-windows:
name: Acceptance Tests (snyk-win.exe)
context: nodejs-install
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!make
#
# This Makefile is only for building release artifacts. Use `npm run` for CLIv1 scripts.
#
# Documentation: https://www.gnu.org/software/make/manual/make.html
#

# First target is default when running `make`.
.PHONY: help
help:
@echo 'Usage: make <target>'
@echo
@echo 'This Makefile is currently only for building release artifacts.'
@echo 'Use `npm run` for CLIv1 scripts.'

binary-releases:
mkdir binary-releases

binary-releases/version: | binary-releases
./release-scripts/next-version.sh > binary-releases/version
5 changes: 2 additions & 3 deletions release-scripts/make-binaries.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

mkdir binary-releases
# Do not run this file locally. To build release artifacts, see CONTRIBUTING.

mv "$(npm pack --workspace '@snyk/fix')" binary-releases/snyk-fix.tgz
mv "$(npm pack --workspace '@snyk/protect')" binary-releases/snyk-protect.tgz
@@ -48,8 +48,7 @@ gpg --clear-sign --local-user=1F4B9569 --passphrase="$SNYK_CODE_SIGNING_GPG_PASS
cat sha256sums.txt.asc
popd

BUILD_VERSION="$(jq -r '.version' package.json)"
echo "${BUILD_VERSION}" > binary-releases/version
BUILD_VERSION="$(cat binary-releases/version)"

cp ./release-scripts/release.json binary-releases/release.json
if [[ $(uname -s) == "Darwin" ]];then
16 changes: 16 additions & 0 deletions release-scripts/next-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
# Checks the latest version of Snyk CLI on npm and decides the next version.
# Only output the next version to stdout. All other output should go to stderr.

CURRENT_VERSION="$(npm view snyk version)"
RELEASE_BRANCH="master"
if [ "${CIRCLE_BRANCH:-}" == "${RELEASE_BRANCH}" ]; then
NEXT_VERSION="$(npx semver "${CURRENT_VERSION}" -i minor)"
else
NEXT_VERSION="${CURRENT_VERSION}-dev.$(git rev-parse HEAD)"
fi
echo "Current version: ${CURRENT_VERSION}" 1>&2
echo "Next version: ${NEXT_VERSION}" 1>&2

echo "${NEXT_VERSION}"
13 changes: 2 additions & 11 deletions release-scripts/prepare-packages-for-release.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail

CURRENT_VERSION="$(npm view snyk version)"
RELEASE_BRANCH="master"
if [ "${CIRCLE_BRANCH}" == "${RELEASE_BRANCH}" ]; then
NEXT_VERSION="$(npx semver "${CURRENT_VERSION}" -i minor)"
else
NEXT_VERSION="${CURRENT_VERSION}-dev.$(git rev-parse HEAD)"
fi
echo "Current version: ${CURRENT_VERSION}"
echo "Next version: ${NEXT_VERSION}"

npm version "${NEXT_VERSION}" --no-git-tag-version --workspaces --include-workspace-root
BUILD_VERSION="$(cat binary-releases/version)"
npm version "${BUILD_VERSION}" --no-git-tag-version --workspaces --include-workspace-root
npx ts-node ./release-scripts/prune-dependencies-in-packagejson.ts
10 changes: 5 additions & 5 deletions src/cli/commands/test/iac/index.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,6 @@ import {
getIacDisplayErrorFileOutput,
iacTestTitle,
shouldLogUserMessages,
spinnerFailureMessage,
spinnerMessage,
spinnerSuccessMessage,
} from '../../../../lib/formatters/iac-output';
@@ -86,7 +85,8 @@ export default async function(
let iacIgnoredIssuesCount = 0;
let iacOutputMeta: IacOutputMeta | undefined;

const isNewIacOutputSupported = await hasFeatureFlag('iacCliOutput', options);
const isNewIacOutputSupported =
config.IAC_OUTPUT_V2 || (await hasFeatureFlag('iacCliOutput', options));

if (shouldLogUserMessages(options, isNewIacOutputSupported)) {
console.log(EOL + iacTestTitle + EOL);
@@ -102,10 +102,10 @@ export default async function(
}

try {
testSpinner?.start(spinnerMessage);

const rulesOrigin = await initRules(iacOrgSettings, options);

testSpinner?.start(spinnerMessage);

for (const path of paths) {
// Create a copy of the options so a specific test can
// modify them i.e. add `options.file` etc. We'll need
@@ -197,7 +197,7 @@ export default async function(
if (isPartialSuccess) {
testSpinner?.succeed(spinnerSuccessMessage);
} else {
testSpinner?.fail(spinnerFailureMessage + EOL);
testSpinner?.stop();
}

// resultOptions is now an array of 1 or more options used for
13 changes: 8 additions & 5 deletions src/cli/commands/test/iac/local-execution/rules.ts
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ import {
OCIRegistryURLComponents,
RulesOrigin,
} from './types';
import { EOL } from 'os';
import { UnsupportedEntitlementFlagError } from './assert-iac-options-flag';
import chalk from 'chalk';
import {
extractOCIRegistryURLComponents,
FailedToBuildOCIArtifactError,
@@ -21,6 +21,10 @@ import { config as userConfig } from '../../../../../lib/user-config';
import { isValidUrl } from './url-utils';
import { CustomError } from '../../../../../lib/errors';
import { getErrorStringCode } from './error-utils';
import {
customRulesMessage,
customRulesReportMessage,
} from '../../../../../lib/formatters/iac-output';

export async function initRules(
iacOrgSettings: IacOrgSettings,
@@ -46,14 +50,13 @@ export async function initRules(
(isOCIRegistryURLProvided || customRulesPath) &&
!(options.sarif || options.json)
) {
let userMessage = 'Using custom rules to generate misconfigurations.';
let userMessage = `${customRulesMessage}${EOL}`;

if (options.report) {
userMessage +=
"\nPlease note that your custom rules will not be sent to the Snyk platform, and will not be available on the project's page.";
userMessage += `${customRulesReportMessage}${EOL}`;
}

console.log(chalk.hex('#ff9b00')(userMessage));
console.log(userMessage);
}

if (isOCIRegistryURLProvided && customRulesPath) {
6 changes: 4 additions & 2 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as snykConfig from 'snyk-config';
import { InvalidEndpointConfigError } from './errors/invalid-endpoint-config-error';
import { config as userConfig } from './user-config';
import * as url from 'url';

@@ -24,6 +23,7 @@ interface Config {
DRIFTCTL_PATH?: string;
DRIFTCTL_URL?: string;
IAC_BUNDLE_PATH?: string;
IAC_OUTPUT_V2?: boolean;
}

// TODO: fix the types!
@@ -37,7 +37,9 @@ if (endpoint && endpoint !== config.API) {
const parsedEndpoint = url.parse(endpoint);
// Endpoint option must be a valid URL including protocol
if (!parsedEndpoint || !parsedEndpoint.protocol || !parsedEndpoint.host) {
throw new InvalidEndpointConfigError();
console.warn(
"Invalid 'endpoint' config option. Endpoint must be a full and valid URL including protocol and for Snyk.io it should contain path to '/api'",
);
}
console.warn(
'Using a custom API endpoint from `snyk config` (tip: it should contain path to `/api`):',
10 changes: 0 additions & 10 deletions src/lib/errors/invalid-endpoint-config-error.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/lib/formatters/iac-output/index.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,8 @@ export {
iacTestTitle,
spinnerMessage,
spinnerSuccessMessage,
spinnerFailureMessage,
customRulesMessage,
customRulesReportMessage,
shouldLogUserMessages,
formatShareResultsOutput,
failuresTipOutput,
7 changes: 4 additions & 3 deletions src/lib/formatters/iac-output/v2/failures/list.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EOL } from 'os';

import { IacFileInDirectory } from '../../../../types';
import { colors } from '../color-utils';
import { colors, contentPadding } from '../utils';

export function formatIacTestFailures(testFailures: IacFileInDirectory[]) {
const sectionComponents: string[] = [];

const titleOutput = colors.info.bold(`Test Failures`);
const titleOutput = colors.title(`Test Failures`);
sectionComponents.push(titleOutput);

const testFailuresListOutput = formatFailuresList(testFailures);
@@ -49,10 +49,11 @@ function formatFailure(
failureReason: string,
testFailures: IacFileInDirectory[],
): string {
const pathPrefix = 'Path: ';
const pathPrefix = contentPadding + 'Path: ';
const pathLeftPadding = ' '.repeat(pathPrefix.length);

return (
contentPadding +
colors.failure.bold(failureReason) +
EOL +
pathPrefix +
4 changes: 2 additions & 2 deletions src/lib/formatters/iac-output/v2/failures/tip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EOL } from 'os';
import { contactSupportMessage, reTryMessage } from '../../../../common';
import { colors } from '../color-utils';
import { colors } from '../utils';

export const failuresTipOutput = colors.failure.bold(
export const failuresTipOutput = colors.info.bold(
reTryMessage + EOL + contactSupportMessage,
);
3 changes: 2 additions & 1 deletion src/lib/formatters/iac-output/v2/index.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ export {
iacTestTitle,
spinnerMessage,
spinnerSuccessMessage,
spinnerFailureMessage,
shouldLogUserMessages,
customRulesMessage,
customRulesReportMessage,
} from './user-messages';
export { formatShareResultsOutput } from './share-results';
export { formatIacTestFailures, failuresTipOutput } from './failures';
6 changes: 3 additions & 3 deletions src/lib/formatters/iac-output/v2/issues-list/index.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import * as isEmpty from 'lodash.isempty';
import * as debug from 'debug';

import { IacOutputMeta } from '../../../../types';
import { colors } from '../color-utils';
import { colors, contentPadding } from '../utils';
import { formatScanResultsNewOutput } from './formatters';
import { formatIssue } from './issue';
import { SEVERITY } from '../../../../snyk-test/common';
@@ -23,7 +23,7 @@ export function getIacDisplayedIssues(
return (
titleOutput +
EOL +
' '.repeat(2) +
contentPadding +
colors.success.bold('No vulnerable paths were found!')
);
}
@@ -34,7 +34,7 @@ export function getIacDisplayedIssues(
const severityResults: FormattedOutputResult[] =
formattedResults.results[severity];

const titleOutput = colors.severities[severity](
const titleOutput = colors.title(
`${capitalize(severity)} Severity Issues: ${severityResults.length}`,
);

22 changes: 13 additions & 9 deletions src/lib/formatters/iac-output/v2/issues-list/issue.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { EOL } from 'os';
import { iacRemediationTypes } from '../../../../iac/constants';

import { printPath } from '../../../remediation-based-format-issues';
import { colors } from '../color-utils';
import { colors, contentPadding } from '../utils';
import { FormattedOutputResult } from './types';
import { AnnotatedIacIssue } from '../../../../snyk-test/iac-test-result';

@@ -13,7 +13,13 @@ export function formatIssue(result: FormattedOutputResult): string {

const propertiesOutput = formatProperties(result);

return titleOutput + EOL + propertiesOutput;
return (
contentPadding +
titleOutput +
EOL +
contentPadding +
propertiesOutput.join(EOL + contentPadding)
);
}

function formatTitle(issue: AnnotatedIacIssue): string {
@@ -25,7 +31,7 @@ function formatTitle(issue: AnnotatedIacIssue): string {
return titleOutput;
}

function formatProperties(result: FormattedOutputResult): string {
function formatProperties(result: FormattedOutputResult): string[] {
const remediationKey = iacRemediationTypes?.[result.projectType];

const properties = [
@@ -55,10 +61,8 @@ function formatProperties(result: FormattedOutputResult): string {
...properties.map(([key]) => key.length),
);

return properties
.map(
([key, value]) =>
`${key}: ${' '.repeat(maxPropertyNameLength - key.length)}${value}`,
)
.join(EOL);
return properties.map(
([key, value]) =>
`${key}: ${' '.repeat(maxPropertyNameLength - key.length)}${value}`,
);
}
2 changes: 1 addition & 1 deletion src/lib/formatters/iac-output/v2/share-results.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IacOutputMeta } from '../../../types';
import { shareResultsOutput } from '../v1';
import { colors } from './color-utils';
import { colors } from './utils';

export function formatShareResultsOutput(outputMeta: IacOutputMeta) {
return colors.info.bold(shareResultsOutput(outputMeta));
2 changes: 1 addition & 1 deletion src/lib/formatters/iac-output/v2/test-summary.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import { rightPadWithSpaces } from '../../../right-pad';
import { SEVERITY } from '../../../snyk-test/common';
import { icon } from '../../../theme';
import { IacOutputMeta } from '../../../types';
import { colors } from './color-utils';
import { colors } from './utils';
import { IacTestData } from './types';

const PAD_LENGTH = 19; // chars to align
Loading