Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 6fdc9f8

Browse files
cewaldtkostuch
authored andcommitted
Add ES client support for authentication
1 parent 7f5e2d1 commit 6fdc9f8

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"index": "vue_storefront_catalog",
2323
"port": 9200,
2424
"protocol": "http",
25+
"requestTimeout": 5000,
2526
"min_score": 0.01,
2627
"indices": [
2728
"vue_storefront_catalog",

src/lib/elastic.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ function getHits (result) {
6868
}
6969

7070
function getClient (config) {
71-
const esConfig = { // as we're runing tax calculation and other data, we need a ES indexer
72-
node: `${config.elasticsearch.protocol}://${config.elasticsearch.host}:${config.elasticsearch.port}`,
73-
apiVersion: config.elasticsearch.apiVersion,
74-
requestTimeout: 5000
75-
}
71+
let { host, port, protocol, apiVersion, requestTimeout } = config.elasticsearch
72+
const node = `${protocol}://${host}:${port}`
73+
74+
let auth
7675
if (config.elasticsearch.user) {
77-
esConfig.auth = config.elasticsearch.user + ':' + config.elasticsearch.password
76+
const { user, password } = config.elasticsearch
77+
auth = { username: user, password }
7878
}
79-
return new es.Client(esConfig)
79+
80+
return new es.Client({ node, auth, apiVersion, requestTimeout })
8081
}
8182

8283
function putAlias (db, originalName, aliasName, next) {

0 commit comments

Comments
 (0)