From c519090b346918ba6cb4ddd1d3f86624133e06b1 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 11 Nov 2018 19:40:59 +0100 Subject: [PATCH] fix(core): update --- .snyk | 4 ++ package-lock.json | 61 ++++++++++++++++----- package.json | 2 + qenv.yml | 3 + test/test.ts | 30 +++++++++- ts/index.ts | 11 ++-- ts/smartlog-destination-receiver.plugins.ts | 3 +- 7 files changed, 93 insertions(+), 21 deletions(-) create mode 100644 .snyk create mode 100644 qenv.yml diff --git a/.snyk b/.snyk new file mode 100644 index 0000000..88ba614 --- /dev/null +++ b/.snyk @@ -0,0 +1,4 @@ +# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. +version: v1.13.1 +ignore: {} +patch: {} diff --git a/package-lock.json b/package-lock.json index 9764c11..5354e9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -74,6 +74,15 @@ "@pushrocks/smartpromise": "^2.0.5" } }, + "@pushrocks/qenv": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@pushrocks/qenv/-/qenv-2.0.2.tgz", + "integrity": "sha512-DKYbGy2m0fDRCVp9vwtgx1vZfYfK0k36POplCGo0jJat/DmB51KOjZ3gkqRqNJnoRQrn/kFH8+Xrm7D6gOotoA==", + "dev": true, + "requires": { + "@pushrocks/smartfile": "^6.0.6" + } + }, "@pushrocks/smartdelay": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.2.tgz", @@ -100,6 +109,16 @@ "vinyl-file": "^3.0.0" } }, + "@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/smartpromise": "^2.0.5", + "@types/through2": "^2.0.33", + "through2": "^2.0.3" + } + }, "@pushrocks/smartlog": { "version": "2.0.9", "resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-2.0.9.tgz", @@ -211,6 +230,14 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.5.tgz", "integrity": "sha512-GzdHjq3t3eGLMv92Al90Iq+EoLL+86mPfQhuglbBFO7HiLdC/rkt+zrzJJumAiBF6nsrBWhou22rPW663AAyFw==" }, + "@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", "resolved": "https://registry.npmjs.org/@types/vinyl/-/vinyl-2.0.2.tgz", @@ -463,8 +490,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", @@ -609,8 +635,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", @@ -621,8 +646,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", @@ -773,14 +797,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", @@ -815,8 +837,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", @@ -864,7 +885,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" } @@ -912,6 +932,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", @@ -990,8 +1019,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", @@ -1035,6 +1063,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", diff --git a/package.json b/package.json index a45870a..c6b7e63 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,14 @@ "devDependencies": { "@gitzone/tsbuild": "^2.0.22", "@gitzone/tstest": "^1.0.15", + "@pushrocks/qenv": "^2.0.2", "@pushrocks/tapbundle": "^3.0.7", "@types/node": "^10.11.7", "tslint": "^5.11.0", "tslint-config-prettier": "^1.15.0" }, "dependencies": { + "@pushrocks/smarthash": "^2.0.0", "@pushrocks/smartlog-interfaces": "^2.0.3", "@pushrocks/smartrequest": "^1.1.14" } diff --git a/qenv.yml b/qenv.yml new file mode 100644 index 0000000..a69f7cc --- /dev/null +++ b/qenv.yml @@ -0,0 +1,3 @@ +vars: + - RECEIVER_ENDPOINT + - PASSPHRASE \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index ebdfba4..0a4a295 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,34 @@ import { expect, tap } from '@pushrocks/tapbundle'; +import { Qenv } from '@pushrocks/qenv'; +import * as smartlog from '@pushrocks/smartlog'; +const testQenv = new Qenv('./', './.nogit/'); + import * as smartlogDestinationReceiver from '../ts/index'; -tap.test('first test', async () => { - console.log(smartlogDestinationReceiver.standardExport); +let testSmartlogReceiver: smartlogDestinationReceiver.SmartlogDestinationReceiver; + +tap.test('should create a valid SmartlogDestinationReceiver', async () => { + testSmartlogReceiver = new smartlogDestinationReceiver.SmartlogDestinationReceiver({ + receiverEndpoint: process.env.RECEIVER_ENDPOINT, + passphrase: process.env.PASSPHRASE + }); +}); + +tap.test('should send a valid message', async () => { + testSmartlogReceiver.handleLog({ + timestamp: Date.now(), + context: { + company: 'Lossless GmbH', + companyunit: 'Lossless Cloud', + containerName: null, + environment: 'local', + runtime: 'node', + zone: 'gitzone' + }, + type: 'log', + level: 'info', + message: 'This is a message', + }); }); tap.start(); diff --git a/ts/index.ts b/ts/index.ts index d59beaa..1b96cfc 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -17,10 +17,13 @@ export class SmartlogDestinationReceiver implements ILogDestination { this.options = optionsArg; } - handleLog(logPackageArg: ILogPackage) { - plugins.smartrequest.postJson(this.options.receiverEndpoint, { - auth: this.options.passphrase, - logPackage: logPackageArg + public async handleLog(logPackageArg: ILogPackage) { + const response = await plugins.smartrequest.postJson(this.options.receiverEndpoint, { + requestBody: { + auth: plugins.smarthash.sha256FromStringSync(this.options.passphrase), + logPackage: logPackageArg + } }); + console.log(response.body); } } diff --git a/ts/smartlog-destination-receiver.plugins.ts b/ts/smartlog-destination-receiver.plugins.ts index 4251df1..cc98007 100644 --- a/ts/smartlog-destination-receiver.plugins.ts +++ b/ts/smartlog-destination-receiver.plugins.ts @@ -1,4 +1,5 @@ +import * as smarthash from '@pushrocks/smarthash'; import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces'; import * as smartrequest from '@pushrocks/smartrequest'; -export { smartlogInterfaces, smartrequest }; +export { smarthash, smartlogInterfaces, smartrequest };