Skip to content

Commit

Permalink
feat: pass policy (.snyk) to iac-test via the config file.
Browse files Browse the repository at this point in the history
This commit adds the policy file to the config file. We use the existing "policy" library to find and load the policy file.
We have decided that we can only have one .snyk file per repo, so even if we scan multiple paths, we will use the current working directory to load the .snyk file from the root of the project.
  • Loading branch information
Ilianna Papastefanou committed Aug 23, 2022
1 parent 02f422a commit 6d3ad76
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/cli/commands/test/iac/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { parseTags } from '../local-execution';
import { systemCachePath } from '../../../../../lib/iac/test/v2/scan';
import { getFlag } from '../index';
import { IaCTestFlags } from '../local-execution/types';
import { findAndLoadPolicy } from '../../../../../lib/policy';

export async function test(
paths: string[],
Expand Down Expand Up @@ -58,6 +59,7 @@ async function prepareTestConfig(
const targetName = getFlag(options, 'target-name');
const remoteRepoUrl = getFlag(options, 'remote-repo-url');
const attributes = parseAttributes(options);
const policy = await findAndLoadPolicy(process.cwd(), 'iac', options);

return {
paths,
Expand All @@ -72,6 +74,7 @@ async function prepareTestConfig(
targetReference: options['target-reference'],
targetName,
remoteRepoUrl,
policy: policy?.toString(),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/iac/test/v2/scan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function createConfig(options: TestConfig): string {
apiUrl: config.API,
apiAuth: getAuthHeader(),
allowAnalytics: allowAnalytics(),
policy: options.policy,
});

fs.writeFileSync(tempConfig, configData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as os from 'os';

const policyEngineChecksums = `4f86b8133caa3e27410c853a910a41551a92de3c6402891fc22d8306185a170a snyk-iac-test_0.21.1_Windows_arm64.exe
58b617385dcb1f7da100c1c04e50260d98dbee6811eda9575fc0a41367f9222e snyk-iac-test_0.21.1_Windows_x86_64.exe
6fdd0b0d944bc4986a061d1eec404c6ef5cc7cc5ce4d9a3755b3dd24aa89af57 snyk-iac-test_0.21.1_Darwin_x86_64
80dc9ab2b4b51df29d4a3edd994a394c1c62d6c1f2d364ce98e1b5365a05f855 snyk-iac-test_0.21.1_Linux_arm64
b06f169fc03f6e6c3c7047c9270c6b7b20496070122ed3babeedd7e568c98009 snyk-iac-test_0.21.1_Linux_x86_64
c98a06db1bafa683cc479ecf77e7191eb94ece82dfdf9c229ac7258e73094f10 snyk-iac-test_0.21.1_Darwin_arm64
const policyEngineChecksums = `0313de2afa00ed6301e8cadbe344e448085c6e94cb0e87a06264b908c3c5e2de snyk-iac-test_0.22.0_Windows_x86_64.exe
031416e2714ba2bfe85bb294f588eebc20b028dae2222b1929df2072fd01028d snyk-iac-test_0.22.0_Windows_arm64.exe
03dcc3b16f1d84f80346aaf05fe7f8a5f8099af765c9979e8f36ee4b9cee4fb3 snyk-iac-test_0.22.0_Darwin_x86_64
54d0a20a209c45f948f147e4280650b366b4f8252b042fe4a30bec832fe3f915 snyk-iac-test_0.22.0_Darwin_arm64
cb0d714746310cda42914163572e39c4e4f044342d54695ac901d80e03c9ecf8 snyk-iac-test_0.22.0_Linux_x86_64
f95568949342bf7f33285500022a9ee0f3d64fc6dd601f16ce9b654e43cb6de6 snyk-iac-test_0.22.0_Linux_arm64
`;

export const policyEngineVersion = getPolicyEngineVersion();

export function formatPolicyEngineFileName(releaseVersion: string) {
export function formatPolicyEngineFileName(releaseVersion: string): string {
let platform = 'Linux';
switch (os.platform()) {
case 'darwin':
Expand Down
4 changes: 2 additions & 2 deletions src/lib/iac/test/v2/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IacOrgSettings } from '../../../../cli/commands/test/iac/local-execution/types';
import { SEVERITY } from '../../../snyk-test/legacy';
import { ProjectAttributes } from '../../../types';
import { Tag } from '../../../types';
import { ProjectAttributes, Tag } from '../../../types';

export interface TestConfig {
paths: string[];
Expand All @@ -16,4 +15,5 @@ export interface TestConfig {
targetReference?: string;
targetName?: string;
remoteRepoUrl?: string;
policy?: string;
}

0 comments on commit 6d3ad76

Please sign in to comment.