From 22a521a3cc767a482e5236043a16ac0a4308b892 Mon Sep 17 00:00:00 2001 From: Dima Revutskyi Date: Wed, 4 Nov 2020 17:49:31 +0200 Subject: [PATCH 1/3] Fix getting an api id for different types of the API gateway --- src/Globals.ts | 5 +++++ src/index.ts | 18 +++++++++--------- src/types.ts | 1 + test/unit-tests/index.test.ts | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Globals.ts b/src/Globals.ts index 6ef5b4f2..acc9a5b8 100644 --- a/src/Globals.ts +++ b/src/Globals.ts @@ -22,6 +22,11 @@ export default class Globals { websocket: "WEBSOCKET", }; + public static gatewayAPIIdKeys = { + [Globals.apiTypes.rest]: 'restApiId', + [Globals.apiTypes.websocket]: 'websocketApiId', + }; + public static tlsVersions = { tls_1_0: "TLS_1_0", tls_1_2: "TLS_1_2", diff --git a/src/index.ts b/src/index.ts index bad5dc12..d78ebbe0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,6 @@ import APIGatewayWrapper = require("./aws/api-gateway-wrapper"); import CloudFormationWrapper = require("./aws/cloud-formation-wrapper"); import DomainConfig = require("./DomainConfig"); -import DomainInfo = require("./DomainInfo"); import Globals from "./Globals"; import {CustomDomain, ServerlessInstance, ServerlessOptions} from "./types"; import {getAWSPagedResults, sleep, throttledCall} from "./utils"; @@ -524,17 +523,18 @@ class ServerlessCustomDomain { * Gets rest API id from existing config or CloudFormation stack */ public async getApiId(domain: DomainConfig): Promise { - const apiGateway = this.serverless.service.provider.apiGateway; - if (apiGateway && apiGateway.restApiId) { - const restApiId = apiGateway.restApiId; + const apiGateway = this.serverless.service.provider.apiGateway || {}; + const apiIdKey = Globals.gatewayAPIIdKeys[domain.apiType]; + const apiId = apiGateway[apiIdKey]; + if (apiId) { // if string value exists return the value - if (typeof restApiId === "string") { - Globals.logInfo(`Mapping custom domain to existing API ${restApiId}.`); - return restApiId; + if (typeof apiId === "string") { + Globals.logInfo(`Mapping custom domain to existing API ${apiId}.`); + return apiId; } // in case object and Fn::ImportValue try to get restApiId from the CloudFormation exports - if (typeof restApiId === "object" && restApiId["Fn::ImportValue"]) { - const importName = restApiId["Fn::ImportValue"]; + if (typeof apiId === "object" && apiId["Fn::ImportValue"]) { + const importName = apiId["Fn::ImportValue"]; let importValues; try { importValues = await this.cloudFormationWrapper.getImportValues([importName]); diff --git a/src/types.ts b/src/types.ts index a7e2d974..0e344d94 100644 --- a/src/types.ts +++ b/src/types.ts @@ -27,6 +27,7 @@ export interface ServerlessInstance { // tslint:disable-line }, apiGateway: { restApiId: string, + websocketApiId: string, }, } custom: { diff --git a/test/unit-tests/index.test.ts b/test/unit-tests/index.test.ts index bfbc4198..fb727b82 100644 --- a/test/unit-tests/index.test.ts +++ b/test/unit-tests/index.test.ts @@ -90,6 +90,7 @@ const constructPlugin = (customDomainOptions, multiple: boolean = false) => { provider: { apiGateway: { restApiId: null, + websocketApiId: null, }, compiledCloudFormationTemplate: { Outputs: null, From 471532ce1d5537007add6f6f446995ce1687a570 Mon Sep 17 00:00:00 2001 From: Dima Revutskyi Date: Wed, 4 Nov 2020 17:54:34 +0200 Subject: [PATCH 2/3] fix lint --- src/Globals.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Globals.ts b/src/Globals.ts index acc9a5b8..50666586 100644 --- a/src/Globals.ts +++ b/src/Globals.ts @@ -23,8 +23,8 @@ export default class Globals { }; public static gatewayAPIIdKeys = { - [Globals.apiTypes.rest]: 'restApiId', - [Globals.apiTypes.websocket]: 'websocketApiId', + [Globals.apiTypes.rest]: "restApiId", + [Globals.apiTypes.websocket]: "websocketApiId", }; public static tlsVersions = { From 80ddfa8ddc94640c20ff7d60d663cf5dc977b1b9 Mon Sep 17 00:00:00 2001 From: Dima Revutskyi Date: Wed, 4 Nov 2020 18:06:32 +0200 Subject: [PATCH 3/3] remove .sonarcloud.properties --- .sonarcloud.properties | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .sonarcloud.properties diff --git a/.sonarcloud.properties b/.sonarcloud.properties deleted file mode 100644 index 8b137891..00000000 --- a/.sonarcloud.properties +++ /dev/null @@ -1 +0,0 @@ -