@opensearch-project/opensearch 1.1.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.eslintrc.json +31 -0
- package/.prettierrc.json +5 -0
- package/.whitesource +15 -0
- package/ADMINS.md +13 -31
- package/CHANGELOG.md +24 -0
- package/COMPATIBILITY.md +27 -0
- package/DEVELOPER_GUIDE.md +22 -5
- package/MAINTAINERS.md +15 -70
- package/Makefile +2 -12
- package/README.md +19 -123
- package/RELEASING.md +3 -3
- package/SECURITY.md +1 -1
- package/USER_GUIDE.md +197 -0
- package/api/api/bulk.js +54 -28
- package/api/api/cat.js +355 -266
- package/api/api/clear_scroll.js +18 -19
- package/api/api/cluster.js +367 -221
- package/api/api/count.js +56 -26
- package/api/api/create.js +51 -26
- package/api/api/dangling_indices.js +96 -53
- package/api/api/delete.js +50 -24
- package/api/api/delete_by_query.js +89 -27
- package/api/api/delete_by_query_rethrottle.js +34 -21
- package/api/api/delete_script.js +32 -19
- package/api/api/exists.js +56 -24
- package/api/api/exists_source.js +61 -29
- package/api/api/explain.js +61 -24
- package/api/api/features.js +57 -37
- package/api/api/field_caps.js +37 -20
- package/api/api/get.js +56 -24
- package/api/api/get_script.js +31 -19
- package/api/api/get_script_context.js +16 -17
- package/api/api/get_script_languages.js +16 -17
- package/api/api/get_source.js +56 -24
- package/api/api/index.js +61 -30
- package/api/api/indices.js +1069 -859
- package/api/api/info.js +16 -17
- package/api/api/ingest.js +133 -98
- package/api/api/mget.js +51 -28
- package/api/api/msearch.js +50 -28
- package/api/api/msearch_template.js +54 -28
- package/api/api/mtermvectors.js +49 -26
- package/api/api/nodes.js +282 -156
- package/api/api/ping.js +16 -17
- package/api/api/put_script.js +41 -27
- package/api/api/rank_eval.js +38 -22
- package/api/api/reindex.js +39 -19
- package/api/api/reindex_rethrottle.js +33 -21
- package/api/api/render_search_template.js +19 -20
- package/api/api/scripts_painless_execute.js +16 -17
- package/api/api/scroll.js +32 -19
- package/api/api/search.js +109 -26
- package/api/api/search_shards.js +37 -20
- package/api/api/search_template.js +65 -28
- package/api/api/shutdown.js +67 -56
- package/api/api/snapshot.js +348 -226
- package/api/api/tasks.js +66 -48
- package/api/api/terms_enum.js +18 -19
- package/api/api/termvectors.js +58 -28
- package/api/api/update.js +65 -26
- package/api/api/update_by_query.js +90 -25
- package/api/api/update_by_query_rethrottle.js +34 -21
- package/api/index.js +268 -181
- package/api/new.d.ts +2043 -531
- package/api/opensearch_dashboards.d.ts +240 -238
- package/api/requestParams.d.ts +302 -71
- package/api/types.d.ts +6205 -5721
- package/api/utils.js +23 -24
- package/codecov.yml +2 -2
- package/index.d.ts +5203 -1037
- package/index.js +154 -143
- package/index.mjs +10 -11
- package/jenkins/release.JenkinsFile +11 -0
- package/lib/Connection.d.ts +38 -28
- package/lib/Connection.js +166 -170
- package/lib/Helpers.d.ts +108 -68
- package/lib/Helpers.js +401 -378
- package/lib/Serializer.d.ts +3 -4
- package/lib/Serializer.js +40 -41
- package/lib/Transport.d.ts +39 -15
- package/lib/Transport.js +381 -337
- package/lib/aws/AwsSigv4Signer.js +167 -0
- package/lib/aws/errors.js +24 -0
- package/lib/aws/index.d.ts +39 -0
- package/lib/aws/index.js +19 -0
- package/lib/errors.d.ts +26 -9
- package/lib/errors.js +76 -73
- package/lib/pool/BaseConnectionPool.js +101 -99
- package/lib/pool/CloudConnectionPool.js +17 -18
- package/lib/pool/ConnectionPool.js +106 -107
- package/lib/pool/index.d.ts +9 -8
- package/lib/pool/index.js +7 -8
- package/package.json +37 -15
package/lib/Connection.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
+
* Copyright OpenSearch Contributors
|
|
2
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
3
4
|
*
|
|
4
5
|
* The OpenSearch Contributors require contributions made to
|
|
5
6
|
* this file be licensed under the Apache-2.0 license or a
|
|
6
7
|
* compatible open source license.
|
|
7
8
|
*
|
|
8
|
-
* Modifications Copyright OpenSearch Contributors. See
|
|
9
|
-
* GitHub history for details.
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
11
|
/*
|
|
@@ -28,189 +27,188 @@
|
|
|
28
27
|
* under the License.
|
|
29
28
|
*/
|
|
30
29
|
|
|
31
|
-
'use strict'
|
|
30
|
+
'use strict';
|
|
32
31
|
|
|
33
|
-
const assert = require('assert')
|
|
34
|
-
const { inspect } = require('util')
|
|
35
|
-
const hpagent = require('hpagent')
|
|
36
|
-
const http = require('http')
|
|
37
|
-
const https = require('https')
|
|
38
|
-
const debug = require('debug')('opensearch')
|
|
39
|
-
const { pipeline } = require('stream')
|
|
40
|
-
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]
|
|
32
|
+
const assert = require('assert');
|
|
33
|
+
const { inspect } = require('util');
|
|
34
|
+
const hpagent = require('hpagent');
|
|
35
|
+
const http = require('http');
|
|
36
|
+
const https = require('https');
|
|
37
|
+
const debug = require('debug')('opensearch');
|
|
38
|
+
const { pipeline } = require('stream');
|
|
39
|
+
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;
|
|
41
40
|
const {
|
|
42
41
|
ConnectionError,
|
|
43
42
|
RequestAbortedError,
|
|
44
43
|
TimeoutError,
|
|
45
|
-
ConfigurationError
|
|
46
|
-
} = require('./errors')
|
|
44
|
+
ConfigurationError,
|
|
45
|
+
} = require('./errors');
|
|
47
46
|
|
|
48
47
|
class Connection {
|
|
49
|
-
constructor
|
|
50
|
-
this.url = opts.url
|
|
51
|
-
this.ssl = opts.ssl || null
|
|
52
|
-
this.id = opts.id || stripAuth(opts.url.href)
|
|
53
|
-
this.headers = prepareHeaders(opts.headers, opts.auth)
|
|
54
|
-
this.deadCount = 0
|
|
55
|
-
this.resurrectTimeout = 0
|
|
56
|
-
|
|
57
|
-
this._openRequests = 0
|
|
58
|
-
this._status = opts.status || Connection.statuses.ALIVE
|
|
59
|
-
this.roles = Object.assign({}, defaultRoles, opts.roles)
|
|
48
|
+
constructor(opts) {
|
|
49
|
+
this.url = opts.url;
|
|
50
|
+
this.ssl = opts.ssl || null;
|
|
51
|
+
this.id = opts.id || stripAuth(opts.url.href);
|
|
52
|
+
this.headers = prepareHeaders(opts.headers, opts.auth);
|
|
53
|
+
this.deadCount = 0;
|
|
54
|
+
this.resurrectTimeout = 0;
|
|
55
|
+
|
|
56
|
+
this._openRequests = 0;
|
|
57
|
+
this._status = opts.status || Connection.statuses.ALIVE;
|
|
58
|
+
this.roles = Object.assign({}, defaultRoles, opts.roles);
|
|
60
59
|
|
|
61
60
|
if (!['http:', 'https:'].includes(this.url.protocol)) {
|
|
62
|
-
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
|
|
61
|
+
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`);
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
if (typeof opts.agent === 'function') {
|
|
66
|
-
this.agent = opts.agent(opts)
|
|
65
|
+
this.agent = opts.agent(opts);
|
|
67
66
|
} else if (opts.agent === false) {
|
|
68
|
-
this.agent = undefined
|
|
67
|
+
this.agent = undefined;
|
|
69
68
|
} else {
|
|
70
|
-
const agentOptions = Object.assign(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
const agentOptions = Object.assign(
|
|
70
|
+
{},
|
|
71
|
+
{
|
|
72
|
+
keepAlive: true,
|
|
73
|
+
keepAliveMsecs: 1000,
|
|
74
|
+
maxSockets: 256,
|
|
75
|
+
maxFreeSockets: 256,
|
|
76
|
+
scheduling: 'lifo',
|
|
77
|
+
},
|
|
78
|
+
opts.agent
|
|
79
|
+
);
|
|
77
80
|
if (opts.proxy) {
|
|
78
|
-
agentOptions.proxy = opts.proxy
|
|
79
|
-
this.agent =
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
agentOptions.proxy = opts.proxy;
|
|
82
|
+
this.agent =
|
|
83
|
+
this.url.protocol === 'http:'
|
|
84
|
+
? new hpagent.HttpProxyAgent(agentOptions)
|
|
85
|
+
: new hpagent.HttpsProxyAgent(Object.assign({}, agentOptions, this.ssl));
|
|
82
86
|
} else {
|
|
83
|
-
this.agent =
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
this.agent =
|
|
88
|
+
this.url.protocol === 'http:'
|
|
89
|
+
? new http.Agent(agentOptions)
|
|
90
|
+
: new https.Agent(Object.assign({}, agentOptions, this.ssl));
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
this.makeRequest = this.url.protocol === 'http:'
|
|
90
|
-
? http.request
|
|
91
|
-
: https.request
|
|
94
|
+
this.makeRequest = this.url.protocol === 'http:' ? http.request : https.request;
|
|
92
95
|
}
|
|
93
96
|
|
|
94
|
-
request
|
|
95
|
-
this._openRequests
|
|
96
|
-
let cleanedListeners = false
|
|
97
|
+
request(params, callback) {
|
|
98
|
+
this._openRequests++;
|
|
99
|
+
let cleanedListeners = false;
|
|
97
100
|
|
|
98
|
-
const requestParams = this.buildRequestObject(params)
|
|
101
|
+
const requestParams = this.buildRequestObject(params);
|
|
99
102
|
// https://github.com/nodejs/node/commit/b961d9fd83
|
|
100
103
|
if (INVALID_PATH_REGEX.test(requestParams.path) === true) {
|
|
101
|
-
callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null)
|
|
104
|
+
callback(new TypeError(`ERR_UNESCAPED_CHARACTERS: ${requestParams.path}`), null);
|
|
102
105
|
/* istanbul ignore next */
|
|
103
|
-
return { abort: () => {
|
|
106
|
+
return { abort: () => {} };
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
debug('Starting a new request', params)
|
|
107
|
-
const request = this.makeRequest(requestParams)
|
|
109
|
+
debug('Starting a new request', params);
|
|
110
|
+
const request = this.makeRequest(requestParams);
|
|
108
111
|
|
|
109
|
-
const onResponse = response => {
|
|
110
|
-
cleanListeners()
|
|
111
|
-
this._openRequests
|
|
112
|
-
callback(null, response)
|
|
113
|
-
}
|
|
112
|
+
const onResponse = (response) => {
|
|
113
|
+
cleanListeners();
|
|
114
|
+
this._openRequests--;
|
|
115
|
+
callback(null, response);
|
|
116
|
+
};
|
|
114
117
|
|
|
115
118
|
const onTimeout = () => {
|
|
116
|
-
cleanListeners()
|
|
117
|
-
this._openRequests
|
|
118
|
-
request.once('error', () => {
|
|
119
|
-
request.abort()
|
|
120
|
-
callback(new TimeoutError('Request timed out', params), null)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const onError = err => {
|
|
124
|
-
cleanListeners()
|
|
125
|
-
this._openRequests
|
|
126
|
-
callback(new ConnectionError(err.message), null)
|
|
127
|
-
}
|
|
119
|
+
cleanListeners();
|
|
120
|
+
this._openRequests--;
|
|
121
|
+
request.once('error', () => {}); // we need to catch the request aborted error
|
|
122
|
+
request.abort();
|
|
123
|
+
callback(new TimeoutError('Request timed out', params), null);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const onError = (err) => {
|
|
127
|
+
cleanListeners();
|
|
128
|
+
this._openRequests--;
|
|
129
|
+
callback(new ConnectionError(err.message), null);
|
|
130
|
+
};
|
|
128
131
|
|
|
129
132
|
const onAbort = () => {
|
|
130
|
-
cleanListeners()
|
|
131
|
-
request.once('error', () => {
|
|
132
|
-
debug('Request aborted', params)
|
|
133
|
-
this._openRequests
|
|
134
|
-
callback(new RequestAbortedError(), null)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
request.on('response', onResponse)
|
|
138
|
-
request.on('timeout', onTimeout)
|
|
139
|
-
request.on('error', onError)
|
|
140
|
-
request.on('abort', onAbort)
|
|
133
|
+
cleanListeners();
|
|
134
|
+
request.once('error', () => {}); // we need to catch the request aborted error
|
|
135
|
+
debug('Request aborted', params);
|
|
136
|
+
this._openRequests--;
|
|
137
|
+
callback(new RequestAbortedError(), null);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
request.on('response', onResponse);
|
|
141
|
+
request.on('timeout', onTimeout);
|
|
142
|
+
request.on('error', onError);
|
|
143
|
+
request.on('abort', onAbort);
|
|
141
144
|
|
|
142
145
|
// Disables the Nagle algorithm
|
|
143
|
-
request.setNoDelay(true)
|
|
146
|
+
request.setNoDelay(true);
|
|
144
147
|
|
|
145
148
|
// starts the request
|
|
146
149
|
if (isStream(params.body) === true) {
|
|
147
|
-
pipeline(params.body, request, err => {
|
|
150
|
+
pipeline(params.body, request, (err) => {
|
|
148
151
|
/* istanbul ignore if */
|
|
149
152
|
if (err != null && cleanedListeners === false) {
|
|
150
|
-
cleanListeners()
|
|
151
|
-
this._openRequests
|
|
152
|
-
callback(err, null)
|
|
153
|
+
cleanListeners();
|
|
154
|
+
this._openRequests--;
|
|
155
|
+
callback(err, null);
|
|
153
156
|
}
|
|
154
|
-
})
|
|
157
|
+
});
|
|
155
158
|
} else {
|
|
156
|
-
request.end(params.body)
|
|
159
|
+
request.end(params.body);
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
return request
|
|
162
|
+
return request;
|
|
160
163
|
|
|
161
|
-
function cleanListeners
|
|
162
|
-
request.removeListener('response', onResponse)
|
|
163
|
-
request.removeListener('timeout', onTimeout)
|
|
164
|
-
request.removeListener('error', onError)
|
|
165
|
-
request.removeListener('abort', onAbort)
|
|
166
|
-
cleanedListeners = true
|
|
164
|
+
function cleanListeners() {
|
|
165
|
+
request.removeListener('response', onResponse);
|
|
166
|
+
request.removeListener('timeout', onTimeout);
|
|
167
|
+
request.removeListener('error', onError);
|
|
168
|
+
request.removeListener('abort', onAbort);
|
|
169
|
+
cleanedListeners = true;
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
// TODO: write a better closing logic
|
|
171
|
-
close
|
|
172
|
-
debug('Closing connection', this.id)
|
|
174
|
+
close(callback = () => {}) {
|
|
175
|
+
debug('Closing connection', this.id);
|
|
173
176
|
if (this._openRequests > 0) {
|
|
174
|
-
setTimeout(() => this.close(callback), 1000)
|
|
177
|
+
setTimeout(() => this.close(callback), 1000);
|
|
175
178
|
} else {
|
|
176
179
|
if (this.agent !== undefined) {
|
|
177
|
-
this.agent.destroy()
|
|
180
|
+
this.agent.destroy();
|
|
178
181
|
}
|
|
179
|
-
callback()
|
|
182
|
+
callback();
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
setRole
|
|
186
|
+
setRole(role, enabled) {
|
|
184
187
|
if (validRoles.indexOf(role) === -1) {
|
|
185
|
-
throw new ConfigurationError(`Unsupported role: '${role}'`)
|
|
188
|
+
throw new ConfigurationError(`Unsupported role: '${role}'`);
|
|
186
189
|
}
|
|
187
190
|
if (typeof enabled !== 'boolean') {
|
|
188
|
-
throw new ConfigurationError('enabled should be a boolean')
|
|
191
|
+
throw new ConfigurationError('enabled should be a boolean');
|
|
189
192
|
}
|
|
190
193
|
|
|
191
|
-
this.roles[role] = enabled
|
|
192
|
-
return this
|
|
194
|
+
this.roles[role] = enabled;
|
|
195
|
+
return this;
|
|
193
196
|
}
|
|
194
197
|
|
|
195
|
-
get status
|
|
196
|
-
return this._status
|
|
198
|
+
get status() {
|
|
199
|
+
return this._status;
|
|
197
200
|
}
|
|
198
201
|
|
|
199
|
-
set status
|
|
200
|
-
assert(
|
|
201
|
-
|
|
202
|
-
`Unsupported status: '${status}'`
|
|
203
|
-
)
|
|
204
|
-
this._status = status
|
|
202
|
+
set status(status) {
|
|
203
|
+
assert(~validStatuses.indexOf(status), `Unsupported status: '${status}'`);
|
|
204
|
+
this._status = status;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
buildRequestObject
|
|
208
|
-
const url = this.url
|
|
207
|
+
buildRequestObject(params) {
|
|
208
|
+
const url = this.url;
|
|
209
209
|
const request = {
|
|
210
210
|
protocol: url.protocol,
|
|
211
|
-
hostname: url.hostname[0] === '['
|
|
212
|
-
? url.hostname.slice(1, -1)
|
|
213
|
-
: url.hostname,
|
|
211
|
+
hostname: url.hostname[0] === '[' ? url.hostname.slice(1, -1) : url.hostname,
|
|
214
212
|
hash: url.hash,
|
|
215
213
|
search: url.search,
|
|
216
214
|
pathname: url.pathname,
|
|
@@ -219,42 +217,40 @@ class Connection {
|
|
|
219
217
|
origin: url.origin,
|
|
220
218
|
// https://github.com/elastic/elasticsearch-js/issues/843
|
|
221
219
|
port: url.port !== '' ? url.port : undefined,
|
|
222
|
-
headers: this.headers,
|
|
223
|
-
agent: this.agent
|
|
224
|
-
}
|
|
220
|
+
headers: Object.assign({}, this.headers),
|
|
221
|
+
agent: this.agent,
|
|
222
|
+
};
|
|
225
223
|
|
|
226
|
-
const paramsKeys = Object.keys(params)
|
|
224
|
+
const paramsKeys = Object.keys(params);
|
|
227
225
|
for (let i = 0, len = paramsKeys.length; i < len; i++) {
|
|
228
|
-
const key = paramsKeys[i]
|
|
226
|
+
const key = paramsKeys[i];
|
|
229
227
|
if (key === 'path') {
|
|
230
|
-
request.pathname = resolve(request.pathname, params[key])
|
|
228
|
+
request.pathname = resolve(request.pathname, params[key]);
|
|
231
229
|
} else if (key === 'querystring' && !!params[key] === true) {
|
|
232
230
|
if (request.search === '') {
|
|
233
|
-
request.search = '?' + params[key]
|
|
231
|
+
request.search = '?' + params[key];
|
|
234
232
|
} else {
|
|
235
|
-
request.search += '&' + params[key]
|
|
233
|
+
request.search += '&' + params[key];
|
|
236
234
|
}
|
|
237
235
|
} else if (key === 'headers') {
|
|
238
|
-
request.headers = Object.assign({}, request.headers, params.headers)
|
|
236
|
+
request.headers = Object.assign({}, request.headers, params.headers);
|
|
239
237
|
} else {
|
|
240
|
-
request[key] = params[key]
|
|
238
|
+
request[key] = params[key];
|
|
241
239
|
}
|
|
242
240
|
}
|
|
243
241
|
|
|
244
|
-
request.path = request.pathname + request.search
|
|
242
|
+
request.path = request.pathname + request.search;
|
|
245
243
|
|
|
246
|
-
return request
|
|
244
|
+
return request;
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
// Handles console.log and utils.inspect invocations.
|
|
250
248
|
// We want to hide `auth`, `agent` and `ssl` since they made
|
|
251
249
|
// the logs very hard to read. The user can still
|
|
252
250
|
// access them with `instance.agent` and `instance.ssl`.
|
|
253
|
-
[inspect.custom]
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
...headers
|
|
257
|
-
} = this.headers
|
|
251
|
+
[inspect.custom]() {
|
|
252
|
+
// eslint-disable-next-line no-unused-vars
|
|
253
|
+
const { authorization, ...headers } = this.headers;
|
|
258
254
|
|
|
259
255
|
return {
|
|
260
256
|
url: stripAuth(this.url.toString()),
|
|
@@ -264,15 +260,13 @@ class Connection {
|
|
|
264
260
|
resurrectTimeout: this.resurrectTimeout,
|
|
265
261
|
_openRequests: this._openRequests,
|
|
266
262
|
status: this.status,
|
|
267
|
-
roles: this.roles
|
|
268
|
-
}
|
|
263
|
+
roles: this.roles,
|
|
264
|
+
};
|
|
269
265
|
}
|
|
270
266
|
|
|
271
|
-
toJSON
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
...headers
|
|
275
|
-
} = this.headers
|
|
267
|
+
toJSON() {
|
|
268
|
+
// eslint-disable-next-line no-unused-vars
|
|
269
|
+
const { authorization, ...headers } = this.headers;
|
|
276
270
|
|
|
277
271
|
return {
|
|
278
272
|
url: stripAuth(this.url.toString()),
|
|
@@ -282,64 +276,66 @@ class Connection {
|
|
|
282
276
|
resurrectTimeout: this.resurrectTimeout,
|
|
283
277
|
_openRequests: this._openRequests,
|
|
284
278
|
status: this.status,
|
|
285
|
-
roles: this.roles
|
|
286
|
-
}
|
|
279
|
+
roles: this.roles,
|
|
280
|
+
};
|
|
287
281
|
}
|
|
288
282
|
}
|
|
289
283
|
|
|
290
284
|
Connection.statuses = {
|
|
291
285
|
ALIVE: 'alive',
|
|
292
|
-
DEAD: 'dead'
|
|
293
|
-
}
|
|
286
|
+
DEAD: 'dead',
|
|
287
|
+
};
|
|
294
288
|
|
|
295
289
|
Connection.roles = {
|
|
290
|
+
CLUSTER_MANAGER: 'cluster_manager',
|
|
291
|
+
/**
|
|
292
|
+
* @deprecated use CLUSTER_MANAGER instead
|
|
293
|
+
*/
|
|
296
294
|
MASTER: 'master',
|
|
297
295
|
DATA: 'data',
|
|
298
|
-
INGEST: 'ingest'
|
|
299
|
-
}
|
|
296
|
+
INGEST: 'ingest',
|
|
297
|
+
};
|
|
300
298
|
|
|
301
299
|
const defaultRoles = {
|
|
302
|
-
[Connection.roles.MASTER]: true,
|
|
303
300
|
[Connection.roles.DATA]: true,
|
|
304
|
-
[Connection.roles.INGEST]: true
|
|
305
|
-
}
|
|
301
|
+
[Connection.roles.INGEST]: true,
|
|
302
|
+
};
|
|
306
303
|
|
|
307
|
-
const validStatuses = Object.keys(Connection.statuses)
|
|
308
|
-
|
|
309
|
-
const validRoles = Object.keys(Connection.roles)
|
|
310
|
-
.map(k => Connection.roles[k])
|
|
304
|
+
const validStatuses = Object.keys(Connection.statuses).map((k) => Connection.statuses[k]);
|
|
305
|
+
const validRoles = Object.keys(Connection.roles).map((k) => Connection.roles[k]);
|
|
311
306
|
|
|
312
|
-
function stripAuth
|
|
313
|
-
if (url.indexOf('@') === -1) return url
|
|
314
|
-
return url.slice(0, url.indexOf('//') + 2) + url.slice(url.indexOf('@') + 1)
|
|
307
|
+
function stripAuth(url) {
|
|
308
|
+
if (url.indexOf('@') === -1) return url;
|
|
309
|
+
return url.slice(0, url.indexOf('//') + 2) + url.slice(url.indexOf('@') + 1);
|
|
315
310
|
}
|
|
316
311
|
|
|
317
|
-
function isStream
|
|
318
|
-
return obj != null && typeof obj.pipe === 'function'
|
|
312
|
+
function isStream(obj) {
|
|
313
|
+
return obj != null && typeof obj.pipe === 'function';
|
|
319
314
|
}
|
|
320
315
|
|
|
321
|
-
function resolve
|
|
322
|
-
const hostEndWithSlash = host[host.length - 1] === '/'
|
|
323
|
-
const pathStartsWithSlash = path[0] === '/'
|
|
316
|
+
function resolve(host, path) {
|
|
317
|
+
const hostEndWithSlash = host[host.length - 1] === '/';
|
|
318
|
+
const pathStartsWithSlash = path[0] === '/';
|
|
324
319
|
|
|
325
320
|
if (hostEndWithSlash === true && pathStartsWithSlash === true) {
|
|
326
|
-
return host + path.slice(1)
|
|
321
|
+
return host + path.slice(1);
|
|
327
322
|
} else if (hostEndWithSlash !== pathStartsWithSlash) {
|
|
328
|
-
return host + path
|
|
323
|
+
return host + path;
|
|
329
324
|
} else {
|
|
330
|
-
return host + '/' + path
|
|
325
|
+
return host + '/' + path;
|
|
331
326
|
}
|
|
332
327
|
}
|
|
333
328
|
|
|
334
|
-
function prepareHeaders
|
|
329
|
+
function prepareHeaders(headers = {}, auth) {
|
|
335
330
|
if (auth != null && headers.authorization == null) {
|
|
336
331
|
/* istanbul ignore else */
|
|
337
332
|
if (auth.username && auth.password) {
|
|
338
|
-
headers.authorization =
|
|
333
|
+
headers.authorization =
|
|
334
|
+
'Basic ' + Buffer.from(`${auth.username}:${auth.password}`).toString('base64');
|
|
339
335
|
}
|
|
340
336
|
}
|
|
341
|
-
return headers
|
|
337
|
+
return headers;
|
|
342
338
|
}
|
|
343
339
|
|
|
344
|
-
module.exports = Connection
|
|
345
|
-
module.exports.internals = { prepareHeaders }
|
|
340
|
+
module.exports = Connection;
|
|
341
|
+
module.exports.internals = { prepareHeaders };
|