-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathidentity.ts
31 lines (26 loc) · 1.06 KB
/
identity.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
import { Tags } from "aws-cdk-lib";
import type { IConstruct } from "constructs";
export interface StackStageIdentity {
stack: string;
stage: string;
}
export interface AppIdentity {
app: string;
}
export interface Identity extends StackStageIdentity, AppIdentity {}
export const AppIdentity = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- user defined type guard
isAppIdentity(props: any): props is AppIdentity {
return props ? "app" in props : false;
},
suffixText(appIdentity: AppIdentity, text: string): string {
const titleCaseApp = appIdentity.app.charAt(0).toUpperCase() + appIdentity.app.slice(1);
// CloudFormation Logical Ids must be alphanumeric, so remove any non-alphanumeric characters: https://stackoverflow.com/a/20864946
const alphanumericTitleCaseApp = titleCaseApp.replace(/[\W_]+/g, "");
return `${text}${alphanumericTitleCaseApp}`;
},
taggedConstruct<T extends IConstruct>(appIdentity: AppIdentity, construct: T): T {
Tags.of(construct).add("App", appIdentity.app);
return construct;
},
};