Skip to content

Commit

Permalink
fix: condition new JSON output only for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiu-snyk committed Jun 13, 2024
1 parent 9337513 commit 56882bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/lib/iac/test/v2/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IacTestError,
mapIacTestError,
} from '../../../snyk-test/iac-test-result';
import { previewFeaturesEnabled } from "../../../preview-features-enabled";

export interface Result {
meta: Meta;
Expand All @@ -29,7 +30,7 @@ export interface Result {
projectType: IacProjectType | State.InputTypeEnum;
ok: boolean;
infrastructureAsCodeIssues: IacIssue[];
infrastructureAsCodeSuccesses: IacSuccess[];
infrastructureAsCodeSuccesses?: IacSuccess[];
error?: string;
}

Expand Down Expand Up @@ -277,7 +278,8 @@ function vulnerabilitiesToResult(
projectType: kind,
ok: false,
infrastructureAsCodeIssues,
infrastructureAsCodeSuccesses,
// TODO: IAC-2962 - Remove conditional after the feature is GA
...(previewFeaturesEnabled() && { infrastructureAsCodeSuccesses }),
};
}

Expand Down
14 changes: 10 additions & 4 deletions src/lib/iac/test/v2/scan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import config from '../../../../config';
import { api, getOAuthToken } from '../../../../api-token';
import envPaths from 'env-paths';
import { restoreEnvProxy } from '../../../env-utils';
import { previewFeaturesEnabled } from "../../../../preview-features-enabled";

const debug = newDebug('snyk-iac');
const debugOutput = newDebug('snyk-iac:output');
Expand Down Expand Up @@ -123,10 +124,15 @@ function processFlags(
const flags = ['-bundle', rulesBundlePath, '-policy', policyPath];

flags.push('-output', outputPath);
// to reduce the size of the output
flags.push('-exclude-raw-results');
// required for infrastructureAsCodeSuccesses to be populated
flags.push('-include-passed-vulnerabilities');


// TODO: IAC-2962 - Remove condition after the feature is GA
if (previewFeaturesEnabled()) {
// to reduce the size of the output
flags.push('-exclude-raw-results');
// required for infrastructureAsCodeSuccesses to be populated
flags.push('-include-passed-vulnerabilities');
}

if (options.severityThreshold) {
flags.push('-severity-threshold', options.severityThreshold);
Expand Down
11 changes: 11 additions & 0 deletions test/jest/unit/lib/iac/test/v2/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import {
import { ScanError } from '../../../../../../../src/lib/iac/test/v2/scan/results';

describe('convertEngineToJsonResults', () => {
beforeAll(() => {
// TODO: IAC-2962 - Remove this after the feature is GA
process.env.SNYK_INTERNAL_PREVIEW_FEATURES = '1';
});


afterAll(() => {
// TODO: IAC-2962 - Remove this after the feature is GA
delete process.env.SNYK_INTERNAL_PREVIEW_FEATURES;
});

const snykIacTestFixtureContent = fs.readFileSync(
path.join(
__dirname,
Expand Down

0 comments on commit 56882bb

Please sign in to comment.