Skip to content

Commit

Permalink
Improve updaet logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Or-Geva committed Nov 2, 2023
1 parent 751d887 commit e593b3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/connect/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class ConnectionManager implements ExtensionComponent, vscode.Disposable
return false;
}
if (this.areCompleteCredentialsSet()) {
return ConnectionUtils.checkArtifactoryConnection(
return await ConnectionUtils.checkArtifactoryConnection(
this._rtUrl,
this._username,
this._password,
Expand Down
33 changes: 12 additions & 21 deletions src/main/scanLogic/scanRunners/analyzerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AnalyzerManager {
public static readonly JF_RELEASES_REPO: string = 'JF_RELEASES_REPO';

protected _binary: Resource;
private static FINISH_UPDATE_PROMISE: Promise<void>;
private static FINISH_UPDATE_PROMISE: Promise<boolean>;

constructor(private _connectionManager: ConnectionManager, protected _logManager: LogManager) {
this._binary = new Resource(this.getUrlPath(), this.getDefaultTargetPath(), _logManager, this.createJFrogCLient());
Expand Down Expand Up @@ -83,32 +83,23 @@ export class AnalyzerManager {
);
}

private checkForUpdates(): Promise<void> {
return this._binary
.isOutdated()
.then((isOutdated: boolean) => {
if (isOutdated) {
this._logManager.logMessage('Updating Advanced Security Features', 'INFO');
this._binary
.update()
.then(() => this._logManager.logMessage('Updating Advanced Security Features finished successfully', 'INFO'))
.catch((err: Error) => {
this._logManager.logMessage('Updating Advanced Security Features failed: ' + err.message, 'ERR');
});
}
})
.catch((err: Error) => {
this._logManager.logMessage('Failed to check if extension is outdated: ' + err.message, 'ERR');
});
private async checkForUpdates(): Promise<boolean> {
if (await this._binary.isOutdated()) {
this._logManager.logMessage('Updating Advanced Security Features', 'INFO');
try {
return await this._binary.update();
} catch (error) {
this._logManager.logMessage('Failed to check if extension is outdated: ' + error, 'ERR');
}
}
return false;
}

/**
* Get the default path to download the analyzer manager to
*/
public getDefaultTargetPath(): string {
return Utils.addWinSuffixIfNeeded(
path.join(ScanUtils.getIssuesPath(), AnalyzerManager.BINARY_NAME, AnalyzerManager.BINARY_NAME)
);
return Utils.addWinSuffixIfNeeded(path.join(ScanUtils.getIssuesPath(), AnalyzerManager.BINARY_NAME, AnalyzerManager.BINARY_NAME));
}

public async runWithTimeout(checkCancel: () => void, args: string[], executionLogDirectory?: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Resource {
this._logManager.logMessage('Resource ' + this._name + ' was update successfully.', 'DEBUG');
return true;
} catch (error) {
this._logManager.logMessage('Updating resource ' + this._name + ' failed.', 'ERR');
this._logManager.logMessage('Updating resource ' + this._name + ' failed. err:' + error, 'ERR');
throw error;
} finally {
ScanUtils.removeFolder(tmpFolder);
Expand Down
13 changes: 8 additions & 5 deletions src/test/tests/utils/testIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class AnalyzerManagerIntegrationEnv extends BaseIntegrationEnv {
/** @override */
public async initialize(rootTest?: string) {
await super.initialize();
if (this.entitledJasRunnerFactory) {
return;
}
this.entitledJasRunnerFactory = new MockJasRunnerFactory(
this.connectionManager,
this.logManager,
Expand Down Expand Up @@ -116,11 +119,11 @@ function getTestLocation(filePath: string, filesWithIssues: FileWithSecurityIssu
assert.isDefined(
potential,
'Expected file ' +
filePath +
' should contain evidence for issue ' +
ruleId +
' in location ' +
[location.startLine, location.endLine, location.startColumn, location.endColumn]
filePath +
' should contain evidence for issue ' +
ruleId +
' in location ' +
[location.startLine, location.endLine, location.startColumn, location.endColumn]
);
return potential!;
}
Expand Down

0 comments on commit e593b3e

Please sign in to comment.