Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
maksadbek committed Oct 4, 2024
2 parents 3cad8a2 + 1b8f717 commit 43a787f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@brightsec/cli",
"version": "12.5.0",
"version": "12.6.0-next.1",
"private": false,
"repository": {
"type": "git",
Expand Down
15 changes: 11 additions & 4 deletions src/Config/CliBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SystemConfigManager } from './SystemConfigManager';
import { CliInfo } from './CliInfo';
import { Arguments, Argv, CommandModule } from 'yargs';
import { init, runWithAsyncContext, setContext } from '@sentry/node';
import ms from 'ms';

export interface CliBuilderOptions {
info: CliInfo;
Expand Down Expand Up @@ -75,11 +76,17 @@ export class CliBuilder {
'Specify a proxy URL to route all inbound traffic through. For more information, see the --proxy option.'
})
.option('timeout', {
describe: 'Request timeout in seconds',
describe:
'Request timeout in seconds or a duration string (e.g. 10s, 1m, 1h, 10h, 1y).',
default: 30,
type: 'number',
coerce(arg: number) {
return arg * 1000;
coerce(arg: string) {
// if arg is not a number, then it's a duration string
// convert duration string to milliseconds
if (isNaN(+arg)) {
return ms(arg);
}

return +arg * 1000;
}
})
.conflicts({
Expand Down
31 changes: 5 additions & 26 deletions src/Scan/BasePolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Polling } from './Polling';
import { Breakpoint } from './Breakpoint';
import { Backoff, logger } from '../Utils';
import { PollingConfig } from './PollingFactory';
import ms from 'ms';
import axios from 'axios';
import { ok } from 'node:assert';

Expand Down Expand Up @@ -33,9 +32,7 @@ export class BasePolling implements Polling {
}

if (this.options.interval) {
const interval = this.toMilliseconds(this.options.interval);

if (interval < this.defaultInterval) {
if (this.options.interval < this.defaultInterval) {
logger.warn(`Warning: polling interval is too small.`);
logger.warn(`The recommended way to set polling interval to 10s.`);
}
Expand Down Expand Up @@ -69,13 +66,9 @@ export class BasePolling implements Polling {
clearTimeout(this.timeoutDescriptor);
}

private setTimeout(timeout: number | string = this.options.timeout): void {
const timeoutInMs: number = this.toMilliseconds(timeout);
this.timeoutDescriptor = setTimeout(
() => (this._active = false),
timeoutInMs
);
logger.debug(`The polling timeout has been set to %d ms.`, timeoutInMs);
private setTimeout(timeout: number = this.options.timeout): void {
this.timeoutDescriptor = setTimeout(() => (this._active = false), timeout);
logger.debug(`The polling timeout has been set to %d ms.`, timeout);
}

private async *poll(): AsyncIterableIterator<ScanState> {
Expand All @@ -96,19 +89,6 @@ export class BasePolling implements Polling {
}
}

private toMilliseconds(time: string | number): number {
if (typeof time === 'string') {
const milliseconds = ms(time);
if (!milliseconds) {
return;
}

return milliseconds;
} else if (typeof time === 'number') {
return time;
}
}

private isRedundant(status: ScanStatus): boolean {
return (
status === ScanStatus.DONE ||
Expand All @@ -119,8 +99,7 @@ export class BasePolling implements Polling {
}

private delay(): Promise<void> {
const interval =
this.toMilliseconds(this.options.interval) ?? this.defaultInterval;
const interval = this.options.interval ?? this.defaultInterval;

return new Promise<void>((resolve) => setTimeout(resolve, interval));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Scan/PollingFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Polling } from './Polling';
import { BreakpointType } from './BreakpointType';

export interface PollingConfig {
timeout?: number | string;
timeout?: number;
interval?: number;
breakpoint: BreakpointType;
scanId: string;
Expand Down
1 change: 1 addition & 0 deletions src/Utils/Helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ describe('Helpers', () => {
expect(actual).toEqual([TestEnum.TEST, TestEnum.PROD]);
});
});

describe('parseHeaders', () => {
it('should return empty object', () => {
// arrange
Expand Down

0 comments on commit 43a787f

Please sign in to comment.