Skip to content

Commit

Permalink
[PCSUP-24582] VisualStudioCode - single file exception error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChananM committed Sep 5, 2024
1 parent 4c4fc57 commit 33e8e1a
Show file tree
Hide file tree
Showing 25 changed files with 279 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/*.ts
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Change Log

## [1.0.20] - 2024-09-05

### Fixed

- Fixed an issue where standalone files couldn't be scanned
- Fixed an issue where opening issues from the Prisma Cloud side panel didn't work

## [1.0.19] - 2024-08-29

### Added

- Added the following data to Prisma Cloid analytics
- Added the following data to Prisma Cloud analytics

- Extension version
- VS Code version
Expand Down
45 changes: 28 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
"repository": "https://github.com/bridgecrewio/prisma-cloud-vscode-plugin",
"icon": "static/icons/prisma.png",
"description": "a static code analysis tool to scan code for Infrastructure-as-Code (IaC) misconfigurations, Software Composition Analysis (SCA) issues and Secrets vulnerabilities.",
"version": "1.0.19",
"version": "1.0.20",
"engines": {
"vscode": "^1.79.0"
},
"categories": [
"Other"
],
"activationEvents": [
"*"
"onStartupFinished"
],
"main": "./out/extension.js",
"files": [
"out",
"static"
],
"contributes": {
"viewsContainers": {
"activitybar": [
Expand Down Expand Up @@ -272,7 +268,7 @@
"typescript": "^5.1.6"
},
"dependencies": {
"axios": "^1.5.1",
"axios": "^1.7.4",
"semver": "^7.5.2",
"uuid": "^9.0.1",
"winston": "^3.13.0"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/checkov/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,4 @@ export class CheckovInstall {
return `"${join(dirname(envPath), 'checkov')}"`;
}
}
};
}
16 changes: 9 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import * as vscode from 'vscode';

import { registerCommands } from './commands';
import { CONFIG } from './config';
import { COMMAND } from './constants';
import { registerWindowEvents, registerWorkspaceEvents } from './events';
import logger, { initiateLogger } from './logger';
import { initializeServices } from './services';
import { registerSidebar } from './views/interface/primarySidebar';
import { registerCheckovResultView } from './views/interface/checkovResult';
import { registerCustomHighlight, lineClickDisposable } from './services/customPopupService';
import { initializeInstallationId } from './utils';
import { initiateLogger } from './logger';
import { initializeAnalyticsService } from './services/analyticsService';
import { CustomersModulesService, initializeCustomersModulesService } from './services/customersModulesService';
import { initializeAuthenticationService } from './services/authenticationService';
import { CustomersModulesService, initializeCustomersModulesService } from './services/customersModulesService';
import { lineClickDisposable, registerCustomHighlight } from './services/customPopupService';
import { initializeInstallationId } from './utils';
import { registerCheckovResultView } from './views/interface/checkovResult';
import { registerSidebar } from './views/interface/primarySidebar';

export async function activate(context: vscode.ExtensionContext) {
initiateLogger(context.logUri.fsPath);

logger.info(`Initiating Prisma Cloud VS Code extension version ${vscode.extensions.getExtension(CONFIG.extensionId)?.packageJSON.version}`);
logger.info(`Plugin path: ${context.extensionPath}`);
initializeInstallationId(context);
CustomersModulesService.loadCachedData(context);
await initializeAuthenticationService(context);
Expand Down
21 changes: 12 additions & 9 deletions src/services/checkov/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CheckovExecutor {
const executor = CheckovExecutor.executors.get(installation.type);
executor ?
CheckovExecutor.actualCheckovVersion = await CheckovExecutor.executors.get(installation.type)?.getCheckovVersion(installation) :
logger.error(`No executor found for ${installation.type}, can't determine Checkov version`);
logger.error(`No executor found for ${installation?.type}, can't determine Checkov version`);
}

public static getExecutor() {
Expand All @@ -53,7 +53,7 @@ export class CheckovExecutor {
}

if (!executor) {
logger.error(`No executor found for ${installation.type}, aborting scan operation`);
logger.error(`No executor found for ${installation?.type}, aborting scan operation`);
return;
}

Expand All @@ -62,6 +62,11 @@ export class CheckovExecutor {
return;
}

if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1 && !targetFiles) {
vscode.window.showWarningMessage('Full scan is only supported when working with a single VS Code workspace');
return;
}

const emptyPrismaSettings = CheckovExecutor.getEmptyPrismaSettings();

if (!emptyPrismaSettings.length) {
Expand All @@ -76,12 +81,12 @@ export class CheckovExecutor {
try {
checkovOutput = await executor.execute(installation, targetFiles);
} catch (e: any) {
logger.info(`The Checkov execution was failed due to: ${e.message}`);
logger.info(`Checkov execution failed due to: ${e.message}`);
AbstractExecutor.isScanInProgress = false;
await reRenderViews();
StatusBar.reset();
if (!shouldDisableErrorMessage()) {
vscode.window.showErrorMessage(`Scanning is stopped due to: ${e.message}`);
vscode.window.showErrorMessage(`Scanning stopped due to: ${e.message}`);
}
return;
}
Expand Down Expand Up @@ -124,18 +129,16 @@ export class CheckovExecutor {

private static processOutput(output: CheckovOutput) {
if (Array.isArray(output)) {
const failedChecks = output.reduce((acc: CheckovResult[], checkType) => {
return output.reduce((acc: CheckovResult[], checkType) => {
if (checkType) {
for (const check of checkType.results.failed_checks) {
check.check_type = checkType.check_type;
check.id = uuidv4();
check.severity = check.severity || SEVERITY.INFO;
};
}
}
return acc.concat(checkType?.results.failed_checks ?? []);
}, []);

return failedChecks;
}

// response from checkov with EmptyCheckovOutput type
Expand Down Expand Up @@ -169,4 +172,4 @@ export class CheckovExecutor {
public static get checkovVersion() {
return CheckovExecutor.actualCheckovVersion;
}
};
}
30 changes: 21 additions & 9 deletions src/services/checkov/executors/DockerExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { getCertificate, getPrismaApiUrl, getProxyConfigurations } from '../../.
import logger from '../../../logger';
import { CheckovInstallation } from '../../../types';
import { asyncExec, isWindows } from '../../../utils';
import { parseUri } from '../../../utils/fileUtils';
import { reRenderViews } from '../../../views/interface/utils';
import { AbstractExecutor } from './abstractExecutor';
import * as path from 'path';

export class DockerExecutor extends AbstractExecutor {

Expand All @@ -28,7 +30,7 @@ export class DockerExecutor extends AbstractExecutor {
...DockerExecutor.getDockerParams(),
...containerName,
...DockerExecutor.getEnvs(),
...DockerExecutor.getVolumeMounts(),
...DockerExecutor.getVolumeMounts(files),
...DockerExecutor.getWorkdir(),
...DockerExecutor.getImage(),
...(await DockerExecutor.getCheckovCliParams(installation, DockerExecutor.fixFilePaths(files))),
Expand Down Expand Up @@ -90,12 +92,19 @@ export class DockerExecutor extends AbstractExecutor {
return envs;
}

private static getVolumeMounts() {
let volume = `${DockerExecutor.projectPath}:${DockerExecutor.projectPath}`;
const volumeMounts = [
'--volume', volume
];

private static getVolumeMounts(files?: string[]) {
const volumeMounts = [];
if (files) {
files.forEach(file => {
const dir = path.dirname(file);
volumeMounts.push('--volume', `"${dir}":"${dir}"`);
});
} else if (vscode.workspace.workspaceFolders) {
const dir = parseUri(vscode.workspace.workspaceFolders[0].uri);
volumeMounts.push('--volume', `${dir}:${dir}`);
} else {
AbstractExecutor.projectPaths.forEach(path => volumeMounts.push('--volume', `${path}:${path}`));
}
const cert = getCertificate();
if (cert) {
volumeMounts.push('--volume', `${cert}:${CONFIG.checkov.docker.certificateMountPath}`);
Expand All @@ -105,7 +114,10 @@ export class DockerExecutor extends AbstractExecutor {
}

private static getWorkdir() {
return ['--workdir', DockerExecutor.projectPath!];
if (vscode.workspace.workspaceFolders) {
return ['--workdir', parseUri(vscode.workspace.workspaceFolders[0].uri)];
}
return [];
}

private static getImage() {
Expand All @@ -128,5 +140,5 @@ export class DockerExecutor extends AbstractExecutor {
const {stdout} = await asyncExec(`${installation.entrypoint} ${args.join(' ')}`);
return stdout.trim();
}
};
}

Loading

0 comments on commit 33e8e1a

Please sign in to comment.