Compare View

switch
from
...
to
 
Commits (2)

Changes

Showing 3 changed files Side-by-side Diff

lib/callback/apikey-checker.js
... ... @@ -3,6 +3,8 @@ const MODULE_NAME = 'CALLBACK.APIKEY-CHECKER';
3 3 const config = require('komodo-sdk/config');
4 4 const logger = require('tektrans-logger');
5 5  
  6 +const { DEBUG_CALLBACK_APIKEY } = process.env;
  7 +
6 8 const sendInvalidApikeyResponse = (xid, res) => {
7 9 res.status(403).json({
8 10 status: 'NOT-OK',
... ... @@ -17,19 +19,38 @@ if (!config.partner.callback.apikey) {
17 19 }
18 20  
19 21 module.exports = (req, res, next) => {
  22 + const { xid } = res.locals;
  23 + const apikeyFromRequest = req.params.apikey;
  24 +
20 25 if (!config.partner || !config.partner.callback || !config.partner.callback.apikey) {
  26 + if (DEBUG_CALLBACK_APIKEY) {
  27 + logger.verbose(`${MODULE_NAME} 8BE57EB4: Skip APIKEY checker on no config`, {
  28 + xid,
  29 + });
  30 + }
21 31 next();
22 32 return;
23 33 }
24 34  
25   - const { xid } = res.locals;
26   - const apikeyFromRequest = req.params.apikey;
  35 + if (DEBUG_CALLBACK_APIKEY) {
  36 + logger.verbose(`${MODULE_NAME} 1A634029: Checking for apikey validity`, {
  37 + xid,
  38 + apikeyFromRequest,
  39 + });
  40 + }
27 41  
28 42 if (
29 43 typeof config.partner.callback.apikey === 'object'
30 44 && Array.isArray(config.partner.callback.apikey)
31 45 && config.partner.callback.apikey.indexOf(apikeyFromRequest) >= 0
32 46 ) {
  47 + if (DEBUG_CALLBACK_APIKEY) {
  48 + logger.verbose(`${MODULE_NAME} 4BC7B45D: Apikey match with one of array element`, {
  49 + xid,
  50 + apikeyFromRequest,
  51 + });
  52 + }
  53 +
33 54 next();
34 55 return;
35 56 }
... ... @@ -38,6 +59,12 @@ module.exports = (req, res, next) => {
38 59 typeof config.partner.callback.apikey === 'string'
39 60 && config.partner.callback.apikey === apikeyFromRequest
40 61 ) {
  62 + if (DEBUG_CALLBACK_APIKEY) {
  63 + logger.verbose(`${MODULE_NAME} FC80DC85: Apikey match with string config`, {
  64 + xid,
  65 + apikeyFromRequest,
  66 + });
  67 + }
41 68 next();
42 69 return;
43 70 }
1 1 {
2 2 "name": "komodo-gw-komodo-httpgetx",
3   - "version": "0.3.1",
  3 + "version": "0.3.2",
4 4 "lockfileVersion": 2,
5 5 "requires": true,
6 6 "packages": {
7 7 "": {
8 8 "name": "komodo-gw-komodo-httpgetx",
9   - "version": "0.3.1",
  9 + "version": "0.3.2",
10 10 "license": "ISC",
11 11 "dependencies": {
12 12 "axios": "^1.1.3",
1 1 {
2 2 "name": "komodo-gw-komodo-httpgetx",
3   - "version": "0.3.1",
  3 + "version": "0.3.2",
4 4 "description": "Komodo gateway to KOMODO HTTPGETX",
5 5 "main": "index.js",
6 6 "scripts": {