-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1450 from pelias/blackmad-higher-levels-es-debug
Add new debugging levels
- Loading branch information
Showing
17 changed files
with
223 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,61 @@ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
|
||
function _sanitize(raw, clean){ | ||
const messages = {errors: [], warnings: []}; | ||
/** | ||
* @param {object} exposeInternalDebugTools property of pelias config | ||
*/ | ||
function _setup(exposeInternalDebugTools) { | ||
return { | ||
sanitize: (raw, clean) => { | ||
const messages = { errors: [], warnings: [] }; | ||
|
||
if(!_.isUndefined(raw.debug) ){ | ||
clean.enableDebug = (typeof raw.debug === 'string') ? isTruthy(raw.debug.toLowerCase()) : isTruthy( raw.debug ); | ||
} | ||
return messages; | ||
} | ||
if (_.isUndefined(raw.debug)) { | ||
return messages; | ||
} | ||
|
||
function _expected() { | ||
return [{ name: 'debug' }]; | ||
} | ||
clean.enableDebug = false; | ||
|
||
if (_.isEqual(raw.debug, {})) { | ||
return messages; | ||
} | ||
|
||
const debugStr = raw.debug.toString().toLowerCase(); | ||
|
||
const debugLevelMapping = { | ||
'false': 0, | ||
'true': 1, | ||
'elastic': 2, | ||
'explain': 3 | ||
}; | ||
|
||
const numericDebugStr = Number(debugStr); | ||
|
||
const debugLevel = isNaN(numericDebugStr) ? debugLevelMapping[debugStr] : numericDebugStr; | ||
|
||
if (_.isNil(debugLevel)) { | ||
messages.errors.push('Unknown debug value: ' + debugStr); | ||
} | ||
|
||
if (debugLevel >= 2 && !exposeInternalDebugTools) { | ||
messages.errors.push('Debug level not enabled: ' + debugStr); | ||
} else { | ||
if (debugLevel >= 1) { | ||
clean.enableDebug = true; | ||
} | ||
if (debugLevel >= 2) { | ||
clean.enableElasticDebug = true; | ||
} | ||
if (debugLevel >= 3) { | ||
clean.enableElasticExplain = true; | ||
} | ||
} | ||
|
||
return messages; | ||
}, | ||
|
||
function isTruthy(val) { | ||
return _.includes( ['true', '1', 1, true], val ); | ||
expected: () => { | ||
return [{ name: 'debug' }]; | ||
}, | ||
}; | ||
} | ||
|
||
module.exports = () => ({ | ||
sanitize: _sanitize, | ||
expected: _expected | ||
}); | ||
module.exports = _setup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
var sanitizeAll = require('../sanitizer/sanitizeAll'); | ||
var type_mapping = require('../helper/type_mapping'); | ||
|
||
// add categories to the sanitizer list | ||
var sanitizers = { | ||
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), | ||
debug: require('../sanitizer/_debug')(), | ||
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), | ||
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), | ||
// depends on the layers and sources sanitizers, must be run after them | ||
sources_and_layers: require('../sanitizer/_sources_and_layers')(), | ||
geonames_deprecation: require('../sanitizer/_geonames_deprecation')(), | ||
size: require('../sanitizer/_size')(/* use defaults*/), | ||
private: require('../sanitizer/_flag_bool')('private', false), | ||
geo_reverse: require('../sanitizer/_geo_reverse')(), | ||
boundary_country: require('../sanitizer/_boundary_country')(), | ||
categories: require('../sanitizer/_categories')(), | ||
request_language: require('../sanitizer/_request_language')() | ||
}; | ||
module.exports.middleware = (_api_pelias_config) => { | ||
// add categories to the sanitizer list | ||
var sanitizers = { | ||
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), | ||
debug: require('../sanitizer/_debug')(_api_pelias_config.exposeInternalDebugTools), | ||
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), | ||
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), | ||
// depends on the layers and sources sanitizers, must be run after them | ||
sources_and_layers: require('../sanitizer/_sources_and_layers')(), | ||
geonames_deprecation: require('../sanitizer/_geonames_deprecation')(), | ||
size: require('../sanitizer/_size')(/* use defaults*/), | ||
private: require('../sanitizer/_flag_bool')('private', false), | ||
geo_reverse: require('../sanitizer/_geo_reverse')(), | ||
boundary_country: require('../sanitizer/_boundary_country')(), | ||
categories: require('../sanitizer/_categories')(), | ||
request_language: require('../sanitizer/_request_language')() | ||
}; | ||
|
||
// middleware | ||
module.exports.middleware = function( req, res, next ){ | ||
sanitizeAll.runAllChecks(req, sanitizers); | ||
next(); | ||
}; | ||
return function( req, res, next ){ | ||
sanitizeAll.runAllChecks(req, sanitizers); | ||
next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
var sanitizeAll = require('../sanitizer/sanitizeAll'), | ||
sanitizers = { | ||
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), | ||
debug: require('../sanitizer/_debug')(), | ||
ids: require('../sanitizer/_ids')(), | ||
private: require('../sanitizer/_flag_bool')('private', false), | ||
categories: require('../sanitizer/_categories')(true), | ||
request_language: require('../sanitizer/_request_language')() | ||
}; | ||
module.exports.middleware = (_api_pelias_config) => { | ||
var sanitizeAll = require('../sanitizer/sanitizeAll'), | ||
sanitizers = { | ||
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), | ||
debug: require('../sanitizer/_debug')(_api_pelias_config.exposeInternalDebugTools), | ||
ids: require('../sanitizer/_ids')(), | ||
private: require('../sanitizer/_flag_bool')('private', false), | ||
categories: require('../sanitizer/_categories')(true), | ||
request_language: require('../sanitizer/_request_language')() | ||
}; | ||
|
||
// middleware | ||
module.exports.middleware = function(req, res, next){ | ||
sanitizeAll.runAllChecks(req, sanitizers); | ||
next(); | ||
}; | ||
return function(req, res, next){ | ||
sanitizeAll.runAllChecks(req, sanitizers); | ||
next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
var type_mapping = require('../helper/type_mapping'); | ||
var sanitizeAll = require('../sanitizer/sanitizeAll'), | ||
sanitizers = { | ||
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), | ||
debug: require('../sanitizer/_debug')(), | ||
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), | ||
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), | ||
// depends on the layers and sources sanitizers, must be run after them | ||
sources_and_layers: require('../sanitizer/_sources_and_layers')(), | ||
geonames_deprecation: require('../sanitizer/_geonames_deprecation')(), | ||
size: require('../sanitizer/_size')(/* use defaults*/), | ||
private: require('../sanitizer/_flag_bool')('private', false), | ||
geo_reverse: require('../sanitizer/_geo_reverse')(), | ||
boundary_country: require('../sanitizer/_boundary_country')(), | ||
request_language: require('../sanitizer/_request_language')(), | ||
boundary_gid: require('../sanitizer/_boundary_gid')() | ||
}; | ||
module.exports.middleware = (_api_pelias_config) => { | ||
var type_mapping = require('../helper/type_mapping'); | ||
var sanitizeAll = require('../sanitizer/sanitizeAll'), | ||
sanitizers = { | ||
singleScalarParameters: require('../sanitizer/_single_scalar_parameters')(), | ||
debug: require('../sanitizer/_debug')(_api_pelias_config.exposeInternalDebugTools), | ||
layers: require('../sanitizer/_targets')('layers', type_mapping.layer_mapping), | ||
sources: require('../sanitizer/_targets')('sources', type_mapping.source_mapping), | ||
// depends on the layers and sources sanitizers, must be run after them | ||
sources_and_layers: require('../sanitizer/_sources_and_layers')(), | ||
geonames_deprecation: require('../sanitizer/_geonames_deprecation')(), | ||
size: require('../sanitizer/_size')(/* use defaults*/), | ||
private: require('../sanitizer/_flag_bool')('private', false), | ||
geo_reverse: require('../sanitizer/_geo_reverse')(), | ||
boundary_country: require('../sanitizer/_boundary_country')(), | ||
request_language: require('../sanitizer/_request_language')(), | ||
boundary_gid: require('../sanitizer/_boundary_gid')() | ||
}; | ||
|
||
// middleware | ||
module.exports.middleware = function( req, res, next ){ | ||
sanitizeAll.runAllChecks(req, sanitizers); | ||
next(); | ||
}; | ||
// middleware | ||
return function( req, res, next ){ | ||
sanitizeAll.runAllChecks(req, sanitizers); | ||
next(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.