forked from mongodb/docs-worker-pool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook-env-construct.ts
50 lines (46 loc) · 2.06 KB
/
webhook-env-construct.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
import { IQueue } from 'aws-cdk-lib/aws-sqs';
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
import { Construct } from 'constructs';
import { getSsmPathPrefix } from '../../../utils/ssm';
import { getDashboardUrl } from '../../../utils/slack';
import { getEnv } from '../../../utils/env';
interface WebhookEnvConstructProps {
jobsQueue: IQueue;
jobUpdatesQueue: IQueue;
secureStrings: Record<string, string>;
}
export class WebhookEnvConstruct extends Construct {
readonly environment: Record<string, string>;
constructor(scope: Construct, id: string, { jobsQueue, jobUpdatesQueue, secureStrings }: WebhookEnvConstructProps) {
super(scope, id);
const ssmPrefix = getSsmPathPrefix();
const env = getEnv();
const dbName = StringParameter.valueFromLookup(this, `${ssmPrefix}/atlas/dbname`);
const snootyDbName = StringParameter.valueFromLookup(this, `${ssmPrefix}/atlas/collections/snooty`);
const dbUsername = StringParameter.valueFromLookup(this, `${ssmPrefix}/atlas/username`);
const dbHost = StringParameter.valueFromLookup(this, `${ssmPrefix}/atlas/host`);
const jobCollection = StringParameter.valueFromLookup(this, `${ssmPrefix}/atlas/collections/job/queue`);
const entitlementCollection = StringParameter.valueFromLookup(
this,
`${ssmPrefix}/atlas/collections/user/entitlements`
);
const dbPassword = secureStrings['MONGO_ATLAS_PASSWORD'];
this.environment = {
...secureStrings,
MONGO_ATLAS_USERNAME: dbUsername,
MONGO_ATLAS_PASSWORD: dbPassword,
MONGO_ATLAS_HOST: dbHost,
MONGO_ATLAS_URL: `mongodb+srv://${dbUsername}:${dbPassword}@${dbHost}/admin?retryWrites=true`,
DB_NAME: dbName,
SNOOTY_DB_NAME: snootyDbName,
JOB_QUEUE_COL_NAME: jobCollection,
NODE_CONFIG_DIR: './config',
JOBS_QUEUE_URL: jobsQueue.queueUrl,
JOB_UPDATES_QUEUE_URL: jobUpdatesQueue.queueUrl,
NODE_OPTIONS: '--enable-source-maps',
USER_ENTITLEMENT_COL_NAME: entitlementCollection,
DASHBOARD_URL: getDashboardUrl(env, jobCollection),
STAGE: env,
};
}
}