Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scan): add template to scan create #465

Merged
merged 7 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Commands/RetestScan.ts
BMNTeam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@ export class RetestScan implements CommandModule {

public builder(argv: Argv): Argv {
return argv
.option('name', {
alias: 'n',
describe: 'Name of the scan.',
string: false,
demandOption: false
})
.option('token', {
alias: 't',
describe: 'Bright API-key',
requiresArg: true,
demandOption: true
})
.option('template', {
alias: 'tp',
requiresArg: false,
string: true,
describe: 'ID of the template'
})
.positional('scan', {
describe: 'ID of an existing scan which you want to re-run.',
type: 'string',
Expand All @@ -35,8 +47,20 @@ export class RetestScan implements CommandModule {

public async handler(args: Arguments): Promise<void> {
try {
if (!args.name && args.template) {
throw Error('please make sure that name is specified.');
}

const body = args.name && {
templateId: args.template as string,
name: args.name as string
};

const scanManager: Scans = container.resolve(Scans);
const scanId: string = await scanManager.retest(args.scan as string);
const scanId: string = await scanManager.retest(
args.scan as string,
body
);

// eslint-disable-next-line no-console
console.log(scanId);
Expand Down
7 changes: 7 additions & 0 deletions src/Commands/RunScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ export class RunScan implements CommandModule {
string: true,
describe: 'ID of the project'
})
.option('template', {
alias: 'tp',
requiresArg: false,
string: true,
describe: 'ID of the template'
})
.option('module', {
default: Module.DAST,
requiresArg: true,
Expand Down Expand Up @@ -178,6 +184,7 @@ export class RunScan implements CommandModule {
module: args.module,
authObjectId: args.auth,
projectId: args.project,
templateId: args.template,
buckets: args.bucket,
hostsFilter: args.hostFilter,
headers: Helpers.parseHeaders(args.header as string[]),
Expand Down
2 changes: 2 additions & 0 deletions src/Scan/RestScans.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('RestScans', () => {
const scanConfig: ScanConfig = {
name: 'scan',
module: Module.DAST,
buckets: [],
BMNTeam marked this conversation as resolved.
Show resolved Hide resolved
tests: [],
fileId: 'id'
};
Expand Down Expand Up @@ -100,6 +101,7 @@ describe('RestScans', () => {
const scanConfig: ScanConfig = {
name: 'scan',
module: Module.DAST,
buckets: [],
BMNTeam marked this conversation as resolved.
Show resolved Hide resolved
tests: [],
fileId: 'id'
};
Expand Down
7 changes: 6 additions & 1 deletion src/Scan/RestScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Discovery,
Header,
ScanConfig,
ScanRetestConfig,
Scans,
ScanState,
SourceType,
Expand Down Expand Up @@ -52,8 +53,12 @@ export class RestScans implements Scans {
return id;
}

public async retest(scanId: string): Promise<string> {
public async retest(
scanId: string,
body?: ScanRetestConfig
): Promise<string> {
const { id }: { id: string } = await this.client.post({
...(body?.name && { body: { config: body } }),
uri: `/api/v1/scans/${scanId}/retest`
});

Expand Down
8 changes: 7 additions & 1 deletion src/Scan/Scans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface ScanConfig {
module: Module;
authObjectId?: string;
projectId?: string;
templateId?: string;
discoveryTypes?: Discovery[];
tests: TestType[];
buckets: string[];
Expand All @@ -150,6 +151,11 @@ export interface ScanConfig {
repeaters?: string[];
}

export interface ScanRetestConfig {
name?: string;
templateId?: string;
}

export enum IssueCategory {
MEDIUM = 'Medium',
HIGH = 'High',
Expand Down Expand Up @@ -192,7 +198,7 @@ export interface StorageFile {
export interface Scans {
create(body: ScanConfig): Promise<string>;

retest(scanId: string): Promise<string>;
retest(scanId: string, body?: ScanRetestConfig): Promise<string>;

stop(scanId: string): Promise<void>;

Expand Down