forked from LightspeedGMI/serverless-domain-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainConfig.ts
100 lines (87 loc) · 3.98 KB
/
DomainConfig.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
/**
* Wrapper class for Custom Domain information
*/
import Globals from "./Globals";
import DomainInfo = require("./DomainInfo");
import * as AWS from "aws-sdk"; // imported for Types
class DomainConfig {
public givenDomainName: string;
public basePath: string | undefined;
public stage: string | undefined;
public certificateName: string | undefined;
public certificateArn: string | undefined;
public createRoute53Record: boolean | undefined;
public endpointType: string | undefined;
public apiType: string | undefined;
public hostedZoneId: string | undefined;
public hostedZonePrivate: boolean | undefined;
public enabled: boolean | string | undefined;
public securityPolicy: string | undefined;
public domainInfo: DomainInfo | undefined;
public apiId: string | undefined;
public apiMapping: AWS.ApiGatewayV2.GetApiMappingResponse;
public allowPathMatching: boolean | false;
constructor(config: any) {
this.enabled = this.evaluateEnabled(config.enabled);
this.givenDomainName = config.domainName;
this.hostedZonePrivate = config.hostedZonePrivate;
this.certificateArn = config.certificateArn;
this.certificateName = config.certificateName;
this.createRoute53Record = config.createRoute53Record;
this.hostedZoneId = config.hostedZoneId;
this.hostedZonePrivate = config.hostedZonePrivate;
this.allowPathMatching = config.allowPathMatching;
let basePath = config.basePath;
if (basePath == null || basePath.trim() === "") {
basePath = "(none)";
}
this.basePath = basePath;
let stage = config.stage;
if (typeof stage === "undefined") {
stage = Globals.options.stage || Globals.serverless.service.provider.stage;
}
this.stage = stage;
const endpointTypeWithDefault = config.endpointType || Globals.endpointTypes.edge;
const endpointTypeToUse = Globals.endpointTypes[endpointTypeWithDefault.toLowerCase()];
if (!endpointTypeToUse) {
throw new Error(`${endpointTypeWithDefault} is not supported endpointType, use edge or regional.`);
}
this.endpointType = endpointTypeToUse;
const apiTypeWithDefault = config.apiType || Globals.apiTypes.rest;
const apiTypeToUse = Globals.apiTypes[apiTypeWithDefault.toLowerCase()];
if (!apiTypeToUse) {
throw new Error(`${apiTypeWithDefault} is not supported api type, use REST, HTTP or WEBSOCKET.`);
}
this.apiType = apiTypeToUse;
const securityPolicyDefault = config.securityPolicy || Globals.tlsVersions.tls_1_2;
const tlsVersionToUse = Globals.tlsVersions[securityPolicyDefault.toLowerCase()];
if (!tlsVersionToUse) {
throw new Error(`${securityPolicyDefault} is not a supported securityPolicy, use tls_1_0 or tls_1_2.`);
}
this.securityPolicy = tlsVersionToUse;
}
/**
* Determines whether this plug-in is enabled.
*
* This method reads the customDomain property "enabled" to see if this plug-in should be enabled.
* If the property's value is undefined, a default value of true is assumed (for backwards
* compatibility).
* If the property's value is provided, this should be boolean, otherwise an exception is thrown.
* If no customDomain object exists, an exception is thrown.
*/
private evaluateEnabled(enabled: any): boolean {
// const enabled = this.serverless.service.custom.customDomain.enabled;
if (enabled === undefined) {
return true;
}
if (typeof enabled === "boolean") {
return enabled;
} else if (typeof enabled === "string" && enabled === "true") {
return true;
} else if (typeof enabled === "string" && enabled === "false") {
return false;
}
throw new Error(`serverless-domain-manager: Ambiguous enablement boolean: "${enabled}"`);
}
}
export = DomainConfig;