Implemented custom ssl config in elasticsearch.ts

This commit is contained in:
chaoticefx 2022-10-25 11:59:34 +08:00 committed by GitHub
parent 953306aa66
commit 1ac362f90c
1 changed files with 37 additions and 1 deletions

View File

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