-
Notifications
You must be signed in to change notification settings - Fork 0
/
vitestIntegrationSetup.ts
74 lines (59 loc) · 1.85 KB
/
vitestIntegrationSetup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Sha256 } from '@aws-crypto/sha256-js';
import {
CloudFormationClient,
ListExportsCommand,
} from '@aws-sdk/client-cloudformation';
import { fromEnv, fromIni } from '@aws-sdk/credential-providers';
import { EventScoutClient } from '@event-scout/client';
import { SignatureV4 } from '@smithy/signature-v4';
import { config } from 'dotenv';
import {
defaultStage,
getEventScoutEndpointExportName,
getHttpApiExportName,
} from 'iac/shared';
// load .env
config();
const credentials =
process.env.CI === 'true'
? fromEnv()
: fromIni({ profile: process.env.AWS_PROFILE });
const region = process.env.AWS_REGION;
const stage = process.env.STAGE ?? defaultStage;
if (region === undefined) {
throw new Error('expected region');
}
const cloudformationClient = new CloudFormationClient({
region,
credentials,
});
// For now Cloudformation has no better way than to query all exports and filter client-side
const cfOutputs = await cloudformationClient.send(new ListExportsCommand({}));
const httpApiExportName = getHttpApiExportName(stage);
const eventScoutEndpointExportName = getEventScoutEndpointExportName(stage);
const httpApiUrl = cfOutputs.Exports?.find(
o => o.Name === httpApiExportName,
)?.Value;
if (httpApiUrl === undefined) {
throw new Error('unable to retrieve the HTTP URL');
}
const eventScoutEndpoint = cfOutputs.Exports?.find(
o => o.Name === eventScoutEndpointExportName,
)?.Value;
if (eventScoutEndpoint === undefined) {
throw new Error('unable to retrieve the EventScout endpoint');
}
const signatureV4 = new SignatureV4({
service: 'execute-api',
region,
credentials,
sha256: Sha256,
});
const eventScoutClient = new EventScoutClient({
credentials,
region,
endpoint: eventScoutEndpoint,
});
globalThis.eventScoutClient = eventScoutClient;
globalThis.httpApiUrl = httpApiUrl;
globalThis.signatureV4 = signatureV4;