Commit f32ab0025ad2f41e873fab411484d862e0d9b507
1 parent
cd36a23de1
Exists in
master
config.do_not_forward_rc68_to_centers
Showing 2 changed files with 16 additions and 0 deletions Inline Diff
config.sample.json
1 | { | 1 | { |
2 | "listener": { | 2 | "listener": { |
3 | "http": { | 3 | "http": { |
4 | "port": 32979 | 4 | "port": 32979 |
5 | } | 5 | } |
6 | }, | 6 | }, |
7 | "ip_whitelist": [ | 7 | "ip_whitelist": [ |
8 | "127.0.0.1", | 8 | "127.0.0.1", |
9 | "::ffff:127.0.0.1", | 9 | "::ffff:127.0.0.1", |
10 | "::1" | 10 | "::1" |
11 | ], | 11 | ], |
12 | "ascending_deposit": false, | 12 | "ascending_deposit": false, |
13 | "ascending_mutation": false, | 13 | "ascending_mutation": false, |
14 | "blacklist_help_for_origins": [], | 14 | "blacklist_help_for_origins": [], |
15 | "blacklist_help_for_origin_transports": [], | 15 | "blacklist_help_for_origin_transports": [], |
16 | "do_not_forward_rc68_to_centers": [], | ||
16 | "disable_claim_bonus": false | 17 | "disable_claim_bonus": false |
17 | } | 18 | } |
lib/coreapi/request.js
1 | // const PRODUCTION = process.env.NODE_ENV === 'production'; | 1 | // const PRODUCTION = process.env.NODE_ENV === 'production'; |
2 | 2 | ||
3 | const request = require('request'); | 3 | const request = require('request'); |
4 | const uniqid = require('uniqid'); | 4 | const uniqid = require('uniqid'); |
5 | 5 | ||
6 | const coreUrl = require('komodo-sdk/core-url'); | 6 | const coreUrl = require('komodo-sdk/core-url'); |
7 | const config = require('komodo-sdk/config'); | ||
7 | const logger = require('komodo-sdk/logger'); | 8 | const logger = require('komodo-sdk/logger'); |
8 | const commandError = require('../command-handler/error'); | 9 | const commandError = require('../command-handler/error'); |
9 | 10 | ||
10 | function execute(coreEndpoint, params, httpMethod, cb) { | 11 | function execute(coreEndpoint, params, httpMethod, cb) { |
11 | const xid = uniqid(); | 12 | const xid = uniqid(); |
12 | 13 | ||
13 | const requestOptions = { | 14 | const requestOptions = { |
14 | url: coreUrl + coreEndpoint, | 15 | url: coreUrl + coreEndpoint, |
15 | method: httpMethod || 'GET' | 16 | method: httpMethod || 'GET' |
16 | } | 17 | } |
17 | 18 | ||
18 | if (requestOptions.method === 'GET' && params) { | 19 | if (requestOptions.method === 'GET' && params) { |
19 | requestOptions.qs = params; | 20 | requestOptions.qs = params; |
20 | } | 21 | } |
21 | else if (requestOptions.method === 'POST' && params) { | 22 | else if (requestOptions.method === 'POST' && params) { |
22 | requestOptions.data = params; | 23 | requestOptions.data = params; |
23 | } | 24 | } |
24 | 25 | ||
25 | logger.verbose('COREAPI-REQUEST: Requesting to core', { | 26 | logger.verbose('COREAPI-REQUEST: Requesting to core', { |
26 | xid, url: requestOptions.url, http_method: httpMethod, params: params, | 27 | xid, url: requestOptions.url, http_method: httpMethod, params: params, |
27 | }); | 28 | }); |
28 | 29 | ||
29 | request(requestOptions, function(err, res, body) { | 30 | request(requestOptions, function(err, res, body) { |
30 | const responseParams = { | 31 | const responseParams = { |
31 | directResponse: true, | 32 | directResponse: true, |
32 | httpStatusCode: res ? res.statusCode : null, | 33 | httpStatusCode: res ? res.statusCode : null, |
33 | body: body | 34 | body: body |
34 | } | 35 | } |
35 | 36 | ||
36 | if (err) { | 37 | if (err) { |
37 | logger.warn('ERROR on requesting to CORE', { | 38 | logger.warn('ERROR on requesting to CORE', { |
38 | xid, eCode: err.code, eMessage: err.message, | 39 | xid, eCode: err.code, eMessage: err.message, |
39 | }); | 40 | }); |
40 | cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams); | 41 | cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams); |
41 | return; | 42 | return; |
42 | } | 43 | } |
43 | 44 | ||
44 | if (res.statusCode !== 200) { | 45 | if (res.statusCode !== 200) { |
45 | logger.warn('Invalid HTTP status from CORE', { | 46 | logger.warn('Invalid HTTP status from CORE', { |
46 | xid, httpStatus: res.statusCode, | 47 | xid, httpStatus: res.statusCode, |
47 | }); | 48 | }); |
48 | 49 | ||
49 | cb(commandError.ERR_INVALID_CORE_HTTP_STATUS_RESPONSE, null, responseParams); | 50 | cb(commandError.ERR_INVALID_CORE_HTTP_STATUS_RESPONSE, null, responseParams); |
50 | return; | 51 | return; |
51 | } | 52 | } |
52 | 53 | ||
53 | try { | 54 | try { |
54 | var coreResponseObject = JSON.parse(body); | 55 | var coreResponseObject = JSON.parse(body); |
55 | } | 56 | } |
56 | catch(e) { | 57 | catch(e) { |
57 | logger.warn(commandError.ERR_INVALID_CORE_RESPONSE, { | 58 | logger.warn(commandError.ERR_INVALID_CORE_RESPONSE, { |
58 | xid, eCode: e.code, eMessage: e.message, body: body | 59 | xid, eCode: e.code, eMessage: e.message, body: body |
59 | }); | 60 | }); |
60 | cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams); | 61 | cb(commandError.ERR_INVALID_CORE_RESPONSE, null, responseParams); |
61 | return; | 62 | return; |
62 | } | 63 | } |
63 | 64 | ||
64 | logger.verbose('Got CORE response', { | 65 | logger.verbose('Got CORE response', { |
65 | xid, coreResponseObject, | 66 | xid, coreResponseObject, |
66 | }); | 67 | }); |
67 | 68 | ||
69 | // jangan kirim reply rc 68 jika origin/center ada di do_not_forward_rc68_to_centers | ||
70 | if ( | ||
71 | coreResponseObject && coreResponseObject.rc === '68' | ||
72 | && config && config.do_not_forward_rc68_to_centers | ||
73 | && params && params.origin && params.origin.trim() | ||
74 | && typeof params.origin === 'string' | ||
75 | && Array.isArray(config.do_not_forward_rc68_to_centers) | ||
76 | && config.do_not_forward_rc68_to_centers | ||
77 | .map((item) => item && (typeof item === 'string') && item.trim().toUpperCase()) | ||
78 | .indexOf(params.origin.trim().toUpperCase()) >= 0 | ||
79 | ) { | ||
80 | return; | ||
81 | } | ||
82 | |||
68 | cb(err, coreResponseObject, responseParams); | 83 | cb(err, coreResponseObject, responseParams); |
69 | }) | 84 | }) |
70 | 85 | ||
71 | } | 86 | } |
72 | 87 | ||
73 | module.exports = execute; | 88 | module.exports = execute; |