fix(core): update

This commit is contained in:
Philipp Kunz 2018-11-11 01:38:19 +01:00
parent 57893e6962
commit b95780976b
5 changed files with 126 additions and 30 deletions

76
package-lock.json generated
View File

@ -100,13 +100,29 @@
"vinyl-file": "^3.0.0"
}
},
"@pushrocks/smartlog": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-2.0.2.tgz",
"integrity": "sha512-mMJIu4S+6BxLJLB0+6i+M/UhLqi6mUu+x+h+mO0P24kEBCOUWLBz/bP2S8l9ShGV5BIeVSt6OtyvvJeqvyn/Xg==",
"dev": true,
"@pushrocks/smarthash": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@pushrocks/smarthash/-/smarthash-2.0.0.tgz",
"integrity": "sha512-+nxpmemy7Tn5tTRlJKR68HJzFDLVMJQSM/GRzb7wgYPVkjs+zeME4oTV6pn8x3//qFio8C3RdrvsQ1iz+xO/jw==",
"requires": {
"@pushrocks/smartlog-interfaces": "^1.0.9"
"@pushrocks/smartpromise": "^2.0.5",
"@types/through2": "^2.0.33",
"through2": "^2.0.3"
}
},
"@pushrocks/smartlog": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-2.0.8.tgz",
"integrity": "sha512-fZIzmKye+Lsu7rTH+ILZ1u/jJvrAni9c3udQIgrHXtxyNWd8bROO5GAYsSm8pGWbdawv2hpVoG9qa9yKBUQGJA==",
"requires": {
"@pushrocks/smartlog-interfaces": "^2.0.2"
},
"dependencies": {
"@pushrocks/smartlog-interfaces": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.3.tgz",
"integrity": "sha512-49nPRfXT1ZJNY5e23ujysHMDx0yaPMrLBpLtjkGxZRDLIfh1HuohMcGt5aeRhvxooLnM88AOM/2Lg4OltpFDPg=="
}
}
},
"@pushrocks/smartlog-interfaces": {
@ -123,8 +139,7 @@
"@pushrocks/smartpromise": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@pushrocks/smartpromise/-/smartpromise-2.0.5.tgz",
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==",
"dev": true
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
},
"@pushrocks/smartrequest": {
"version": "1.1.14",
@ -212,8 +227,15 @@
"@types/node": {
"version": "10.12.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.1.tgz",
"integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ==",
"dev": true
"integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ=="
},
"@types/through2": {
"version": "2.0.34",
"resolved": "https://registry.npmjs.org/@types/through2/-/through2-2.0.34.tgz",
"integrity": "sha512-nhRG8+RuG/L+0fAZBQYaRflXKjTrHOKH8MFTChnf+dNVMxA3wHYYrfj0tztK0W51ABXjGfRCDc0vRkecCOrsow==",
"requires": {
"@types/node": "*"
}
},
"@types/vinyl": {
"version": "2.0.2",
@ -469,8 +491,7 @@
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"dev": true
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"deep-eql": {
"version": "3.0.1",
@ -617,8 +638,7 @@
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"dev": true
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"is-utf8": {
"version": "0.2.1",
@ -629,8 +649,7 @@
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"dev": true
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"isexe": {
"version": "2.0.0",
@ -783,14 +802,12 @@
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==",
"dev": true
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
},
"readable-stream": {
"version": "2.3.6",
"resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"dev": true,
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
@ -825,8 +842,7 @@
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"semver": {
"version": "5.6.0",
@ -874,7 +890,6 @@
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"dev": true,
"requires": {
"safe-buffer": "~5.1.0"
}
@ -922,6 +937,15 @@
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
},
"through2": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz",
"integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==",
"requires": {
"readable-stream": "~2.3.6",
"xtend": "~4.0.1"
}
},
"ts-node": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz",
@ -1000,8 +1024,7 @@
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"dev": true
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"vinyl": {
"version": "2.2.0",
@ -1045,6 +1068,11 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
},
"yn": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz",

View File

@ -21,6 +21,8 @@
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smarthash": "^2.0.0",
"@pushrocks/smartlog": "^2.0.8",
"@pushrocks/smartlog-interfaces": "^1.0.15"
}
}

View File

@ -1,10 +1,40 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartlog from '@pushrocks/smartlog';
import * as smarthash from '@pushrocks/smarthash';
import * as smartlogReceiver from '../ts/index';
let testReceiver: smartlogReceiver.SmartlogReceiver;
let testSmartlog = smartlog.defaultLogger;
testSmartlog.enableConsole();
tap.test('first test', async () => {
testReceiver = new smartlogReceiver.SmartlogReceiver();
tap.test('should create a valid SmartlogReceiver', async () => {
testReceiver = new smartlogReceiver.SmartlogReceiver({
passphrase: 'hi',
smartlogInstance: testSmartlog,
validatorFunction: () => {
return true;
}
});
expect(testReceiver).to.be.instanceof(smartlogReceiver.SmartlogReceiver);
});
tap.test('should receive a message', async () => {
testReceiver.handleAuthenticatedLog({
auth: smarthash.sha256FromStringSync('hi'),
logPackage: {
logContext: {
company: 'Lossless GmbH',
companyunit: 'Lossless Cloud',
containerName: null,
environment: 'staging',
runtime: 'node',
zone: 'gitzone'
},
logLevel: 'info',
message: 'hi there'
}
});
})
tap.start();

View File

@ -1,13 +1,44 @@
import * as plugins from './sl.receiver.plugins';
import { ILogPackage, ILogPackageAuthenticated } from '@pushrocks/smartlog-interfaces';
import { ILogPackage, ILogPackageAuthenticated, ILogDestination } from '@pushrocks/smartlog-interfaces';
export type TValidatorFunction = () => boolean;
export interface ISmartlogReceiverOptions {
smartlogInstance: plugins.smartlog.Smartlog;
passphrase: string;
validatorFunction: TValidatorFunction;
}
/**
* a class that receives smartlog packages
*/
export class SmartlogReceiver {
passphrase: string;
validatorFunction: TValidatorFunction;
smartlogInstance: plugins.smartlog.Smartlog;
constructor(smartlogReceiverOptions: ISmartlogReceiverOptions) {
this.passphrase = smartlogReceiverOptions.passphrase;
this.validatorFunction = smartlogReceiverOptions.validatorFunction;
this.smartlogInstance = smartlogReceiverOptions.smartlogInstance;
}
/**
* handles a authenticated log
*/
private handleAuthenticatedLog(authenticatedLogArg) {}
handleAuthenticatedLog(authenticatedLogPackageArg: ILogPackageAuthenticated) {
const authString = authenticatedLogPackageArg.auth;
const logPackage = authenticatedLogPackageArg.logPackage;
if(authString === plugins.smarthash.sha256FromStringSync(this.passphrase)) {
this.smartlogInstance.log('ok', 'Message accepted');
this.smartlogInstance
} else {
this.smartlogInstance.log('error', 'Message rejected because of bad passphrase');
// console.log(plugins.smarthash.sha256FromStringSync(this.passphrase));
}
}
}

View File

@ -1,2 +1,7 @@
const removeme = {};
export { removeme };
import * as smarthash from '@pushrocks/smarthash';
import * as smartlog from '@pushrocks/smartlog';
export {
smartlog,
smarthash
};