fix
This commit is contained in:
parent
dac484780c
commit
ebf5eeba48
16
main.js
16
main.js
|
@ -14,7 +14,7 @@ if (!fs.existsSync(configFile)) {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
const findAll = `Client`;
|
||||
const findAll = `Clientaaaa`;
|
||||
|
||||
const config = require(configFile);
|
||||
const grafanaUrl = config.grafanaUrl;
|
||||
|
@ -63,35 +63,32 @@ async function main(){
|
|||
const credentials = `Basic ` + Buffer.from(`${user}:${passw}`).toString('base64');
|
||||
|
||||
console.clear();
|
||||
console.log(colors.green.bold(`-------------------- Starting process --------------------`));
|
||||
console.log(colors.green.bold(`-------------------- Starting process --------------------\n`));
|
||||
|
||||
let responseAllUID = await fetch(urlDashboards, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": credentials
|
||||
Authorization: credentials
|
||||
}
|
||||
});
|
||||
|
||||
let allUID = await responseAllUID.json();
|
||||
|
||||
if (allUID.message=='invalid username or password') {
|
||||
console.error(`Invalid username or password`.red);
|
||||
console.error(`Invalid username or password\n`.red);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
||||
for (let i=0; i < allUID.length; i++) {
|
||||
|
||||
let url = urlUID + allUID[i].uid;
|
||||
let response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": credentials,
|
||||
Authorization: credentials,
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
let data = await response.json();
|
||||
|
||||
let isFound = false;
|
||||
|
@ -134,6 +131,7 @@ async function main(){
|
|||
console.log(colors.magenta.bold(`> ${numberOfVariables} variables`));
|
||||
console.log(colors.magenta(nameVariables.toString().split(",")));
|
||||
}
|
||||
console.log('')
|
||||
numberOfDashboards++;
|
||||
}
|
||||
|
||||
|
@ -145,7 +143,7 @@ async function main(){
|
|||
}
|
||||
|
||||
if (numberOfDashboards==0)
|
||||
console.log(`No results found`.red);
|
||||
console.log(`No results found\n`.red);
|
||||
else
|
||||
console.log(colors.green.bold(`-------- Have been found ${numberOfObjects} results in ${numberOfDashboards} dashboards -------`));
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "findAll-Grafana",
|
||||
"name": "grafana-find",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
@ -35,6 +35,14 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/object-hash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/tr46": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 object-hash contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,453 @@
|
|||
'use strict';
|
||||
|
||||
var crypto = require('crypto');
|
||||
|
||||
/**
|
||||
* Exported function
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
|
||||
* - `excludeValues` {true|*false} hash object keys, values ignored
|
||||
* - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
|
||||
* - `ignoreUnknown` {true|*false} ignore unknown object types
|
||||
* - `replacer` optional function that replaces values before hashing
|
||||
* - `respectFunctionProperties` {*true|false} consider function properties when hashing
|
||||
* - `respectFunctionNames` {*true|false} consider 'name' property of functions for hashing
|
||||
* - `respectType` {*true|false} Respect special properties (prototype, constructor)
|
||||
* when hashing to distinguish between types
|
||||
* - `unorderedArrays` {true|*false} Sort all arrays before hashing
|
||||
* - `unorderedSets` {*true|false} Sort `Set` and `Map` instances before hashing
|
||||
* * = default
|
||||
*
|
||||
* @param {object} object value to hash
|
||||
* @param {object} options hashing options
|
||||
* @return {string} hash value
|
||||
* @api public
|
||||
*/
|
||||
exports = module.exports = objectHash;
|
||||
|
||||
function objectHash(object, options){
|
||||
options = applyDefaults(object, options);
|
||||
|
||||
return hash(object, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exported sugar methods
|
||||
*
|
||||
* @param {object} object value to hash
|
||||
* @return {string} hash value
|
||||
* @api public
|
||||
*/
|
||||
exports.sha1 = function(object){
|
||||
return objectHash(object);
|
||||
};
|
||||
exports.keys = function(object){
|
||||
return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});
|
||||
};
|
||||
exports.MD5 = function(object){
|
||||
return objectHash(object, {algorithm: 'md5', encoding: 'hex'});
|
||||
};
|
||||
exports.keysMD5 = function(object){
|
||||
return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});
|
||||
};
|
||||
|
||||
// Internals
|
||||
var hashes = crypto.getHashes ? crypto.getHashes().slice() : ['sha1', 'md5'];
|
||||
hashes.push('passthrough');
|
||||
var encodings = ['buffer', 'hex', 'binary', 'base64'];
|
||||
|
||||
function applyDefaults(object, sourceOptions){
|
||||
sourceOptions = sourceOptions || {};
|
||||
|
||||
// create a copy rather than mutating
|
||||
var options = {};
|
||||
options.algorithm = sourceOptions.algorithm || 'sha1';
|
||||
options.encoding = sourceOptions.encoding || 'hex';
|
||||
options.excludeValues = sourceOptions.excludeValues ? true : false;
|
||||
options.algorithm = options.algorithm.toLowerCase();
|
||||
options.encoding = options.encoding.toLowerCase();
|
||||
options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true; // default to false
|
||||
options.respectType = sourceOptions.respectType === false ? false : true; // default to true
|
||||
options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
|
||||
options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
|
||||
options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true; // default to false
|
||||
options.unorderedSets = sourceOptions.unorderedSets === false ? false : true; // default to false
|
||||
options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true
|
||||
options.replacer = sourceOptions.replacer || undefined;
|
||||
options.excludeKeys = sourceOptions.excludeKeys || undefined;
|
||||
|
||||
if(typeof object === 'undefined') {
|
||||
throw new Error('Object argument required.');
|
||||
}
|
||||
|
||||
// if there is a case-insensitive match in the hashes list, accept it
|
||||
// (i.e. SHA256 for sha256)
|
||||
for (var i = 0; i < hashes.length; ++i) {
|
||||
if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
|
||||
options.algorithm = hashes[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(hashes.indexOf(options.algorithm) === -1){
|
||||
throw new Error('Algorithm "' + options.algorithm + '" not supported. ' +
|
||||
'supported values: ' + hashes.join(', '));
|
||||
}
|
||||
|
||||
if(encodings.indexOf(options.encoding) === -1 &&
|
||||
options.algorithm !== 'passthrough'){
|
||||
throw new Error('Encoding "' + options.encoding + '" not supported. ' +
|
||||
'supported values: ' + encodings.join(', '));
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/** Check if the given function is a native function */
|
||||
function isNativeFunction(f) {
|
||||
if ((typeof f) !== 'function') {
|
||||
return false;
|
||||
}
|
||||
var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
|
||||
return exp.exec(Function.prototype.toString.call(f)) != null;
|
||||
}
|
||||
|
||||
function hash(object, options) {
|
||||
var hashingStream;
|
||||
|
||||
if (options.algorithm !== 'passthrough') {
|
||||
hashingStream = crypto.createHash(options.algorithm);
|
||||
} else {
|
||||
hashingStream = new PassThrough();
|
||||
}
|
||||
|
||||
if (typeof hashingStream.write === 'undefined') {
|
||||
hashingStream.write = hashingStream.update;
|
||||
hashingStream.end = hashingStream.update;
|
||||
}
|
||||
|
||||
var hasher = typeHasher(options, hashingStream);
|
||||
hasher.dispatch(object);
|
||||
if (!hashingStream.update) {
|
||||
hashingStream.end('');
|
||||
}
|
||||
|
||||
if (hashingStream.digest) {
|
||||
return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding);
|
||||
}
|
||||
|
||||
var buf = hashingStream.read();
|
||||
if (options.encoding === 'buffer') {
|
||||
return buf;
|
||||
}
|
||||
|
||||
return buf.toString(options.encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose streaming API
|
||||
*
|
||||
* @param {object} object Value to serialize
|
||||
* @param {object} options Options, as for hash()
|
||||
* @param {object} stream A stream to write the serializiation to
|
||||
* @api public
|
||||
*/
|
||||
exports.writeToStream = function(object, options, stream) {
|
||||
if (typeof stream === 'undefined') {
|
||||
stream = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = applyDefaults(object, options);
|
||||
|
||||
return typeHasher(options, stream).dispatch(object);
|
||||
};
|
||||
|
||||
function typeHasher(options, writeTo, context){
|
||||
context = context || [];
|
||||
var write = function(str) {
|
||||
if (writeTo.update) {
|
||||
return writeTo.update(str, 'utf8');
|
||||
} else {
|
||||
return writeTo.write(str, 'utf8');
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
dispatch: function(value){
|
||||
if (options.replacer) {
|
||||
value = options.replacer(value);
|
||||
}
|
||||
|
||||
var type = typeof value;
|
||||
if (value === null) {
|
||||
type = 'null';
|
||||
}
|
||||
|
||||
//console.log("[DEBUG] Dispatch: ", value, "->", type, " -> ", "_" + type);
|
||||
|
||||
return this['_' + type](value);
|
||||
},
|
||||
_object: function(object) {
|
||||
var pattern = (/\[object (.*)\]/i);
|
||||
var objString = Object.prototype.toString.call(object);
|
||||
var objType = pattern.exec(objString);
|
||||
if (!objType) { // object type did not match [object ...]
|
||||
objType = 'unknown:[' + objString + ']';
|
||||
} else {
|
||||
objType = objType[1]; // take only the class name
|
||||
}
|
||||
|
||||
objType = objType.toLowerCase();
|
||||
|
||||
var objectNumber = null;
|
||||
|
||||
if ((objectNumber = context.indexOf(object)) >= 0) {
|
||||
return this.dispatch('[CIRCULAR:' + objectNumber + ']');
|
||||
} else {
|
||||
context.push(object);
|
||||
}
|
||||
|
||||
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
||||
write('buffer:');
|
||||
return write(object);
|
||||
}
|
||||
|
||||
if(objType !== 'object' && objType !== 'function' && objType !== 'asyncfunction') {
|
||||
if(this['_' + objType]) {
|
||||
this['_' + objType](object);
|
||||
} else if (options.ignoreUnknown) {
|
||||
return write('[' + objType + ']');
|
||||
} else {
|
||||
throw new Error('Unknown object type "' + objType + '"');
|
||||
}
|
||||
}else{
|
||||
var keys = Object.keys(object);
|
||||
if (options.unorderedObjects) {
|
||||
keys = keys.sort();
|
||||
}
|
||||
// Make sure to incorporate special properties, so
|
||||
// Types with different prototypes will produce
|
||||
// a different hash and objects derived from
|
||||
// different functions (`new Foo`, `new Bar`) will
|
||||
// produce different hashes.
|
||||
// We never do this for native functions since some
|
||||
// seem to break because of that.
|
||||
if (options.respectType !== false && !isNativeFunction(object)) {
|
||||
keys.splice(0, 0, 'prototype', '__proto__', 'constructor');
|
||||
}
|
||||
|
||||
if (options.excludeKeys) {
|
||||
keys = keys.filter(function(key) { return !options.excludeKeys(key); });
|
||||
}
|
||||
|
||||
write('object:' + keys.length + ':');
|
||||
var self = this;
|
||||
return keys.forEach(function(key){
|
||||
self.dispatch(key);
|
||||
write(':');
|
||||
if(!options.excludeValues) {
|
||||
self.dispatch(object[key]);
|
||||
}
|
||||
write(',');
|
||||
});
|
||||
}
|
||||
},
|
||||
_array: function(arr, unordered){
|
||||
unordered = typeof unordered !== 'undefined' ? unordered :
|
||||
options.unorderedArrays !== false; // default to options.unorderedArrays
|
||||
|
||||
var self = this;
|
||||
write('array:' + arr.length + ':');
|
||||
if (!unordered || arr.length <= 1) {
|
||||
return arr.forEach(function(entry) {
|
||||
return self.dispatch(entry);
|
||||
});
|
||||
}
|
||||
|
||||
// the unordered case is a little more complicated:
|
||||
// since there is no canonical ordering on objects,
|
||||
// i.e. {a:1} < {a:2} and {a:1} > {a:2} are both false,
|
||||
// we first serialize each entry using a PassThrough stream
|
||||
// before sorting.
|
||||
// also: we can’t use the same context array for all entries
|
||||
// since the order of hashing should *not* matter. instead,
|
||||
// we keep track of the additions to a copy of the context array
|
||||
// and add all of them to the global context array when we’re done
|
||||
var contextAdditions = [];
|
||||
var entries = arr.map(function(entry) {
|
||||
var strm = new PassThrough();
|
||||
var localContext = context.slice(); // make copy
|
||||
var hasher = typeHasher(options, strm, localContext);
|
||||
hasher.dispatch(entry);
|
||||
// take only what was added to localContext and append it to contextAdditions
|
||||
contextAdditions = contextAdditions.concat(localContext.slice(context.length));
|
||||
return strm.read().toString();
|
||||
});
|
||||
context = context.concat(contextAdditions);
|
||||
entries.sort();
|
||||
return this._array(entries, false);
|
||||
},
|
||||
_date: function(date){
|
||||
return write('date:' + date.toJSON());
|
||||
},
|
||||
_symbol: function(sym){
|
||||
return write('symbol:' + sym.toString());
|
||||
},
|
||||
_error: function(err){
|
||||
return write('error:' + err.toString());
|
||||
},
|
||||
_boolean: function(bool){
|
||||
return write('bool:' + bool.toString());
|
||||
},
|
||||
_string: function(string){
|
||||
write('string:' + string.length + ':');
|
||||
write(string.toString());
|
||||
},
|
||||
_function: function(fn){
|
||||
write('fn:');
|
||||
if (isNativeFunction(fn)) {
|
||||
this.dispatch('[native]');
|
||||
} else {
|
||||
this.dispatch(fn.toString());
|
||||
}
|
||||
|
||||
if (options.respectFunctionNames !== false) {
|
||||
// Make sure we can still distinguish native functions
|
||||
// by their name, otherwise String and Function will
|
||||
// have the same hash
|
||||
this.dispatch("function-name:" + String(fn.name));
|
||||
}
|
||||
|
||||
if (options.respectFunctionProperties) {
|
||||
this._object(fn);
|
||||
}
|
||||
},
|
||||
_number: function(number){
|
||||
return write('number:' + number.toString());
|
||||
},
|
||||
_xml: function(xml){
|
||||
return write('xml:' + xml.toString());
|
||||
},
|
||||
_null: function() {
|
||||
return write('Null');
|
||||
},
|
||||
_undefined: function() {
|
||||
return write('Undefined');
|
||||
},
|
||||
_regexp: function(regex){
|
||||
return write('regex:' + regex.toString());
|
||||
},
|
||||
_uint8array: function(arr){
|
||||
write('uint8array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint8clampedarray: function(arr){
|
||||
write('uint8clampedarray:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int8array: function(arr){
|
||||
write('int8array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint16array: function(arr){
|
||||
write('uint16array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int16array: function(arr){
|
||||
write('int16array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_uint32array: function(arr){
|
||||
write('uint32array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_int32array: function(arr){
|
||||
write('int32array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_float32array: function(arr){
|
||||
write('float32array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_float64array: function(arr){
|
||||
write('float64array:');
|
||||
return this.dispatch(Array.prototype.slice.call(arr));
|
||||
},
|
||||
_arraybuffer: function(arr){
|
||||
write('arraybuffer:');
|
||||
return this.dispatch(new Uint8Array(arr));
|
||||
},
|
||||
_url: function(url) {
|
||||
return write('url:' + url.toString(), 'utf8');
|
||||
},
|
||||
_map: function(map) {
|
||||
write('map:');
|
||||
var arr = Array.from(map);
|
||||
return this._array(arr, options.unorderedSets !== false);
|
||||
},
|
||||
_set: function(set) {
|
||||
write('set:');
|
||||
var arr = Array.from(set);
|
||||
return this._array(arr, options.unorderedSets !== false);
|
||||
},
|
||||
_file: function(file) {
|
||||
write('file:');
|
||||
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
||||
},
|
||||
_blob: function() {
|
||||
if (options.ignoreUnknown) {
|
||||
return write('[blob]');
|
||||
}
|
||||
|
||||
throw Error('Hashing Blob objects is currently not supported\n' +
|
||||
'(see https://github.com/puleos/object-hash/issues/26)\n' +
|
||||
'Use "options.replacer" or "options.ignoreUnknown"\n');
|
||||
},
|
||||
_domwindow: function() { return write('domwindow'); },
|
||||
_bigint: function(number){
|
||||
return write('bigint:' + number.toString());
|
||||
},
|
||||
/* Node.js standard native objects */
|
||||
_process: function() { return write('process'); },
|
||||
_timer: function() { return write('timer'); },
|
||||
_pipe: function() { return write('pipe'); },
|
||||
_tcp: function() { return write('tcp'); },
|
||||
_udp: function() { return write('udp'); },
|
||||
_tty: function() { return write('tty'); },
|
||||
_statwatcher: function() { return write('statwatcher'); },
|
||||
_securecontext: function() { return write('securecontext'); },
|
||||
_connection: function() { return write('connection'); },
|
||||
_zlib: function() { return write('zlib'); },
|
||||
_context: function() { return write('context'); },
|
||||
_nodescript: function() { return write('nodescript'); },
|
||||
_httpparser: function() { return write('httpparser'); },
|
||||
_dataview: function() { return write('dataview'); },
|
||||
_signal: function() { return write('signal'); },
|
||||
_fsevent: function() { return write('fsevent'); },
|
||||
_tlswrap: function() { return write('tlswrap'); },
|
||||
};
|
||||
}
|
||||
|
||||
// Mini-implementation of stream.PassThrough
|
||||
// We are far from having need for the full implementation, and we can
|
||||
// make assumptions like "many writes, then only one final read"
|
||||
// and we can ignore encoding specifics
|
||||
function PassThrough() {
|
||||
return {
|
||||
buf: '',
|
||||
|
||||
write: function(b) {
|
||||
this.buf += b;
|
||||
},
|
||||
|
||||
end: function(b) {
|
||||
this.buf += b;
|
||||
},
|
||||
|
||||
read: function() {
|
||||
return this.buf;
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"name": "object-hash",
|
||||
"version": "3.0.0",
|
||||
"description": "Generate hashes from javascript objects in node and the browser.",
|
||||
"homepage": "https://github.com/puleos/object-hash",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/puleos/object-hash"
|
||||
},
|
||||
"keywords": [
|
||||
"object",
|
||||
"hash",
|
||||
"sha1",
|
||||
"md5"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/puleos/object-hash/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node ./node_modules/.bin/mocha test",
|
||||
"prepublish": "gulp dist"
|
||||
},
|
||||
"author": "Scott Puleo <puleos@gmail.com>",
|
||||
"files": [
|
||||
"index.js",
|
||||
"dist/object_hash.js"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
"gulp": "^4.0.0",
|
||||
"gulp-browserify": "^0.5.1",
|
||||
"gulp-coveralls": "^0.1.4",
|
||||
"gulp-exec": "^3.0.1",
|
||||
"gulp-istanbul": "^1.1.3",
|
||||
"gulp-jshint": "^2.0.0",
|
||||
"gulp-mocha": "^5.0.0",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-replace": "^1.0.0",
|
||||
"gulp-uglify": "^3.0.0",
|
||||
"jshint": "^2.8.0",
|
||||
"jshint-stylish": "^2.1.0",
|
||||
"karma": "^4.2.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"mocha": "^6.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
},
|
||||
"main": "./index.js",
|
||||
"browser": "./dist/object_hash.js"
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
# object-hash
|
||||
|
||||
Generate hashes from objects and values in node and the browser. Uses node.js
|
||||
crypto module for hashing. Supports SHA1 and many others (depending on the platform)
|
||||
as well as custom streams (e.g. CRC32).
|
||||
|
||||
[](https://www.npmjs.com/package/object-hash)
|
||||
|
||||
[](https://secure.travis-ci.org/puleos/object-hash?branch=master)
|
||||
[](https://coveralls.io/github/puleos/object-hash?branch=master)
|
||||
|
||||
* Hash values of any type.
|
||||
* Supports a keys only option for grouping similar objects with different values.
|
||||
|
||||
```js
|
||||
var hash = require('object-hash');
|
||||
|
||||
hash({foo: 'bar'}) // => '67b69634f9880a282c14a0f0cb7ba20cf5d677e9'
|
||||
hash([1, 2, 2.718, 3.14159]) // => '136b9b88375971dff9f1af09d7356e3e04281951'
|
||||
```
|
||||
|
||||
## Versioning Disclaimer
|
||||
|
||||
Starting with version `1.1.8` (released April 2017), new versions will consider
|
||||
the exact returned hash part of the API contract, i.e. changes that will affect
|
||||
hash values will be considered `semver-major`. Previous versions may violate
|
||||
that expectation.
|
||||
|
||||
For more information, see [this discussion](https://github.com/puleos/object-hash/issues/30).
|
||||
|
||||
## hash(value, options)
|
||||
|
||||
Generate a hash from any object or type. Defaults to sha1 with hex encoding.
|
||||
|
||||
* `algorithm` hash algo to be used: 'sha1', 'md5', 'passthrough'. default: sha1
|
||||
* This supports the algorithms returned by `crypto.getHashes()`. Note that the default of SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
|
||||
* This also supports the `passthrough` algorith, which will return the information that would otherwise have been hashed.
|
||||
* `excludeValues` {true|false} hash object keys, values ignored. default: false
|
||||
* `encoding` hash encoding, supports 'buffer', 'hex', 'binary', 'base64'. default: hex
|
||||
* `ignoreUnknown` {true|*false} ignore unknown object types. default: false
|
||||
* `replacer` optional function that replaces values before hashing. default: accept all values
|
||||
* `respectFunctionProperties` {true|false} Whether properties on functions are considered when hashing. default: true
|
||||
* `respectFunctionNames` {true|false} consider `name` property of functions for hashing. default: true
|
||||
* `respectType` {true|false} Whether special type attributes (`.prototype`, `.__proto__`, `.constructor`)
|
||||
are hashed. default: true
|
||||
* `unorderedArrays` {true|false} Sort all arrays before hashing. Note that this affects *all* collections,
|
||||
i.e. including typed arrays, Sets, Maps, etc. default: false
|
||||
* `unorderedSets` {true|false} Sort `Set` and `Map` instances before hashing, i.e. make
|
||||
`hash(new Set([1, 2])) == hash(new Set([2, 1]))` return `true`. default: true
|
||||
* `unorderedObjects` {true|false} Sort objects before hashing, i.e. make `hash({ x: 1, y: 2 }) === hash({ y: 2, x: 1 })`. default: true
|
||||
* `excludeKeys` optional function for excluding specific key(s) from hashing, if true is returned then exclude from hash. default: include all keys
|
||||
|
||||
## hash.sha1(value)
|
||||
|
||||
Hash using the sha1 algorithm.
|
||||
|
||||
Note that SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
|
||||
|
||||
*Sugar method, equivalent to* `hash(value, {algorithm: 'sha1'})`
|
||||
|
||||
## hash.keys(value)
|
||||
|
||||
Hash object keys using the sha1 algorithm, values ignored.
|
||||
|
||||
*Sugar method, equivalent to* `hash(value, {excludeValues: true})`
|
||||
|
||||
## hash.MD5(value)
|
||||
|
||||
Hash using the md5 algorithm.
|
||||
|
||||
Note that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
|
||||
|
||||
*Sugar method, equivalent to* `hash(value, {algorithm: 'md5'})`
|
||||
|
||||
## hash.keysMD5(value)
|
||||
|
||||
Hash object keys using the md5 algorithm, values ignored.
|
||||
|
||||
Note that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.
|
||||
|
||||
*Sugar method, equivalent to* `hash(value, {algorithm: 'md5', excludeValues: true})`
|
||||
|
||||
## hash.writeToStream(value, [options,] stream)
|
||||
|
||||
Write the information that would otherwise have been hashed to a stream, e.g.:
|
||||
|
||||
```js
|
||||
hash.writeToStream({foo: 'bar', a: 42}, {respectType: false}, process.stdout)
|
||||
// => e.g. 'object:a:number:42foo:string:bar'
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
node:
|
||||
|
||||
```js
|
||||
npm install object-hash
|
||||
```
|
||||
|
||||
browser: */dist/object_hash.js*
|
||||
|
||||
```html
|
||||
<script src="object_hash.js" type="text/javascript"></script>
|
||||
|
||||
<script>
|
||||
var hash = objectHash.sha1({foo:'bar'});
|
||||
|
||||
console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9
|
||||
</script>
|
||||
```
|
||||
|
||||
## Example usage
|
||||
|
||||
```js
|
||||
var hash = require('object-hash');
|
||||
|
||||
var peter = { name: 'Peter', stapler: false, friends: ['Joanna', 'Michael', 'Samir'] };
|
||||
var michael = { name: 'Michael', stapler: false, friends: ['Peter', 'Samir'] };
|
||||
var bob = { name: 'Bob', stapler: true, friends: [] };
|
||||
|
||||
/***
|
||||
* sha1 hex encoding (default)
|
||||
*/
|
||||
hash(peter);
|
||||
// 14fa461bf4b98155e82adc86532938553b4d33a9
|
||||
hash(michael);
|
||||
// 4b2b30e27699979ce46714253bc2213010db039c
|
||||
hash(bob);
|
||||
// 38d96106bc8ef3d8bd369b99bb6972702c9826d5
|
||||
|
||||
/***
|
||||
* hash object keys, values ignored
|
||||
*/
|
||||
hash(peter, { excludeValues: true });
|
||||
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
|
||||
hash(michael, { excludeValues: true });
|
||||
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
|
||||
hash.keys(bob);
|
||||
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
|
||||
|
||||
/***
|
||||
* hash object, ignore specific key(s)
|
||||
*/
|
||||
hash(peter, { excludeKeys: function(key) {
|
||||
if ( key === 'friends') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// 66b7d7e64871aa9fda1bdc8e88a28df797648d80
|
||||
|
||||
/***
|
||||
* md5 base64 encoding
|
||||
*/
|
||||
hash(peter, { algorithm: 'md5', encoding: 'base64' });
|
||||
// 6rkWaaDiG3NynWw4svGH7g==
|
||||
hash(michael, { algorithm: 'md5', encoding: 'base64' });
|
||||
// djXaWpuWVJeOF8Sb6SFFNg==
|
||||
hash(bob, { algorithm: 'md5', encoding: 'base64' });
|
||||
// lFzkw/IJ8/12jZI0rQeS3w==
|
||||
```
|
||||
|
||||
## Legacy Browser Support
|
||||
|
||||
IE <= 8 and Opera <= 11 support dropped in version 0.3.0. If you require
|
||||
legacy browser support you must either use an ES5 shim or use version 0.2.5
|
||||
of this module.
|
||||
|
||||
## Development
|
||||
|
||||
```sh-session
|
||||
git clone https://github.com/puleos/object-hash
|
||||
```
|
||||
|
||||
## Node Docker Wrapper
|
||||
|
||||
If you want to stand this up in a docker container, you should take at look
|
||||
at the [](https://github.com/bean5/node-object-hash) project.
|
||||
|
||||
### gulp tasks
|
||||
|
||||
* `gulp watch` (default) watch files, test and lint on change/add
|
||||
* `gulp test` unit tests
|
||||
* `gulp karma` browser unit tests
|
||||
* `gulp lint` jshint
|
||||
* `gulp dist` create browser version in /dist
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Changelog
|
||||
|
||||
### v2.0.0
|
||||
|
||||
Only Node.js versions `>= 6.0.0` are being tested in CI now.
|
||||
No other breaking changes were introduced.
|
|
@ -1,13 +1,19 @@
|
|||
{
|
||||
"name": "findAll-Grafana",
|
||||
"name": "grafana-find",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"getopts": "^2.3.0",
|
||||
"node-fetch": "^2.6.7"
|
||||
"node-fetch": "^2.6.7",
|
||||
"object-hash": "^3.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"gfind": "main.js",
|
||||
"grafana-find": "main.js"
|
||||
}
|
||||
},
|
||||
"node_modules/colors": {
|
||||
|
@ -42,6 +48,14 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/object-hash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/tr46": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
||||
|
@ -81,6 +95,11 @@
|
|||
"whatwg-url": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"object-hash": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
||||
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
|
||||
},
|
||||
"tr46": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"getopts": "^2.3.0",
|
||||
"node-fetch": "^2.6.7"
|
||||
"node-fetch": "^2.6.7",
|
||||
"object-hash": "^3.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"grafana-find": "main.js",
|
||||
|
|
Loading…
Reference in New Issue