Skip to content

Commit a21a02a

Browse files
committed
Refactor 1
1 parent 818df44 commit a21a02a

25 files changed

+292
-404
lines changed

src/main/connect/connectionUtils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,6 @@ export class ConnectionUtils {
178178
return Promise.resolve('Successfully connected to Xray version: ' + xrayVersion);
179179
}
180180

181-
public static async testXrayVersionForScanGraph(jfrogClient: JfrogClient, logger: LogManager): Promise<boolean> {
182-
let xrayVersion: string = await this.getXrayVersion(jfrogClient);
183-
if (!(await this.isXrayVersionCompatible(xrayVersion, ConnectionUtils.MINIMAL_XRAY_VERSION_SUPPORTED))) {
184-
logger.logError(new Error('Dependencies scan is supported only on Xray >= 3.29.0'), true);
185-
return false;
186-
}
187-
return true;
188-
}
189-
190181
public static async testXrayEntitlementForFeature(jfrogClient: JfrogClient, feature: EntitlementScanFeature): Promise<boolean> {
191182
return await jfrogClient
192183
.xray()

src/main/scanLogic/scanManager.ts

Lines changed: 12 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@ import { IGraphResponse, XrayScanProgress } from 'jfrog-client-js';
1010
import { RootNode } from '../treeDataProviders/dependenciesTree/dependenciesRoot/rootTree';
1111
import { AnalyzerUtils } from '../treeDataProviders/utils/analyzerUtils';
1212
import { StepProgress } from '../treeDataProviders/utils/stepProgress';
13-
import { ExcludeScanner, Module } from '../types/jfrogAppsConfig';
14-
import { AppsConfigUtils } from '../utils/appConfigUtils';
1513
import { Configuration } from '../utils/configuration';
1614
import { Resource } from '../utils/resource';
1715
import { ScanUtils } from '../utils/scanUtils';
1816
import { Utils } from '../utils/utils';
1917
import { GraphScanLogic } from './scanGraphLogic';
2018
import { ApplicabilityRunner, ApplicabilityScanResponse } from './scanRunners/applicabilityScan';
21-
import { BinaryRunner } from './scanRunners/binaryRunner';
22-
import { IacRunner, IacScanResponse } from './scanRunners/iacScan';
23-
import { SastScanResponse, SastRunner } from './scanRunners/sastScan';
24-
import { SecretsRunner, SecretsScanResponse } from './scanRunners/secretsScan';
19+
import { JasScanner } from './scanRunners/binaryRunner';
2520

26-
export interface SupportedScans {
21+
export interface EntitledScans {
2722
dependencies: boolean;
2823
applicability: boolean;
2924
sast: boolean;
@@ -39,7 +34,7 @@ export class ScanManager implements ExtensionComponent {
3934
private static readonly RESOURCE_CHECK_UPDATE_INTERVAL_MILLISECS: number = 1000 * 60 * 60 * 24;
4035

4136
private static lastOutdatedCheck: number;
42-
private _supportedScans: SupportedScans = {} as SupportedScans;
37+
private _entitledScans: EntitledScans = {} as EntitledScans;
4338

4439
constructor(private _connectionManager: ConnectionManager, protected _logManager: LogManager) {}
4540

@@ -56,16 +51,16 @@ export class ScanManager implements ExtensionComponent {
5651
return this._connectionManager;
5752
}
5853

59-
public get supportedScans(): SupportedScans {
60-
return this._supportedScans;
54+
public get entitledScans(): EntitledScans {
55+
return this._entitledScans;
6156
}
6257

6358
/**
6459
* Updates all the resources that are outdated.
6560
* @param supportedScans - the supported scan to get the needed resources. if default, should call getSupportedScans before calling this method.
6661
* @returns true if all the outdated resources updated successfully, false otherwise
6762
*/
68-
public async updateResources(supportedScans: SupportedScans = this._supportedScans): Promise<boolean> {
63+
public async updateResources(supportedScans: EntitledScans = this._entitledScans): Promise<boolean> {
6964
let result: boolean = true;
7065
await ScanUtils.backgroundTask(async (progress: vscode.Progress<{ message?: string; increment?: number }>) => {
7166
progress.report({ message: 'Checking for updates' });
@@ -98,7 +93,7 @@ export class ScanManager implements ExtensionComponent {
9893
return result;
9994
}
10095

101-
private async getOutdatedResources(supportedScans: SupportedScans): Promise<Resource[]> {
96+
private async getOutdatedResources(supportedScans: EntitledScans): Promise<Resource[]> {
10297
if (!this.shouldCheckOutdated()) {
10398
return [];
10499
}
@@ -130,23 +125,16 @@ export class ScanManager implements ExtensionComponent {
130125
return !ScanManager.lastOutdatedCheck || Date.now() - ScanManager.lastOutdatedCheck > ScanManager.RESOURCE_CHECK_UPDATE_INTERVAL_MILLISECS;
131126
}
132127

133-
private getResources(supportedScans: SupportedScans): Resource[] {
128+
private getResources(supportedScans: EntitledScans): Resource[] {
134129
let resources: Resource[] = [];
135130
if (supportedScans.applicability || supportedScans.iac || supportedScans.secrets) {
136-
resources.push(BinaryRunner.getAnalyzerManagerResource(this._logManager));
131+
resources.push(JasScanner.getAnalyzerManagerResource(this._logManager));
137132
} else {
138133
this.logManager.logMessage('You are not entitled to run Advanced Security scans', 'DEBUG');
139134
}
140135
return resources;
141136
}
142137

143-
/**
144-
* Validate if the graph-scan is supported in the Xray version
145-
*/
146-
public async validateGraphSupported(): Promise<boolean> {
147-
return await ConnectionUtils.testXrayVersionForScanGraph(this._connectionManager.createJfrogClient(), this._logManager);
148-
}
149-
150138
/**
151139
* Check if Contextual Analysis (Applicability) is supported for the user
152140
*/
@@ -179,14 +167,9 @@ export class ScanManager implements ExtensionComponent {
179167
/**
180168
* Get all the entitlement status for each type of scan the manager offers
181169
*/
182-
public async getSupportedScans(): Promise<SupportedScans> {
183-
let supportedScans: SupportedScans = {} as SupportedScans;
170+
public async getSupportedScans(): Promise<EntitledScans> {
171+
let supportedScans: EntitledScans = {} as EntitledScans;
184172
let requests: Promise<any>[] = [];
185-
requests.push(
186-
this.validateGraphSupported()
187-
.then(res => (supportedScans.dependencies = res))
188-
.catch(err => ScanUtils.onScanError(err, this._logManager, true))
189-
);
190173
requests.push(
191174
this.isApplicabilitySupported()
192175
.then(res => (supportedScans.applicability = res))
@@ -208,7 +191,7 @@ export class ScanManager implements ExtensionComponent {
208191
.catch(err => ScanUtils.onScanError(err, this._logManager, true))
209192
);
210193
await Promise.all(requests);
211-
this._supportedScans = supportedScans;
194+
this._entitledScans = supportedScans;
212195
return supportedScans;
213196
}
214197

@@ -250,60 +233,4 @@ export class ScanManager implements ExtensionComponent {
250233
);
251234
return await applicableRunner.scan(directory, checkCancel, cveToRun, skipFiles);
252235
}
253-
254-
/**
255-
* Scan directory for 'Infrastructure As Code' (Iac) issues.
256-
* @param module - the module that will be scanned
257-
* @param checkCancel - check if should cancel
258-
* @returns the Iac scan response
259-
*/
260-
public async scanIac(module: Module, checkCancel: () => void): Promise<IacScanResponse | undefined> {
261-
let iacRunner: IacRunner = new IacRunner(this._connectionManager, this.logManager);
262-
if (!iacRunner.validateSupported()) {
263-
this._logManager.logMessage('Iac runner could not find binary to run', 'WARN');
264-
return undefined;
265-
}
266-
if (AppsConfigUtils.ShouldSkipScanner(module, ExcludeScanner.Iac)) {
267-
this._logManager.debug('Skipping IaC scanning');
268-
return undefined;
269-
}
270-
return await iacRunner.scan(module, checkCancel);
271-
}
272-
/**
273-
* Scan directory for secrets issues.
274-
* @param module - the module that will be scanned
275-
* @param checkCancel - check if should cancel
276-
* @returns the Secrets scan response
277-
*/
278-
public async scanSecrets(module: Module, checkCancel: () => void): Promise<SecretsScanResponse | undefined> {
279-
let secretsRunner: SecretsRunner = new SecretsRunner(this._connectionManager, this.logManager);
280-
if (!secretsRunner.validateSupported()) {
281-
this._logManager.logMessage('Secrets runner could not find binary to run', 'WARN');
282-
return undefined;
283-
}
284-
if (AppsConfigUtils.ShouldSkipScanner(module, ExcludeScanner.Secrets)) {
285-
this._logManager.debug('Skipping secrets scanning');
286-
return undefined;
287-
}
288-
return await secretsRunner.scan(module, checkCancel);
289-
}
290-
291-
/**
292-
* Scan for SAST issues.
293-
* @param module - the module that will be scanned
294-
* @param requests - the SAST requests to run
295-
* @returns the scan response
296-
*/
297-
public async scanSast(module: Module, checkCancel: () => void): Promise<SastScanResponse | undefined> {
298-
let sastRunner: SastRunner = new SastRunner(this._connectionManager, this._logManager);
299-
if (!sastRunner.validateSupported()) {
300-
this._logManager.logMessage('Sast runner could not find binary to run', 'WARN');
301-
return undefined;
302-
}
303-
if (AppsConfigUtils.ShouldSkipScanner(module, ExcludeScanner.Sast)) {
304-
this._logManager.debug('Skipping SAST scanning');
305-
return undefined;
306-
}
307-
return sastRunner.scan(module, checkCancel);
308-
}
309236
}

src/main/scanLogic/scanRunners/applicabilityScan.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { LogManager } from '../../log/logManager';
2-
import { BinaryRunner } from './binaryRunner';
3-
import { AnalyzeIssue, AnalyzeLocation, AnalyzerScanRun, ScanType, AnalyzeScanRequest, FileIssues } from './analyzerModels';
41
import { ConnectionManager } from '../../connect/connectionManager';
2+
import { LogManager } from '../../log/logManager';
3+
import { Module } from '../../types/jfrogAppsConfig';
54
import { Resource } from '../../utils/resource';
65
import { ScanUtils } from '../../utils/scanUtils';
7-
import { PackageType } from '../../types/projectType';
6+
import { AnalyzeIssue, AnalyzeLocation, AnalyzeScanRequest, AnalyzerScanRun, FileIssues, ScanType } from './analyzerModels';
7+
import { JasScanner } from './binaryRunner';
88

99
/**
1010
* The request that is sent to the binary to scan applicability
@@ -38,18 +38,14 @@ export interface CveApplicableDetails {
3838
/**
3939
* Describes a runner for the Applicability scan executable file.
4040
*/
41-
export class ApplicabilityRunner extends BinaryRunner {
41+
export class ApplicabilityRunner extends JasScanner {
4242
constructor(
4343
connectionManager: ConnectionManager,
4444
logManager: LogManager,
4545
binary?: Resource,
4646
timeout: number = ScanUtils.ANALYZER_TIMEOUT_MILLISECS
4747
) {
48-
super(connectionManager, timeout, ScanType.ContextualAnalysis, logManager, binary);
49-
}
50-
51-
public static supportedPackageTypes(): PackageType[] {
52-
return [PackageType.Npm, PackageType.Yarn, PackageType.Python, PackageType.Maven];
48+
super(connectionManager, timeout, ScanType.ContextualAnalysis, logManager, {} as Module, binary);
5349
}
5450

5551
/** @override */

0 commit comments

Comments
 (0)