Skip to content

Commit 6a881f1

Browse files
committed
CCM-10048: publish event
1 parent 18bcc74 commit 6a881f1

File tree

4 files changed

+139
-213
lines changed

4 files changed

+139
-213
lines changed

infrastructure/terraform/components/sandbox/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ output "download_bucket_name" {
1414
value = module.backend_api.download_bucket_name
1515
}
1616

17+
output "guardduty_quarantine_arn" {
18+
value = module.backend_api.guardduty_quarantine_arn
19+
}
20+
1721
output "internal_bucket_name" {
1822
value = module.backend_api.internal_bucket_name
1923
}

tests/test-team/helpers/eventbridge/eventbridge-helper.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import {
33
PutEventsCommand,
44
} from '@aws-sdk/client-eventbridge';
55

6+
export type GuardDutyScanResult =
7+
| 'NO_THREATS_FOUND'
8+
| 'THREATS_FOUND'
9+
| 'UNSUPPORTED';
10+
611
export class EventBridgeHelper {
712
readonly #client: EventBridgeClient;
813

@@ -13,10 +18,7 @@ export class EventBridgeHelper {
1318
async publishGuardDutyEvent(
1419
s3ObjectKey: string,
1520
s3VersionId: string,
16-
guardDutyScanResultStatus:
17-
| 'NO_THREATS_FOUND'
18-
| 'THREATS_FOUND'
19-
| 'UNSUPPORTED'
21+
guardDutyScanResultStatus: GuardDutyScanResult
2022
) {
2123
const resp = await this.#client.send(
2224
new PutEventsCommand({
@@ -42,7 +44,7 @@ export class EventBridgeHelper {
4244

4345
private createGuardDutyEvent(
4446
s3ObjectKey: string,
45-
scanResultStatus: 'NO_THREATS_FOUND' | 'THREATS_FOUND' | 'UNSUPPORTED',
47+
scanResultStatus: GuardDutyScanResult,
4648
versionId: string
4749
) {
4850
const SOURCE = 'test.guardduty';

tests/test-team/helpers/use-cases/simulate-guard-duty-scan.ts

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { IUseCase } from './use-case-orchestrator';
2-
import { EventBridgeHelper } from '../eventbridge/eventbridge-helper';
2+
import {
3+
EventBridgeHelper,
4+
GuardDutyScanResult,
5+
} from '../eventbridge/eventbridge-helper';
36
import { S3Helper } from '../s3/s3-helper';
7+
import { Template } from '../types';
8+
9+
type FileConfig = {
10+
currentVersion?: string;
11+
event: GuardDutyScanResult;
12+
type: 'pdf' | 'csv';
13+
};
414

515
type Config = {
616
templateId: string;
717
templateOwner: string;
8-
files: Array<{
9-
name?: string;
10-
currentVersion?: string;
11-
eventType: 'THREATS_FOUND' | 'NO_THREATS_FOUND' | 'UNSUPPORTED';
12-
}>;
18+
files: FileConfig[];
1319
};
1420

1521
export class SimulateGuardDutyScan implements IUseCase<void> {
@@ -25,13 +31,13 @@ export class SimulateGuardDutyScan implements IUseCase<void> {
2531

2632
async execute() {
2733
for (const file of this.#config.files) {
28-
if (!file.name || !file.currentVersion) {
34+
if (!file.currentVersion) {
2935
throw new Error('No file name or file currentVersion', {
3036
cause: file,
3137
});
3238
}
3339

34-
const s3FilePath = this.s3ObjectPath(file.name, file.currentVersion);
40+
const s3FilePath = this.s3ObjectPath(file.type, file.currentVersion);
3541

3642
const s3VersionId = await this.#s3Helper.getVersionId(
3743
process.env.TEMPLATES_QUARANTINE_BUCKET_NAME,
@@ -45,16 +51,46 @@ export class SimulateGuardDutyScan implements IUseCase<void> {
4551
this.#eventBridgeHelper.publishGuardDutyEvent(
4652
s3FilePath,
4753
s3VersionId,
48-
file.eventType
54+
file.event
4955
);
5056
}
5157
}
5258

53-
private s3ObjectPath(file: string, versionId: string) {
54-
return `${this.parentFolderByFileType(file)}/${this.#config.templateOwner}/${this.#config.templateId}/${versionId}/${file}`;
59+
private s3ObjectPath(fileType: 'pdf' | 'csv', versionId: string) {
60+
const parentFolder = fileType === 'pdf' ? 'pdf-template' : 'test-data';
61+
62+
return `${parentFolder}/${this.#config.templateOwner}/${this.#config.templateId}/${versionId}.${fileType}`;
5563
}
5664

57-
private parentFolderByFileType(file: string) {
58-
return file.endsWith('.pdf') ? 'pdf-template' : 'csv-test-data';
65+
static async publish(
66+
template: Template,
67+
events: {
68+
pdfTemplateEvent?: GuardDutyScanResult;
69+
csvTestDataEvent?: GuardDutyScanResult;
70+
}
71+
) {
72+
const files: FileConfig[] = [];
73+
74+
if (events.pdfTemplateEvent) {
75+
files.push({
76+
currentVersion: template.files?.pdfTemplate?.currentVersion,
77+
event: events.pdfTemplateEvent,
78+
type: 'pdf',
79+
});
80+
}
81+
82+
if (events.csvTestDataEvent) {
83+
files.push({
84+
currentVersion: template.files?.pdfTemplate?.currentVersion,
85+
event: events.csvTestDataEvent,
86+
type: 'csv',
87+
});
88+
}
89+
90+
await new SimulateGuardDutyScan({
91+
templateId: template.id,
92+
templateOwner: template.owner,
93+
files,
94+
}).execute();
5995
}
6096
}

0 commit comments

Comments
 (0)