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

feat: Add support for severity threshold [CFG-1991] #3451

Merged
merged 1 commit into from
Jul 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli/commands/test/iac/local-execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ export enum IaCErrorCodes {
CwdTraversal = 2003,
NoBundle = 2004,
OpenBundle = 2005,
InvalidSeverityThreshold = 2006,
Scan = 2100,
UnableToRecognizeInputType = 2101,
UnsupportedInputType = 2102,
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ async function prepareTestConfig(
orgSettings,
userRulesBundlePath: config.IAC_BUNDLE_PATH,
userPolicyEnginePath: config.IAC_POLICY_ENGINE_PATH,
severityThreshold: options.severityThreshold,
};
}
2 changes: 2 additions & 0 deletions src/lib/iac/test/v2/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const snykIacTestErrorsUserMessages = {
'Running the scan from outside of the current working directory is not supported',
NoBundle: 'A rules bundle were not provided',
OpenBundle: "The Snyk CLI couldn't open the rules bundle",
InvalidSeverityThreshold:
'The provided severity threshold is invalid. The following values are supported: "low", "medium", "high", "critical"',
Scan: defaultUserMessage,
UnableToRecognizeInputType: 'Input type was not recognized',
UnsupportedInputType: 'Input type is not supported',
Expand Down
8 changes: 7 additions & 1 deletion src/lib/iac/test/v2/scan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export function scan(
policyEnginePath: string,
rulesBundlePath: string,
): SnykIacTestOutput {
const args = ['-bundle', rulesBundlePath, ...options.paths];
const args = ['-bundle', rulesBundlePath];

if (options.severityThreshold) {
args.push('-severity-threshold', options.severityThreshold);
}

args.push(...options.paths);

const process = childProcess.spawnSync(policyEnginePath, args, {
encoding: 'utf-8',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/iac/test/v2/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IacOrgSettings } from '../../../../cli/commands/test/iac/local-execution/types';
import { SEVERITY } from '../../../snyk-test/legacy';

export interface TestConfig {
paths: string[];
Expand All @@ -7,4 +8,5 @@ export interface TestConfig {
userPolicyEnginePath?: string;
projectName: string;
orgSettings: IacOrgSettings;
severityThreshold?: SEVERITY;
}