From 255c594d043205ad59354c48f7d35a683112759f Mon Sep 17 00:00:00 2001 From: chaoticefx <79575739+chaoticefx@users.noreply.github.com> Date: Tue, 1 Nov 2022 09:08:17 +0800 Subject: [PATCH] Cleaned up config declaration in constructor --- .../server/src/integrations/elasticsearch.ts | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index 8cda6692a0..c021662a41 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -5,7 +5,7 @@ import { IntegrationBase, } from "@budibase/types" -const { Client } = require("@elastic/elasticsearch") +import { Client, ClientOptions } from "@elastic/elasticsearch" interface ElasticsearchConfig { url: string @@ -100,22 +100,18 @@ class ElasticSearchIntegration implements IntegrationBase { constructor(config: ElasticsearchConfig) { this.config = config - let newConfig = { + const clientConfig: ClientOptions = { node: this.config.url, - ssl: this.config.ssl - ? { - rejectUnauthorized: this.config.rejectUnauthorized, - ca: this.config.ca || undefined, - } - : undefined, } - if (newConfig.ssl && !newConfig.ssl.ca) { - delete newConfig.ssl.ca - } else if (!newConfig.ssl) { - delete newConfig.ssl + if (this.config.ssl) { + clientConfig.ssl = { + rejectUnauthorized: this.config.rejectUnauthorized, + ca: this.config.ca || undefined, + } } - this.client = new Client(newConfig) + + this.client = new Client(clientConfig) } async create(query: { index: string; json: object }) {