forked from amplify-education/serverless-domain-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.ts
113 lines (97 loc) · 3.15 KB
/
globals.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import DomainConfig = require("./domain-config");
import {ServerlessInstance, ServerlessOptions, ServerlessUtils} from "./types";
export default class Globals {
public static pluginName = "Serverless Domain Manager";
public static serverless: ServerlessInstance;
public static options: ServerlessOptions;
public static v3Utils: ServerlessUtils;
public static defaultRegion = "us-east-1";
public static defaultBasePath = "(none)";
public static defaultStage = "$default";
public static endpointTypes = {
edge: "EDGE",
regional: "REGIONAL",
};
public static apiTypes = {
http: "HTTP",
rest: "REST",
websocket: "WEBSOCKET",
};
public static gatewayAPIIdKeys = {
[Globals.apiTypes.rest]: "restApiId",
[Globals.apiTypes.websocket]: "websocketApiId",
};
// Cloud Formation Resource Ids
public static CFResourceIds = {
[Globals.apiTypes.http]: "HttpApi",
[Globals.apiTypes.rest]: "ApiGatewayRestApi",
[Globals.apiTypes.websocket]: "WebsocketsApi",
};
public static tlsVersions = {
tls_1_0: "TLS_1_0",
tls_1_2: "TLS_1_2",
};
public static routingPolicies = {
simple: "simple",
latency: "latency",
weighted: "weighted",
};
public static cliLog(prefix: string, message: string): void {
Globals.serverless.cli.log(`${prefix} ${message}`, Globals.pluginName);
}
/**
* Logs error message
*/
public static logError(message: string): void {
if (Globals.v3Utils) {
Globals.v3Utils.log.error(message);
} else {
Globals.cliLog("[Error]", message);
}
}
/**
* Logs info message
*/
public static logInfo(message: string): void {
if (Globals.v3Utils) {
Globals.v3Utils.log.verbose(message);
} else {
Globals.cliLog("[Info]", message);
}
}
/**
* Logs warning message
*/
public static logWarning(message: string): void {
if (Globals.v3Utils) {
Globals.v3Utils.log.warning(message);
} else {
Globals.cliLog("[WARNING]", message);
}
}
/**
* Prints out a summary of all domain manager related info
*/
public static printDomainSummary(domains: DomainConfig[]): void {
const summaryList = [];
domains.forEach((domain) => {
if (domain.domainInfo) {
summaryList.push(`Domain Name: ${domain.givenDomainName}`);
summaryList.push(`Target Domain: ${domain.domainInfo.domainName}`);
summaryList.push(`Hosted Zone Id: ${domain.domainInfo.hostedZoneId}`);
}
})
// don't print summary if summaryList is empty
if (!summaryList.length) {
return;
}
if (Globals.v3Utils) {
Globals.serverless.addServiceOutputSection(Globals.pluginName, summaryList);
} else {
Globals.cliLog("[Summary]", "Distribution Domain Name");
summaryList.forEach((item) => {
Globals.cliLog("", `${item}`);
})
}
}
}