Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7c69f043e5
commit
bb8f397742
@ -36,13 +36,13 @@ const {
|
|||||||
|
|
||||||
const noop = () => {}
|
const noop = () => {}
|
||||||
|
|
||||||
const productCheckEmitter = new EventEmitter()
|
|
||||||
const clientVersion = require('../package.json').version
|
const clientVersion = require('../package.json').version
|
||||||
const userAgent = `elasticsearch-js/${clientVersion} (${os.platform()} ${os.release()}-${os.arch()}; Node.js ${process.version})`
|
const userAgent = `elasticsearch-js/${clientVersion} (${os.platform()} ${os.release()}-${os.arch()}; Node.js ${process.version})`
|
||||||
const MAX_BUFFER_LENGTH = buffer.constants.MAX_LENGTH
|
const MAX_BUFFER_LENGTH = buffer.constants.MAX_LENGTH
|
||||||
const MAX_STRING_LENGTH = buffer.constants.MAX_STRING_LENGTH
|
const MAX_STRING_LENGTH = buffer.constants.MAX_STRING_LENGTH
|
||||||
const kProductCheck = Symbol('product check')
|
const kProductCheck = Symbol('product check')
|
||||||
const kApiVersioning = Symbol('api versioning')
|
const kApiVersioning = Symbol('api versioning')
|
||||||
|
const kEventEmitter = Symbol('event emitter')
|
||||||
|
|
||||||
class Transport {
|
class Transport {
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
@ -71,6 +71,7 @@ class Transport {
|
|||||||
this.opaqueIdPrefix = opts.opaqueIdPrefix
|
this.opaqueIdPrefix = opts.opaqueIdPrefix
|
||||||
this[kProductCheck] = 0 // 0 = to be checked, 1 = checking, 2 = checked-ok, 3 checked-notok, 4 checked-nodefault
|
this[kProductCheck] = 0 // 0 = to be checked, 1 = checking, 2 = checked-ok, 3 checked-notok, 4 checked-nodefault
|
||||||
this[kApiVersioning] = process.env.ELASTIC_CLIENT_APIVERSIONING === 'true'
|
this[kApiVersioning] = process.env.ELASTIC_CLIENT_APIVERSIONING === 'true'
|
||||||
|
this[kEventEmitter] = new EventEmitter()
|
||||||
|
|
||||||
this.nodeFilter = opts.nodeFilter || defaultNodeFilter
|
this.nodeFilter = opts.nodeFilter || defaultNodeFilter
|
||||||
if (typeof opts.nodeSelector === 'function') {
|
if (typeof opts.nodeSelector === 'function') {
|
||||||
@ -460,7 +461,7 @@ class Transport {
|
|||||||
prepareRequest()
|
prepareRequest()
|
||||||
} else {
|
} else {
|
||||||
// wait for product check to finish
|
// wait for product check to finish
|
||||||
productCheckEmitter.once('product-check', (error, status) => {
|
this[kEventEmitter].once('product-check', (error, status) => {
|
||||||
if (status === false) {
|
if (status === false) {
|
||||||
const err = error || new ProductNotSupportedError(result)
|
const err = error || new ProductNotSupportedError(result)
|
||||||
if (this[kProductCheck] === 4) {
|
if (this[kProductCheck] === 4) {
|
||||||
@ -564,48 +565,48 @@ class Transport {
|
|||||||
'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.',
|
'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.',
|
||||||
'ProductNotSupportedSecurityError'
|
'ProductNotSupportedSecurityError'
|
||||||
)
|
)
|
||||||
productCheckEmitter.emit('product-check', null, true)
|
this[kEventEmitter].emit('product-check', null, true)
|
||||||
} else {
|
} else {
|
||||||
this[kProductCheck] = 0
|
this[kProductCheck] = 0
|
||||||
productCheckEmitter.emit('product-check', err, false)
|
this[kEventEmitter].emit('product-check', err, false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug('Checking elasticsearch version', result.body, result.headers)
|
debug('Checking elasticsearch version', result.body, result.headers)
|
||||||
if (result.body.version == null || typeof result.body.version.number !== 'string') {
|
if (result.body.version == null || typeof result.body.version.number !== 'string') {
|
||||||
debug('Can\'t access Elasticsearch version')
|
debug('Can\'t access Elasticsearch version')
|
||||||
return productCheckEmitter.emit('product-check', null, false)
|
return this[kEventEmitter].emit('product-check', null, false)
|
||||||
}
|
}
|
||||||
const tagline = result.body.tagline
|
const tagline = result.body.tagline
|
||||||
const version = result.body.version.number.split('.')
|
const version = result.body.version.number.split('.')
|
||||||
const major = Number(version[0])
|
const major = Number(version[0])
|
||||||
const minor = Number(version[1])
|
const minor = Number(version[1])
|
||||||
if (major < 6) {
|
if (major < 6) {
|
||||||
return productCheckEmitter.emit('product-check', null, false)
|
return this[kEventEmitter].emit('product-check', null, false)
|
||||||
} else if (major >= 6 && major < 7) {
|
} else if (major >= 6 && major < 7) {
|
||||||
if (tagline !== 'You Know, for Search') {
|
if (tagline !== 'You Know, for Search') {
|
||||||
debug('Bad tagline')
|
debug('Bad tagline')
|
||||||
return productCheckEmitter.emit('product-check', null, false)
|
return this[kEventEmitter].emit('product-check', null, false)
|
||||||
}
|
}
|
||||||
} else if (major === 7 && minor < 14) {
|
} else if (major === 7 && minor < 14) {
|
||||||
if (tagline !== 'You Know, for Search') {
|
if (tagline !== 'You Know, for Search') {
|
||||||
debug('Bad tagline')
|
debug('Bad tagline')
|
||||||
return productCheckEmitter.emit('product-check', null, false)
|
return this[kEventEmitter].emit('product-check', null, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.body.version.build_flavor !== 'default') {
|
if (result.body.version.build_flavor !== 'default') {
|
||||||
debug('Bad build_flavor')
|
debug('Bad build_flavor')
|
||||||
this[kProductCheck] = 4
|
this[kProductCheck] = 4
|
||||||
return productCheckEmitter.emit('product-check', null, false)
|
return this[kEventEmitter].emit('product-check', null, false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (result.headers['x-elastic-product'] !== 'Elasticsearch') {
|
if (result.headers['x-elastic-product'] !== 'Elasticsearch') {
|
||||||
debug('x-elastic-product not recognized')
|
debug('x-elastic-product not recognized')
|
||||||
return productCheckEmitter.emit('product-check', null, false)
|
return this[kEventEmitter].emit('product-check', null, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug('Valid Elasticsearch distribution')
|
debug('Valid Elasticsearch distribution')
|
||||||
this[kProductCheck] = 2
|
this[kProductCheck] = 2
|
||||||
productCheckEmitter.emit('product-check', null, true)
|
this[kEventEmitter].emit('product-check', null, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user