Better message in case of unsupported build flavor (#1498)

This commit is contained in:
Tomas Della Vedova
2021-07-24 16:54:18 +02:00
committed by GitHub
parent 28e57dd2e4
commit 6686316433
4 changed files with 159 additions and 26 deletions

View File

@ -69,7 +69,7 @@ class Transport {
this.generateRequestId = opts.generateRequestId || generateRequestId()
this.name = opts.name
this.opaqueIdPrefix = opts.opaqueIdPrefix
this[kProductCheck] = 0 // 0 = to be checked, 1 = checking, 2 = checked-ok, 3 checked-notok
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.nodeFilter = opts.nodeFilter || defaultNodeFilter
@ -455,9 +455,12 @@ class Transport {
prepareRequest()
} else {
// wait for product check to finish
productCheckEmitter.once('product-check', status => {
productCheckEmitter.once('product-check', (error, status) => {
if (status === false) {
const err = new ProductNotSupportedError(result)
const err = error || new ProductNotSupportedError(result)
if (this[kProductCheck] === 4) {
err.message = 'The client noticed that the server is not a supported distribution of Elasticsearch'
}
this.emit('request', err, result)
process.nextTick(callback, err, result)
} else {
@ -470,8 +473,11 @@ class Transport {
}
}
// the product check is finished and it's not Elasticsearch
} else if (this[kProductCheck] === 3) {
} else if (this[kProductCheck] === 3 || this[kProductCheck] === 4) {
const err = new ProductNotSupportedError(result)
if (this[kProductCheck] === 4) {
err.message = 'The client noticed that the server is not a supported distribution of Elasticsearch'
}
this.emit('request', err, result)
process.nextTick(callback, err, result)
// the product check finished and it's Elasticsearch
@ -550,42 +556,48 @@ class Transport {
if (err.statusCode === 401 || err.statusCode === 403) {
this[kProductCheck] = 2
process.emitWarning('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.')
productCheckEmitter.emit('product-check', true)
productCheckEmitter.emit('product-check', null, true)
} else {
this[kProductCheck] = 0
productCheckEmitter.emit('product-check', false)
productCheckEmitter.emit('product-check', err, false)
}
} else {
debug('Checking elasticsearch version', result.body, result.headers)
if (result.body.version == null || typeof result.body.version.number !== 'string') {
debug('Can\'t access Elasticsearch version')
return productCheckEmitter.emit('product-check', false)
return productCheckEmitter.emit('product-check', null, false)
}
const tagline = result.body.tagline
const version = result.body.version.number.split('.')
const major = Number(version[0])
const minor = Number(version[1])
if (major < 6) {
return productCheckEmitter.emit('product-check', false)
return productCheckEmitter.emit('product-check', null, false)
} else if (major >= 6 && major < 7) {
if (tagline !== 'You Know, for Search') {
debug('Bad tagline')
return productCheckEmitter.emit('product-check', false)
return productCheckEmitter.emit('product-check', null, false)
}
} else if (major === 7 && minor < 14) {
if (tagline !== 'You Know, for Search' || result.body.version.build_flavor !== 'default') {
debug('Bad tagline or build_flavor')
return productCheckEmitter.emit('product-check', false)
if (tagline !== 'You Know, for Search') {
debug('Bad tagline')
return productCheckEmitter.emit('product-check', null, false)
}
if (result.body.version.build_flavor !== 'default') {
debug('Bad build_flavor')
this[kProductCheck] = 4
return productCheckEmitter.emit('product-check', null, false)
}
} else {
if (result.headers['x-elastic-product'] !== 'Elasticsearch') {
debug('x-elastic-product not recognized')
return productCheckEmitter.emit('product-check', false)
return productCheckEmitter.emit('product-check', null, false)
}
}
debug('Valid Elasticsearch distribution')
this[kProductCheck] = 2
productCheckEmitter.emit('product-check', true)
productCheckEmitter.emit('product-check', null, true)
}
})
}