From 4a0689d8cb9af0f5ee19426963b68754b6b4dc5d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2019 23:01:40 +0000 Subject: [PATCH 1/2] fix(package): update @hapi/joi to version 16.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7069a43..8ecb591 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "tape": "^4.4.0" }, "dependencies": { - "@hapi/joi": "^15.0.0", + "@hapi/joi": "^16.0.0", "elasticsearch": "^16.0.0", "pelias-config": "^4.5.0", "pelias-logger": "^1.2.1", From 99eff3cbb3bc2cec41d226e8505f65b22f18e463 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 25 Nov 2019 10:50:02 -0500 Subject: [PATCH 2/2] chore(schema): Update validation for new version of joi --- src/configValidation.js | 58 ++++++++++++++++++---------------------- test/configValidation.js | 20 +++++++------- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/configValidation.js b/src/configValidation.js index 3f4631d..a379c40 100644 --- a/src/configValidation.js +++ b/src/configValidation.js @@ -7,46 +7,40 @@ const elasticsearch = require('elasticsearch'); // dbclient.statFrequency: populated by defaults if not overridden // esclient: object, validation performed by elasticsearch module const schema = Joi.object().keys({ - dbclient: { - statFrequency: Joi.number().integer().min(0) - }, - esclient: Joi.object().keys({ + dbclient: Joi.object().required().keys({ + statFrequency: Joi.number().integer().min(0).required() + }), + esclient: Joi.object().required().keys({ requestTimeout: Joi.number().integer().min(0) }).unknown(true), schema: Joi.object().keys({ - indexName: Joi.string(), - typeName: Joi.string() + indexName: Joi.string().required(), + typeName: Joi.string().required() }) -}).requiredKeys( - 'dbclient', 'dbclient.statFrequency', 'esclient', - 'schema.indexName', 'schema.typeName' -).unknown(true); +}).unknown(true); module.exports = { validate: function validate(config) { - Joi.validate(config, schema, (err, value) => { - if (err) { - throw new Error(err.details[0].message); + const validate = schema.validate(config); + if (validate.error) { + throw new Error(validate.error.details[0].message); + } + + // now verify that the index exists + const esclient = new elasticsearch.Client(config.esclient); + + // callback that throws an error if the index doesn't exist + const existsCallback = (error, exists) => { + if (!exists) { + console.error(`ERROR: Elasticsearch index ${config.schema.indexName} does not exist`); + console.error('You must use the pelias-schema tool (https://github.com/pelias/schema/) to create the index first'); + console.error('For full instructions on setting up Pelias, see http://pelias.io/install.html'); + + throw new Error(`elasticsearch index ${config.schema.indexName} does not exist`); } + }; - // now verify that the index exists - const esclient = new elasticsearch.Client(config.esclient); - - // callback that throws an error if the index doesn't exist - const existsCallback = (error, exists) => { - if (!exists) { - console.error(`ERROR: Elasticsearch index ${config.schema.indexName} does not exist`); - console.error('You must use the pelias-schema tool (https://github.com/pelias/schema/) to create the index first'); - console.error('For full instructions on setting up Pelias, see http://pelias.io/install.html'); - - throw new Error(`elasticsearch index ${config.schema.indexName} does not exist`); - } - }; - - // can also be done with promises but it's hard to test mixing the paradigms - esclient.indices.exists({ index: config.schema.indexName }, existsCallback); - - }); + // can also be done with promises but it's hard to test mixing the paradigms + esclient.indices.exists({ index: config.schema.indexName }, existsCallback); } - }; diff --git a/test/configValidation.js b/test/configValidation.js index 03d7a99..154f2a3 100644 --- a/test/configValidation.js +++ b/test/configValidation.js @@ -35,7 +35,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"statFrequency" is required/, 'dbclient.statFrequency should exist'); + }, /"dbclient.statFrequency" is required/, 'dbclient.statFrequency should exist'); t.end(); }); @@ -55,7 +55,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"statFrequency" must be a number/, 'dbclient.statFrequency should be a number'); + }, /"dbclient.statFrequency" must be a number/, 'dbclient.statFrequency should be a number'); }); @@ -77,7 +77,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"statFrequency" must be an integer/, 'dbclient.statFrequency should be an integer'); + }, /"dbclient.statFrequency" must be an integer/, 'dbclient.statFrequency should be an integer'); t.end(); @@ -98,7 +98,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"esclient" must be an object/, 'esclient should be an object'); + }, /"esclient" must be of type object/, 'esclient should be an object'); }); @@ -123,7 +123,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"requestTimeout" must be a number/, 'esclient.requestTimeout should be a number'); + }, /"esclient.requestTimeout" must be a number/, 'esclient.requestTimeout should be a number'); }); t.end(); @@ -146,7 +146,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"requestTimeout" must be an integer/, 'esclient.requestTimeout should be an integer'); + }, /"esclient.requestTimeout" must be an integer/, 'esclient.requestTimeout should be an integer'); t.end(); @@ -168,7 +168,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"requestTimeout" must be larger than or equal to 0/, 'esclient.requestTimeout must be positive'); + }, /"esclient.requestTimeout" must be larger than or equal to 0/, 'esclient.requestTimeout must be positive'); t.end(); @@ -186,7 +186,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"schema" must be an object/); + }, /"schema" must be of type object/); }); @@ -208,7 +208,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"indexName" must be a string/); + }, /"schema.indexName" must be a string/); }); @@ -227,7 +227,7 @@ module.exports.tests.validate = function(test, common) { t.throws(function() { configValidation.validate(config); - }, /"indexName" is required/); + }, /"schema.indexName" is required/); t.end(); });