@@ -5,99 +5,102 @@ import { NodeHttpHandler } from "@smithy/node-http-handler";
5
5
import { ProxyAgent } from "proxy-agent" ;
6
6
7
7
export default class Globals {
8
- public static pluginName = "Serverless Domain Manager" ;
9
-
10
- public static serverless : ServerlessInstance ;
11
- public static options : ServerlessOptions ;
12
- public static v3Utils : ServerlessUtils ;
13
-
14
- public static currentRegion : string ;
15
- public static credentials : any ;
16
-
17
- public static defaultRegion = "us-east-1" ;
18
- public static defaultBasePath = "(none)" ;
19
- public static defaultStage = "$default" ;
20
-
21
- // https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html
22
- public static reservedBasePaths = [ "ping" , "sping" ] ;
23
-
24
- public static endpointTypes = {
25
- edge : "EDGE" ,
26
- regional : "REGIONAL"
27
- } ;
28
-
29
- public static apiTypes = {
30
- http : "HTTP" ,
31
- rest : "REST" ,
32
- websocket : "WEBSOCKET"
33
- } ;
34
-
35
- public static gatewayAPIIdKeys = {
36
- [ Globals . apiTypes . rest ] : "restApiId" ,
37
- [ Globals . apiTypes . websocket ] : "websocketApiId"
38
- } ;
39
-
40
- // Cloud Formation Resource Ids
41
- public static CFResourceIds = {
42
- [ Globals . apiTypes . http ] : "HttpApi" ,
43
- [ Globals . apiTypes . rest ] : "ApiGatewayRestApi" ,
44
- [ Globals . apiTypes . websocket ] : "WebsocketsApi"
45
- } ;
46
-
47
- // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
48
- public static CFFuncNames = {
49
- fnImport : "Fn::ImportValue" ,
50
- ref : "Ref"
51
- }
52
-
53
- /* eslint camelcase: ["error", {allow: ["^tls_"]}] */
54
- public static tlsVersions = {
55
- tls_1_0 : "TLS_1_0" ,
56
- tls_1_2 : "TLS_1_2" ,
57
- tls_1_3 : "TLS_1_3"
58
- } ;
59
-
60
- public static routingPolicies = {
61
- simple : "simple" ,
62
- latency : "latency" ,
63
- weighted : "weighted"
64
- } ;
65
-
66
- public static getBaseStage ( ) {
67
- return Globals . options . stage || Globals . serverless . service . provider . stage ;
68
- }
69
-
70
- public static getServiceEndpoint ( service : string ) {
71
- if ( Globals . serverless . providers . aws . sdk ) {
72
- const serviceConf = Globals . serverless . providers . aws . sdk . config [ service ] ;
73
- return ( serviceConf && serviceConf . endpoint ) || null ;
8
+ public static pluginName = "Serverless Domain Manager" ;
9
+
10
+ public static serverless : ServerlessInstance ;
11
+ public static options : ServerlessOptions ;
12
+ public static v3Utils : ServerlessUtils ;
13
+
14
+ public static currentRegion : string ;
15
+ public static credentials : any ;
16
+
17
+ public static defaultRegion = "us-east-1" ;
18
+ public static defaultBasePath = "(none)" ;
19
+ public static defaultStage = "$default" ;
20
+
21
+ // https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html
22
+ public static reservedBasePaths = [ "ping" , "sping" ] ;
23
+
24
+ public static endpointTypes = {
25
+ edge : "EDGE" ,
26
+ regional : "REGIONAL"
27
+ } ;
28
+
29
+ public static apiTypes = {
30
+ http : "HTTP" ,
31
+ rest : "REST" ,
32
+ websocket : "WEBSOCKET"
33
+ } ;
34
+
35
+ public static gatewayAPIIdKeys = {
36
+ [ Globals . apiTypes . rest ] : "restApiId" ,
37
+ [ Globals . apiTypes . websocket ] : "websocketApiId"
38
+ } ;
39
+
40
+ // Cloud Formation Resource Ids
41
+ public static CFResourceIds = {
42
+ [ Globals . apiTypes . http ] : "HttpApi" ,
43
+ [ Globals . apiTypes . rest ] : "ApiGatewayRestApi" ,
44
+ [ Globals . apiTypes . websocket ] : "WebsocketsApi"
45
+ } ;
46
+
47
+ // https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
48
+ public static CFFuncNames = {
49
+ fnImport : "Fn::ImportValue" ,
50
+ ref : "Ref"
51
+ }
52
+
53
+ /* eslint camelcase: ["error", {allow: ["^tls_"]}] */
54
+ public static tlsVersions = {
55
+ tls_1_0 : "TLS_1_0" ,
56
+ tls_1_2 : "TLS_1_2" ,
57
+ tls_1_3 : "TLS_1_3"
58
+ } ;
59
+
60
+ public static routingPolicies = {
61
+ simple : "simple" ,
62
+ latency : "latency" ,
63
+ weighted : "weighted"
64
+ } ;
65
+
66
+ public static getBaseStage ( ) {
67
+ return Globals . options . stage || Globals . serverless . service . provider . stage ;
68
+ }
69
+
70
+ public static getServiceEndpoint ( service : string ) {
71
+ if ( Globals . serverless . providers . aws . sdk ) {
72
+ const serviceConf = Globals . serverless . providers . aws . sdk . config [ service ] ;
73
+ if ( serviceConf ) {
74
+ return serviceConf . endpoint ;
74
75
}
75
76
return null ;
76
77
}
77
-
78
- public static getRegion ( ) {
79
- const slsRegion = Globals . options . region || Globals . serverless . service . provider . region ;
80
- return slsRegion || Globals . currentRegion || Globals . defaultRegion ;
81
- }
82
-
83
- public static async getProfileCreds ( profile : string ) {
84
- return await fromIni ( { profile } ) ( ) ;
85
- }
86
-
87
- public static getRetryStrategy ( attempts : number = 5 , delay : number = 3000 , backoff : number = 500 ) {
88
- return new ConfiguredRetryStrategy (
89
- attempts , // max attempts.
90
- // This example sets the backoff at 500ms plus 3s per attempt.
91
- // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_retry.html#aws-sdkutil-retry
92
- ( attempt : number ) => backoff + attempt * delay // backoff function.
93
- ) ;
94
- }
95
-
96
- public static getRequestHandler ( ) {
97
- const proxyAgent = new ProxyAgent ( ) ;
98
- return new NodeHttpHandler ( {
99
- httpAgent : proxyAgent ,
100
- httpsAgent : proxyAgent
101
- } ) ;
102
- }
78
+ return null ;
79
+ }
80
+
81
+ public static getRegion ( ) {
82
+ const slsRegion = Globals . options . region || Globals . serverless . service . provider . region ;
83
+ return slsRegion || Globals . currentRegion || Globals . defaultRegion ;
84
+ }
85
+
86
+ public static async getProfileCreds ( profile : string ) {
87
+ return await fromIni ( { profile } ) ( ) ;
88
+ }
89
+
90
+ public static getRetryStrategy ( attempts : number = 5 , delay : number = 3000 , backoff : number = 500 ) {
91
+ return new ConfiguredRetryStrategy (
92
+ attempts , // max attempts.
93
+ // This example sets the backoff at 500ms plus 3s per attempt.
94
+ // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_retry.html#aws-sdkutil-retry
95
+ ( attempt : number ) => backoff + attempt * delay // backoff function.
96
+ ) ;
97
+ }
98
+
99
+ public static getRequestHandler ( ) {
100
+ const proxyAgent = new ProxyAgent ( ) ;
101
+ return new NodeHttpHandler ( {
102
+ httpAgent : proxyAgent ,
103
+ httpsAgent : proxyAgent
104
+ } ) ;
105
+ }
103
106
}
0 commit comments