-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support IaC configs test (K8s only)
- Loading branch information
Showing
10 changed files
with
350 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import chalk from 'chalk'; | ||
import * as Debug from 'debug'; | ||
import { Options, TestOptions } from '../../../lib/types'; | ||
import { CloudConfigTestResult } from '../../../lib/snyk-test/cloud-config-test-result'; | ||
import { getSeverityValue } from './formatters'; | ||
import { formatIssue } from './formatters/remediation-based-format-issues'; | ||
import { AnnotatedCloudConfigIssue } from '../../../lib/snyk-test/cloud-config-test-result'; | ||
|
||
const debug = Debug('cloud-config-output'); | ||
|
||
export function getCloudConfigDisplayedOutput( | ||
res: CloudConfigTestResult, | ||
testOptions: Options & TestOptions, | ||
testedInfoText: string, | ||
meta: string, | ||
prefix: string, | ||
): string { | ||
const issuesTextArray = [ | ||
chalk.bold.white('\nInfrastructure as code issues:'), | ||
]; | ||
|
||
const NoNote = false; | ||
const NotNew = false; | ||
|
||
const issues: AnnotatedCloudConfigIssue[] = res.result.cloudConfigResults; | ||
debug(`iac display output - ${issues.length} issues`); | ||
|
||
issues | ||
.sort((a, b) => getSeverityValue(b.severity) - getSeverityValue(a.severity)) | ||
.forEach((issue) => { | ||
const path: string[][] = [issue.cloudConfigPath]; | ||
issuesTextArray.push( | ||
formatIssue( | ||
issue.id, | ||
issue.title, | ||
issue.severity, | ||
NotNew, | ||
issue.subType, | ||
path, | ||
testOptions, | ||
NoNote, | ||
), | ||
); | ||
}); | ||
|
||
const issuesInfoOutput: string[] = []; | ||
debug(`Cloud Config display output - ${issuesTextArray.length} issues text`); | ||
if (issuesTextArray.length > 0) { | ||
issuesInfoOutput.push(issuesTextArray.join('\n')); | ||
} | ||
|
||
let body = issuesInfoOutput.join('\n\n') + '\n\n' + meta; | ||
|
||
const vulnCountText = `found ${issues.length} issues`; | ||
const summary = testedInfoText + ', ' + chalk.red.bold(vulnCountText); | ||
|
||
body = body + '\n\n' + summary; | ||
|
||
return prefix + body; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { BasicResultData, SEVERITY } from './legacy'; | ||
|
||
export interface AnnotatedCloudConfigIssue { | ||
id: string; | ||
title: string; | ||
description: string; | ||
severity: SEVERITY; | ||
isIgnored: boolean; | ||
cloudConfigPath: string[]; | ||
type: string; | ||
subType: string; | ||
} | ||
|
||
export interface CloudConfigTestResult extends BasicResultData { | ||
targetFile: string; | ||
projectName: string; | ||
displayTargetFile: string; // used for display only | ||
foundProjectCount: number; | ||
result: { | ||
cloudConfigResults: AnnotatedCloudConfigIssue[]; | ||
projectType: string; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//TODO(orka): future - change this file | ||
import { SupportedCloudConfigs } from '../cloud-config/cloud-config-projects'; | ||
|
||
interface Scan { | ||
type: string; | ||
targetFile: string; | ||
data: any; | ||
} | ||
|
||
export interface CloudConfigFile { | ||
fileContent: string; | ||
fileType: 'yaml' | 'yml' | 'json'; | ||
} | ||
|
||
export interface CloudConfigScan extends Scan { | ||
type: SupportedCloudConfigs; | ||
targetFile: string; | ||
data: CloudConfigFile; | ||
targetFileRelativePath: string; | ||
originalProjectName: string; | ||
policy: string; | ||
projectNameOverride?: string; | ||
} |
Oops, something went wrong.