serverless-domain-manager
Version:
Serverless plugin for managing custom domains with API Gateways.
96 lines (95 loc) • 3.77 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const credential_providers_1 = require("@aws-sdk/credential-providers");
const util_retry_1 = require("@smithy/util-retry");
const node_http_handler_1 = require("@smithy/node-http-handler");
const proxy_agent_1 = require("proxy-agent");
class Globals {
static getBaseStage() {
return Globals.options.stage || Globals.serverless.service.provider.stage;
}
static getServiceEndpoint(service) {
if (Globals.serverless.providers.aws.sdk) {
const serviceConf = Globals.serverless.providers.aws.sdk.config[service];
if (serviceConf) {
return serviceConf.endpoint;
}
return null;
}
return null;
}
static getRegion() {
const slsRegion = Globals.options.region || Globals.serverless.service.provider.region;
return slsRegion || Globals.currentRegion || Globals.defaultRegion;
}
static getProfileCreds(profile) {
return __awaiter(this, void 0, void 0, function* () {
return yield (0, credential_providers_1.fromIni)({ profile })();
});
}
static getRetryStrategy(attempts = 5, delay = 3000, backoff = 500) {
return new util_retry_1.ConfiguredRetryStrategy(attempts, // max attempts.
// This example sets the backoff at 500ms plus 3s per attempt.
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_util_retry.html#aws-sdkutil-retry
(attempt) => backoff + attempt * delay // backoff function.
);
}
static getRequestHandler() {
const proxyAgent = new proxy_agent_1.ProxyAgent();
return new node_http_handler_1.NodeHttpHandler({
httpAgent: proxyAgent,
httpsAgent: proxyAgent
});
}
}
Globals.pluginName = "Serverless Domain Manager";
Globals.defaultRegion = "us-east-1";
Globals.defaultBasePath = "(none)";
Globals.defaultStage = "$default";
// https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html
Globals.reservedBasePaths = ["ping", "sping"];
Globals.endpointTypes = {
edge: "EDGE",
regional: "REGIONAL"
};
Globals.apiTypes = {
http: "HTTP",
rest: "REST",
websocket: "WEBSOCKET"
};
Globals.gatewayAPIIdKeys = {
[Globals.apiTypes.rest]: "restApiId",
[Globals.apiTypes.websocket]: "websocketApiId"
};
// Cloud Formation Resource Ids
Globals.CFResourceIds = {
[Globals.apiTypes.http]: "HttpApi",
[Globals.apiTypes.rest]: "ApiGatewayRestApi",
[Globals.apiTypes.websocket]: "WebsocketsApi"
};
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
Globals.CFFuncNames = {
fnImport: "Fn::ImportValue",
ref: "Ref"
};
/* eslint camelcase: ["error", {allow: ["^tls_"]}] */
Globals.tlsVersions = {
tls_1_0: "TLS_1_0",
tls_1_2: "TLS_1_2",
tls_1_3: "TLS_1_3"
};
Globals.routingPolicies = {
simple: "simple",
latency: "latency",
weighted: "weighted"
};
exports.default = Globals;
;