From 1ac362f90ce24f8a122dc1bc5fd6a2d23667c87d Mon Sep 17 00:00:00 2001 From: chaoticefx <79575739+chaoticefx@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:59:34 +0800 Subject: [PATCH 1/4] Implemented custom ssl config in elasticsearch.ts --- .../server/src/integrations/elasticsearch.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index 14887a743d..0bd463606f 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -9,6 +9,9 @@ const { Client } = require("@elastic/elasticsearch") interface ElasticsearchConfig { url: string + ssl?: boolean + ca?: string + rejectUnauthorized?: boolean } const SCHEMA: Integration = { @@ -23,6 +26,21 @@ const SCHEMA: Integration = { required: true, default: "http://localhost:9200", }, + ssl: { + type: DatasourceFieldType.BOOLEAN, + default: false, + required: false, + }, + rejectUnauthorized: { + type: DatasourceFieldType.BOOLEAN, + default: true, + required: false, + }, + ca: { + type: DatasourceFieldType.LONGFORM, + default: false, + required: false, + }, }, query: { create: { @@ -81,7 +99,25 @@ class ElasticSearchIntegration implements IntegrationBase { constructor(config: ElasticsearchConfig) { this.config = config - this.client = new Client({ node: config.url }) + + let newConfig = { + node: this.config.url, + ssl: this.config.ssl + ? { + rejectUnauthorized: this.config.rejectUnauthorized, + ca: this.config.ca ? this.config.ca : undefined + } + : undefined, + } + + if (newConfig.ssl && !newConfig.ssl.ca) + { + delete newConfig.ssl.ca + } else if(!newConfig.ssl) + { + delete newConfig.ssl + } + this.client = new Client(newConfig) } async create(query: { index: string; json: object }) { From ac9c52e70fba54ea4e4e6d1c107bcff002b86dfb Mon Sep 17 00:00:00 2001 From: chaoticefx <79575739+chaoticefx@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:52:49 +0800 Subject: [PATCH 2/4] Fixed code styling --- packages/server/src/integrations/elasticsearch.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index 0bd463606f..51e13b37fa 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -105,16 +105,14 @@ class ElasticSearchIntegration implements IntegrationBase { ssl: this.config.ssl ? { rejectUnauthorized: this.config.rejectUnauthorized, - ca: this.config.ca ? this.config.ca : undefined + ca: this.config.ca || undefined, } : undefined, } - if (newConfig.ssl && !newConfig.ssl.ca) - { + if (newConfig.ssl && !newConfig.ssl.ca) { delete newConfig.ssl.ca - } else if(!newConfig.ssl) - { + } else if(!newConfig.ssl) { delete newConfig.ssl } this.client = new Client(newConfig) From 46a0197cd614d9f5b05d34f0f87c769f311be67f Mon Sep 17 00:00:00 2001 From: chaoticefx <79575739+chaoticefx@users.noreply.github.com> Date: Thu, 27 Oct 2022 16:24:01 +0800 Subject: [PATCH 3/4] Ran npx prettier against elasticsearch.ts --- packages/server/src/integrations/elasticsearch.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index 51e13b37fa..8cda6692a0 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -100,19 +100,19 @@ class ElasticSearchIntegration implements IntegrationBase { constructor(config: ElasticsearchConfig) { this.config = config - let newConfig = { + let newConfig = { node: this.config.url, - ssl: this.config.ssl + ssl: this.config.ssl ? { - rejectUnauthorized: this.config.rejectUnauthorized, - ca: this.config.ca || undefined, - } + rejectUnauthorized: this.config.rejectUnauthorized, + ca: this.config.ca || undefined, + } : undefined, } if (newConfig.ssl && !newConfig.ssl.ca) { delete newConfig.ssl.ca - } else if(!newConfig.ssl) { + } else if (!newConfig.ssl) { delete newConfig.ssl } this.client = new Client(newConfig) From a45c16bc42cf7a5729d0a8bf28038862efaeeb88 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 4/4] 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 }) {