Skip to content

Commit

Permalink
feat: pass projectTags arg to snyk-iac-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilianna Papastefanou committed Aug 5, 2022
1 parent 1463f33 commit ae70c1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/test/iac/local-execution/index.ts
Expand Up @@ -153,7 +153,7 @@ export function removeFileContent({
};
}

function parseTags(options: IaCTestFlags) {
export function parseTags(options: IaCTestFlags) {
if (options.report) {
return generateTags(options);
}
Expand Down
5 changes: 4 additions & 1 deletion src/cli/commands/test/iac/v2/index.ts
Expand Up @@ -10,6 +10,7 @@ import { buildOutput } from '../../../../../lib/iac/test/v2/output';
import { getIacOrgSettings } from '../local-execution/org-settings/get-iac-org-settings';
import { Options, TestOptions } from '../../../../../lib/types';
import { generateProjectAttributes } from '../../../monitor';
import { parseTags } from '../local-execution';

export async function test(
paths: string[],
Expand Down Expand Up @@ -51,6 +52,7 @@ async function prepareTestConfig(

const org = (options.org as string) || config.org;
const orgSettings = await getIacOrgSettings(org);
const projectTags = parseTags(options);

const attributes = parseAttributes(options);

Expand All @@ -62,8 +64,9 @@ async function prepareTestConfig(
userRulesBundlePath: config.IAC_BUNDLE_PATH,
userPolicyEnginePath: config.IAC_POLICY_ENGINE_PATH,
severityThreshold: options.severityThreshold,
attributes,
report: !!options.report,
attributes,
projectTags,
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib/iac/test/v2/scan/index.ts
Expand Up @@ -98,6 +98,15 @@ function processFlags(
flags.push('-project-lifecycle', options.attributes.lifecycle.join(','));
}

if (options.projectTags) {
const stringifiedTags = options.projectTags
.map((tag) => {
return `${tag.key}=${tag.value}`;
})
.join(',');
flags.push('-project-tags', stringifiedTags);
}

if (options.report) {
flags.push('-report');
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/iac/test/v2/types.ts
@@ -1,6 +1,7 @@
import { IacOrgSettings } from '../../../../cli/commands/test/iac/local-execution/types';
import { SEVERITY } from '../../../snyk-test/legacy';
import { ProjectAttributes } from '../../../types';
import { Tag } from '../../../types';

export interface TestConfig {
paths: string[];
Expand All @@ -12,4 +13,5 @@ export interface TestConfig {
report: boolean;
severityThreshold?: SEVERITY;
attributes?: ProjectAttributes;
projectTags?: Tag[];
}

0 comments on commit ae70c1e

Please sign in to comment.