1
0
Fork 0
mirror of synced 2024-06-30 12:00:31 +12:00

Cleaned up config declaration in constructor

This commit is contained in:
chaoticefx 2022-11-01 09:08:17 +08:00 committed by GitHub
parent 20a231b842
commit 255c594d04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@ import {
IntegrationBase, IntegrationBase,
} from "@budibase/types" } from "@budibase/types"
const { Client } = require("@elastic/elasticsearch") import { Client, ClientOptions } from "@elastic/elasticsearch"
interface ElasticsearchConfig { interface ElasticsearchConfig {
url: string url: string
@ -100,22 +100,18 @@ class ElasticSearchIntegration implements IntegrationBase {
constructor(config: ElasticsearchConfig) { constructor(config: ElasticsearchConfig) {
this.config = config this.config = config
let newConfig = { const clientConfig: ClientOptions = {
node: this.config.url, node: this.config.url,
ssl: this.config.ssl }
? {
if (this.config.ssl) {
clientConfig.ssl = {
rejectUnauthorized: this.config.rejectUnauthorized, rejectUnauthorized: this.config.rejectUnauthorized,
ca: this.config.ca || undefined, ca: this.config.ca || undefined,
} }
: undefined,
} }
if (newConfig.ssl && !newConfig.ssl.ca) { this.client = new Client(clientConfig)
delete newConfig.ssl.ca
} else if (!newConfig.ssl) {
delete newConfig.ssl
}
this.client = new Client(newConfig)
} }
async create(query: { index: string; json: object }) { async create(query: { index: string; json: object }) {