Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 86bde0e

Browse files
Undo changes that limit ES access
1 parent 48e701d commit 86bde0e

File tree

1 file changed

+6
-72
lines changed

1 file changed

+6
-72
lines changed

src/common/helper.js

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,11 @@ const config = require('config')
77
const elasticsearch = require('elasticsearch')
88
const _ = require('lodash')
99
const Joi = require('@hapi/joi')
10-
const Mutex = require('async-mutex').Mutex
1110

1211
AWS.config.region = config.ES.AWS_REGION
1312

1413
// Elasticsearch client
15-
let esClient = {
16-
mutex: new Mutex(),
17-
client: null,
18-
19-
ctor (client) {
20-
this.client = client
21-
this.indices = {
22-
exists: client.indices.exists.bind(client.indices),
23-
putMapping: client.indices.putMapping.bind(client.indices),
24-
create: client.indices.create.bind(client.indices),
25-
delete: client.indices.delete.bind(client.indices)
26-
}
27-
},
28-
29-
async create () {
30-
const release = await this.mutex.acquire()
31-
32-
try {
33-
return this.client.create(...arguments)
34-
} finally {
35-
release()
36-
}
37-
},
38-
39-
async update () {
40-
const release = await this.mutex.acquire()
41-
42-
try {
43-
return this.client.update(...arguments)
44-
} finally {
45-
release()
46-
}
47-
},
48-
49-
async delete () {
50-
const release = await this.mutex.acquire()
51-
52-
try {
53-
return this.client.delete(...arguments)
54-
} finally {
55-
release()
56-
}
57-
},
58-
59-
async getSource () {
60-
const release = await this.mutex.acquire()
61-
62-
try {
63-
return this.client.getSource(...arguments)
64-
} finally {
65-
release()
66-
}
67-
},
68-
69-
async get () {
70-
const release = await this.mutex.acquire()
71-
72-
try {
73-
return this.client.get(...arguments)
74-
} finally {
75-
release()
76-
}
77-
},
78-
79-
indices: undefined
80-
}
14+
let esClient
8115

8216
/**
8317
* Get Kafka options
@@ -96,7 +30,7 @@ function getKafkaOptions () {
9630
* @return {Object} Elasticsearch Client Instance
9731
*/
9832
async function getESClient () {
99-
if (esClient.client) {
33+
if (esClient) {
10034
return esClient
10135
}
10236
const host = config.ES.HOST
@@ -105,17 +39,17 @@ async function getESClient () {
10539
// AWS ES configuration is different from other providers
10640
if (/.*amazonaws.*/.test(host)) {
10741
try {
108-
esClient.ctor(new elasticsearch.Client({
42+
esClient = new elasticsearch.Client({
10943
apiVersion,
11044
host,
11145
connectionClass: require('http-aws-es') // eslint-disable-line global-require
112-
}))
46+
})
11347
} catch (error) { console.log(error) }
11448
} else {
115-
esClient.ctor(new elasticsearch.Client({
49+
esClient = new elasticsearch.Client({
11650
apiVersion,
11751
host
118-
}))
52+
})
11953
}
12054
return esClient
12155
}

0 commit comments

Comments
 (0)