Skip to content

Commit

Permalink
feat(@whook/http-transaction): add APM and obfuscator services
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Feb 2, 2020
1 parent 2b47262 commit 8fa973e
Show file tree
Hide file tree
Showing 19 changed files with 878 additions and 172 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/whook-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"homepage": "https://github.com/nfroidure/whook",
"dependencies": {
"@whook/whook": "^3.1.3",
"ajv": "^6.10.2",
"ajv": "^6.11.0",
"common-services": "^6.2.0",
"inquirer": "^7.0.0",
"knifecycle": "^8.1.0",
Expand Down

Large diffs are not rendered by default.

151 changes: 58 additions & 93 deletions packages/whook-example/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Object {
"protocol": "http",
"reqHeaders": Object {
"accept": "application/json, text/plain, */*",
"authorization": "Fake 1-admin",
"authorization": "Fa...n",
"connection": "close",
"host": "localhost:9999",
"user-agent": "__avoid_axios_version__",
Expand Down Expand Up @@ -48,37 +48,8 @@ Object {
"logErrorCalls": Array [],
"logInfoCalls": Array [
Array [
Object {
"endInBytes": 175,
"endOutBytes": 837,
"endTime": 1390694400000,
"errored": false,
"id": "1",
"ip": "127.0.0.1",
"method": "GET",
"operationId": "getDiagnostic",
"protocol": "http",
"reqHeaders": Object {
"accept": "application/json, text/plain, */*",
"authorization": "Fake 1-admin",
"connection": "close",
"host": "localhost:9999",
"user-agent": "__avoid_axios_version__",
},
"resHeaders": Object {
"Access-Control-Allow-Headers": "Accept,Accept-Encoding,Accept-Language,Referrer,Content-Type,Content-Encoding,Authorization,Keep-Alive,User-Agent",
"Access-Control-Allow-Methods": "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Origin": "*",
"Vary": "Origin",
"X-Authenticated": "{\\"hash\\":\\"1-admin\\",\\"userId\\":1,\\"scopes\\":[\\"admin\\"]}",
"content-type": "application/json",
},
"startInBytes": 175,
"startOutBytes": 0,
"startTime": 1390694400000,
"statusCode": 200,
"url": "/v4/diag",
},
"CALL",
"{\\"id\\":\\"1\\",\\"protocol\\":\\"http\\",\\"ip\\":\\"127.0.0.1\\",\\"startInBytes\\":175,\\"startOutBytes\\":0,\\"startTime\\":1390694400000,\\"url\\":\\"/v4/diag\\",\\"method\\":\\"GET\\",\\"reqHeaders\\":{\\"accept\\":\\"application/json, text/plain, */*\\",\\"authorization\\":\\"Fa...n\\",\\"user-agent\\":\\"__avoid_axios_version__\\",\\"host\\":\\"localhost:9999\\",\\"connection\\":\\"close\\"},\\"errored\\":false,\\"endTime\\":1390694400000,\\"endInBytes\\":175,\\"endOutBytes\\":831,\\"statusCode\\":200,\\"resHeaders\\":{\\"content-type\\":\\"application/json\\",\\"X-Authenticated\\":\\"{\\\\\\"hash\\\\\\":\\\\\\"1-admin\\\\\\",\\\\\\"userId\\\\\\":1,\\\\\\"scopes\\\\\\":[\\\\\\"admin\\\\\\"]}\\",\\"Access-Control-Allow-Origin\\":\\"*\\",\\"Access-Control-Allow-Methods\\":\\"GET,POST,PUT,DELETE,OPTIONS\\",\\"Access-Control-Allow-Headers\\":\\"Accept,Accept-Encoding,Accept-Language,Referrer,Content-Type,Content-Encoding,Authorization,Keep-Alive,User-Agent\\",\\"Vary\\":\\"Origin\\"},\\"operationId\\":\\"getDiagnostic\\"}",
],
],
"status": 200,
Expand Down Expand Up @@ -117,37 +88,8 @@ Object {
"logErrorCalls": Array [],
"logInfoCalls": Array [
Array [
Object {
"endInBytes": 175,
"endOutBytes": 510,
"endTime": 1390694400000,
"errored": true,
"id": "2",
"ip": "127.0.0.1",
"method": "GET",
"operationId": "getDiagnostic",
"protocol": "http",
"reqHeaders": Object {
"accept": "application/json, text/plain, */*",
"authorization": "Fake e-admin",
"connection": "close",
"host": "localhost:9999",
"user-agent": "__avoid_axios_version__",
},
"resHeaders": Object {
"Access-Control-Allow-Headers": "Accept,Accept-Encoding,Accept-Language,Referrer,Content-Type,Content-Encoding,Authorization,Keep-Alive,User-Agent",
"Access-Control-Allow-Methods": "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Origin": "*",
"Vary": "Origin",
"cache-control": "private",
"content-type": "application/json",
},
"startInBytes": 175,
"startOutBytes": 0,
"startTime": 1390694400000,
"statusCode": 400,
"url": "/v4/diag",
},
"CALL",
"{\\"id\\":\\"2\\",\\"protocol\\":\\"http\\",\\"ip\\":\\"127.0.0.1\\",\\"startInBytes\\":175,\\"startOutBytes\\":0,\\"startTime\\":1390694400000,\\"url\\":\\"/v4/diag\\",\\"method\\":\\"GET\\",\\"reqHeaders\\":{\\"accept\\":\\"application/json, text/plain, */*\\",\\"authorization\\":\\"Fa...n\\",\\"user-agent\\":\\"__avoid_axios_version__\\",\\"host\\":\\"localhost:9999\\",\\"connection\\":\\"close\\"},\\"errored\\":true,\\"endTime\\":1390694400000,\\"endInBytes\\":175,\\"endOutBytes\\":510,\\"statusCode\\":400,\\"resHeaders\\":{\\"content-type\\":\\"application/json\\",\\"Access-Control-Allow-Origin\\":\\"*\\",\\"Access-Control-Allow-Methods\\":\\"GET,POST,PUT,DELETE,OPTIONS\\",\\"Access-Control-Allow-Headers\\":\\"Accept,Accept-Encoding,Accept-Language,Referrer,Content-Type,Content-Encoding,Authorization,Keep-Alive,User-Agent\\",\\"Vary\\":\\"Origin\\",\\"cache-control\\":\\"private\\"},\\"operationId\\":\\"getDiagnostic\\"}",
],
],
"status": 400,
Expand Down Expand Up @@ -186,36 +128,8 @@ Object {
"logErrorCalls": Array [],
"logInfoCalls": Array [
Array [
Object {
"endInBytes": 146,
"endOutBytes": 447,
"endTime": 1390694400000,
"errored": false,
"id": "0",
"ip": "127.0.0.1",
"method": "GET",
"operationId": "getPing",
"protocol": "http",
"reqHeaders": Object {
"accept": "application/json, text/plain, */*",
"connection": "close",
"host": "localhost:9999",
"user-agent": "__avoid_axios_version__",
},
"resHeaders": Object {
"Access-Control-Allow-Headers": "Accept,Accept-Encoding,Accept-Language,Referrer,Content-Type,Content-Encoding,Authorization,Keep-Alive,User-Agent",
"Access-Control-Allow-Methods": "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Origin": "*",
"Vary": "Origin",
"X-Node-ENV": "test",
"content-type": "application/json",
},
"startInBytes": 146,
"startOutBytes": 0,
"startTime": 1390694400000,
"statusCode": 200,
"url": "/v4/ping",
},
"CALL",
"{\\"id\\":\\"0\\",\\"protocol\\":\\"http\\",\\"ip\\":\\"127.0.0.1\\",\\"startInBytes\\":146,\\"startOutBytes\\":0,\\"startTime\\":1390694400000,\\"url\\":\\"/v4/ping\\",\\"method\\":\\"GET\\",\\"reqHeaders\\":{\\"accept\\":\\"application/json, text/plain, */*\\",\\"user-agent\\":\\"__avoid_axios_version__\\",\\"host\\":\\"localhost:9999\\",\\"connection\\":\\"close\\"},\\"errored\\":false,\\"endTime\\":1390694400000,\\"endInBytes\\":146,\\"endOutBytes\\":447,\\"statusCode\\":200,\\"resHeaders\\":{\\"content-type\\":\\"application/json\\",\\"X-Node-ENV\\":\\"test\\",\\"Access-Control-Allow-Origin\\":\\"*\\",\\"Access-Control-Allow-Methods\\":\\"GET,POST,PUT,DELETE,OPTIONS\\",\\"Access-Control-Allow-Headers\\":\\"Accept,Accept-Encoding,Accept-Language,Referrer,Content-Type,Content-Encoding,Authorization,Keep-Alive,User-Agent\\",\\"Vary\\":\\"Origin\\"},\\"operationId\\":\\"getPing\\"}",
],
],
"status": 200,
Expand All @@ -234,6 +148,9 @@ Object {
Array [
"♻️ - Loading the environment service.",
],
Array [
"❤️ - Initializing the APM service.",
],
Array [
"➰ - Plugin \\"@whook/cli\\" resolved to: /home/whoiam/projects/whook/packages/whook-cli/dist",
],
Expand Down Expand Up @@ -355,6 +272,9 @@ Object {
Array [
"🔧 - Initializing auth mechanisms",
],
Array [
"🕶️ - Initializing the obfuscator service.",
],
Array [
"🚦 - HTTP Router initialized.",
],
Expand Down Expand Up @@ -439,6 +359,24 @@ Object {
Array [
"🚫 - Service \\"KEEP_ALIVE_TIMEOUT\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/KEEP_ALIVE_TIMEOUT",
],
Array [
"🚫 - Service \\"MAX_CLEAR_CHARS\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_CLEAR_CHARS",
],
Array [
"🚫 - Service \\"MAX_CLEAR_CHARS\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/services/MAX_CLEAR_CHARS",
],
Array [
"🚫 - Service \\"MAX_CLEAR_CHARS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/MAX_CLEAR_CHARS",
],
Array [
"🚫 - Service \\"MAX_CLEAR_RATIO\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_CLEAR_RATIO",
],
Array [
"🚫 - Service \\"MAX_CLEAR_RATIO\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/services/MAX_CLEAR_RATIO",
],
Array [
"🚫 - Service \\"MAX_CLEAR_RATIO\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/MAX_CLEAR_RATIO",
],
Array [
"🚫 - Service \\"MAX_CONNECTIONS\\" not found in: /home/whoiam/projects/whook/dist/services/MAX_CONNECTIONS",
],
Expand Down Expand Up @@ -493,6 +431,33 @@ Object {
Array [
"🚫 - Service \\"QUERY_PARSER\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/QUERY_PARSER",
],
Array [
"🚫 - Service \\"SENSIBLE_HEADERS\\" not found in: /home/whoiam/projects/whook/dist/services/SENSIBLE_HEADERS",
],
Array [
"🚫 - Service \\"SENSIBLE_HEADERS\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/services/SENSIBLE_HEADERS",
],
Array [
"🚫 - Service \\"SENSIBLE_HEADERS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SENSIBLE_HEADERS",
],
Array [
"🚫 - Service \\"SENSIBLE_PROPS\\" not found in: /home/whoiam/projects/whook/dist/services/SENSIBLE_PROPS",
],
Array [
"🚫 - Service \\"SENSIBLE_PROPS\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/services/SENSIBLE_PROPS",
],
Array [
"🚫 - Service \\"SENSIBLE_PROPS\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SENSIBLE_PROPS",
],
Array [
"🚫 - Service \\"SHIELD_CHAR\\" not found in: /home/whoiam/projects/whook/dist/services/SHIELD_CHAR",
],
Array [
"🚫 - Service \\"SHIELD_CHAR\\" not found in: /home/whoiam/projects/whook/packages/whook-cli/dist/services/SHIELD_CHAR",
],
Array [
"🚫 - Service \\"SHIELD_CHAR\\" not found in: /home/whoiam/projects/whook/packages/whook-example/src/services/SHIELD_CHAR",
],
Array [
"🚫 - Service \\"SIGNALS\\" not found in: /home/whoiam/projects/whook/dist/services/SIGNALS",
],
Expand Down
5 changes: 5 additions & 0 deletions packages/whook-example/src/config/development/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const CONFIG: AppConfigs = {
SERVICE_NAME_MAP: {
sendSMS: 'logSMS',
},
// Avoid obfuscating secrets in development
MAX_CLEAR_CHARS: Infinity,
MAX_CLEAR_RATIO: 0,
SENSIBLE_PROPS: [],
SENSIBLE_HEADERS: [],
};

export default CONFIG;
6 changes: 3 additions & 3 deletions packages/whook-example/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ describe('runServer', () => {
},
data,
debugCalls: debug.mock.calls.map(filterPaths).sort(sortLogs),
logInfoCalls: logger.info.mock.calls.map(filterPaths),
logErrorCalls: logger.error.mock.calls
logInfoCalls: logger.info.mock.calls
.map(filterPaths)
.filter(([arg1]) => arg1 !== 'An error occured'),
.filter(([arg1]) => arg1 !== 'ERROR'),
logErrorCalls: logger.error.mock.calls.map(filterPaths),
}).toMatchSnapshot();
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/whook-http-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@types/qs": "^6.9.0",
"@whook/http-transaction": "3.1.3",
"ajv": "^6.10.2",
"ajv": "^6.11.0",
"bytes": "^3.1.0",
"camel-case": "^3.0.0",
"content-type": "^1.0.4",
Expand Down
7 changes: 6 additions & 1 deletion packages/whook-http-router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function identity(x) {
return x;
}

export { initErrorHandler, WhookErrorHandler };
export {
initErrorHandler,
WhookErrorHandler,
flattenOpenAPI,
getOpenAPIOperations,
};

export type WhookHandlers = { [name: string]: WhookHandler };
export type WhookParser = (content: string) => string;
Expand Down
Loading

0 comments on commit 8fa973e

Please sign in to comment.