1
0
Fork 0
mirror of synced 2024-06-22 16:10:40 +12:00

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 73c39ca4b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 }) {