Merge pull request #8386 from chaoticefx/elasticsearch-rejectUnauthorized

Custom ssl config for Elasticsearch datasource
This commit is contained in:
Rory Powell 2022-11-01 08:47:27 +00:00 committed by GitHub
commit bf35717449
1 changed files with 32 additions and 2 deletions

View File

@ -5,10 +5,13 @@ import {
IntegrationBase,
} from "@budibase/types"
const { Client } = require("@elastic/elasticsearch")
import { Client, ClientOptions } from "@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,19 @@ class ElasticSearchIntegration implements IntegrationBase {
constructor(config: ElasticsearchConfig) {
this.config = config
this.client = new Client({ node: config.url })
const clientConfig: ClientOptions = {
node: this.config.url,
}
if (this.config.ssl) {
clientConfig.ssl = {
rejectUnauthorized: this.config.rejectUnauthorized,
ca: this.config.ca || undefined,
}
}
this.client = new Client(clientConfig)
}
async create(query: { index: string; json: object }) {