Skip to content

Commit

Permalink
IPROD-93 added OUTBOUND_MUTUAL_TLS_USE_FILES env var
Browse files Browse the repository at this point in the history
  • Loading branch information
geka-evk committed Oct 21, 2023
1 parent 96ded70 commit 5a523e4
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 62 deletions.
6 changes: 3 additions & 3 deletions modules/api-svc/package.json
Expand Up @@ -100,13 +100,13 @@
"@redocly/openapi-cli": "^1.0.0-beta.94",
"@types/jest": "^29.5.6",
"babel-jest": "^29.7.0",
"eslint": "^8.51.0",
"eslint": "^8.52.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^27.4.2",
"eslint-plugin-jest": "^27.4.3",
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"nock": "^13.3.4",
"nock": "^13.3.6",
"npm-check-updates": "^16.7.10",
"openapi-response-validator": "^12.1.3",
"openapi-typescript": "^6.7.0",
Expand Down
6 changes: 4 additions & 2 deletions modules/api-svc/src/config.js
Expand Up @@ -56,6 +56,8 @@ const env = from(process.env, {
asResourceVersions: (resourceString) => parseResourceVersions(resourceString),
});

const OUTBOUND_MUTUAL_TLS_USE_FILES = env.get('OUTBOUND_MUTUAL_TLS_USE_FILES').default('false').asBool();

module.exports = {
__parseResourceVersion: parseResourceVersions,
control: {
Expand All @@ -82,11 +84,11 @@ module.exports = {
mutualTLS: {
enabled: env.get('OUTBOUND_MUTUAL_TLS_ENABLED').default('false').asBool(),
},
creds: {
creds: OUTBOUND_MUTUAL_TLS_USE_FILES ? {
ca: env.get('OUT_CA_CERT_PATH').asFileListContent(),
cert: env.get('OUT_CLIENT_CERT_PATH').asFileContent(),
key: env.get('OUT_CLIENT_KEY_PATH').asFileContent(),
},
} : {}, // will be populated from CONFIGURATION ws-message from pm-management-api
},
},
backendEventHandler: {
Expand Down
21 changes: 5 additions & 16 deletions modules/api-svc/src/index.js
Expand Up @@ -11,9 +11,10 @@
'use strict';

const { hostname } = require('os');
const EventEmitter = require('events');
const _ = require('lodash');
const { Logger } = require('@mojaloop/sdk-standard-components');
const config = require('./config');
const EventEmitter = require('events');

const InboundServer = require('./InboundServer');
const OutboundServer = require('./OutboundServer');
Expand All @@ -32,7 +33,7 @@ const Router = require('./lib/router');
const Validate = require('./lib/validate');
const Cache = require('./lib/cache');
const { SDKStateEnum } = require('./lib/model/common');
const { Logger, WSO2Auth } = require('@mojaloop/sdk-standard-components');
const { createAuthClient } = require('./lib/utils');

const LOG_ID = {
INBOUND: { app: 'mojaloop-connector-inbound-api' },
Expand Down Expand Up @@ -67,14 +68,7 @@ class Server extends EventEmitter {
logger: this.logger.push(LOG_ID.METRICS)
});

this.wso2 = {
auth: new WSO2Auth({
...conf.wso2.auth,
logger,
tlsCreds: conf.outbound.tls.mutualTLS.enabled && conf.outbound.tls.creds,
}),
retryWso2AuthFailureTimes: conf.wso2.requestAuthFailureRetryTimes,
};
this.wso2 = createAuthClient(conf, logger);
this.wso2.auth.on('error', (msg) => {
this.emit('error', 'WSO2 auth error in InboundApi', msg);
});
Expand Down Expand Up @@ -198,12 +192,7 @@ class Server extends EventEmitter {
|| !_.isEqual(this.conf.outbound.tls, newConf.outbound.tls);
if (updateWSO2) {
this.wso2.auth.stop();
this.wso2.auth = new WSO2Auth({
...newConf.wso2.auth,
logger: this.logger,
tlsCreds: newConf.outbound.tls.mutualTLS.enabled && newConf.outbound.tls.creds,
});
this.wso2.retryWso2AuthFailureTimes = newConf.wso2.requestAuthFailureRetryTimes;
this.wso2 = createAuthClient(newConf, this.logger);
this.wso2.auth.on('error', (msg) => {
this.emit('error', 'WSO2 auth error in InboundApi', msg);
});
Expand Down
20 changes: 20 additions & 0 deletions modules/api-svc/src/lib/utils.js
@@ -0,0 +1,20 @@
const { WSO2Auth } = require('@mojaloop/sdk-standard-components');

const createAuthClient = (conf, logger) => {
const { wso2, outbound } = conf;

const auth = new WSO2Auth({
...wso2.auth,
logger,
tlsCreds: outbound.tls.mutualTLS.enabled && outbound.tls.creds,
});

return Object.freeze({
auth,
retryWso2AuthFailureTimes: wso2.requestAuthFailureRetryTimes,
});
};

module.exports = {
createAuthClient,
};
16 changes: 15 additions & 1 deletion modules/api-svc/test/unit/config.test.js
Expand Up @@ -95,7 +95,6 @@ describe('config', () => {
});

it('should transform correctly resources versions to config', () => {

const resourceVersions = {
resourceOneName: {
acceptVersion: '1',
Expand All @@ -116,4 +115,19 @@ describe('config', () => {
expect(() => parseResourceVersion('resourceOneName=1.0;resourceTwoName=1.1')).toThrowError(new Error('Resource versions format should be in format: "resourceOneName=1.0,resourceTwoName=1.1"'));
});

it('should return outbound.tls.creds with keys if OUTBOUND_MUTUAL_TLS_USE_FILES is true', () => {
process.env.OUTBOUND_MUTUAL_TLS_USE_FILES = 'true';
const config = require('~/config');
expect(config.outbound.tls.creds).toStrictEqual({
ca: undefined,
cert: undefined,
key: undefined,
});
});

it('should return outbound.tls.creds as empty object if OUTBOUND_MUTUAL_TLS_USE_FILES is false', () => {
process.env.OUTBOUND_MUTUAL_TLS_USE_FILES = 'false';
const config = require('~/config');
expect(config.outbound.tls.creds).toStrictEqual({});
});
});
2 changes: 1 addition & 1 deletion modules/outbound-command-event-handler/package.json
Expand Up @@ -66,7 +66,7 @@
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"copyfiles": "^2.4.1",
"eslint": "^8.51.0",
"eslint": "^8.52.0",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"npm-check-updates": "^16.7.10",
Expand Down
2 changes: 1 addition & 1 deletion modules/outbound-domain-event-handler/package.json
Expand Up @@ -64,7 +64,7 @@
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"copyfiles": "^2.4.1",
"eslint": "^8.51.0",
"eslint": "^8.52.0",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"npm-check-updates": "^16.7.10",
Expand Down
2 changes: 1 addition & 1 deletion modules/private-shared-lib/package.json
Expand Up @@ -38,7 +38,7 @@
},
"devDependencies": {
"@types/node": "^20.8.7",
"eslint": "^8.51.0",
"eslint": "^8.52.0",
"jest": "^29.7.0",
"npm-check-updates": "^16.7.10",
"replace": "^1.2.2",
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter",
"version": "23.1.1",
"version": "23.1.2",
"description": "mojaloop sdk-scheme-adapter",
"license": "Apache-2.0",
"homepage": "https://github.com/mojaloop/sdk-scheme-adapter",
Expand Down Expand Up @@ -77,7 +77,7 @@
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"audit-ci": "^6.6.1",
"eslint": "^8.51.0",
"eslint": "^8.52.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-plugin-import": "latest",
"husky": "^8.0.3",
Expand Down
77 changes: 42 additions & 35 deletions yarn.lock
Expand Up @@ -2033,10 +2033,10 @@ __metadata:
languageName: node
linkType: hard

"@eslint/js@npm:8.51.0":
version: 8.51.0
resolution: "@eslint/js@npm:8.51.0"
checksum: 0228bf1e1e0414843e56d9ff362a2a72d579c078f93174666f29315690e9e30a8633ad72c923297f7fd7182381b5a476805ff04dac8debe638953eb1ded3ac73
"@eslint/js@npm:8.52.0":
version: 8.52.0
resolution: "@eslint/js@npm:8.52.0"
checksum: 490893b8091a66415f4ac98b963d23eb287264ea3bd6af7ec788f0570705cf64fd6ab84b717785980f55e39d08ff5c7fde6d8e4391ccb507169370ce3a6d091a
languageName: node
linkType: hard

Expand Down Expand Up @@ -2216,14 +2216,14 @@ __metadata:
languageName: node
linkType: hard

"@humanwhocodes/config-array@npm:^0.11.11":
version: 0.11.11
resolution: "@humanwhocodes/config-array@npm:0.11.11"
"@humanwhocodes/config-array@npm:^0.11.13":
version: 0.11.13
resolution: "@humanwhocodes/config-array@npm:0.11.13"
dependencies:
"@humanwhocodes/object-schema": ^1.2.1
"@humanwhocodes/object-schema": ^2.0.1
debug: ^4.1.1
minimatch: ^3.0.5
checksum: db84507375ab77b8ffdd24f498a5b49ad6b64391d30dd2ac56885501d03964d29637e05b1ed5aefa09d57ac667e28028bc22d2da872bfcd619652fbdb5f4ca19
checksum: f8ea57b0d7ed7f2d64cd3944654976829d9da91c04d9c860e18804729a33f7681f78166ef4c761850b8c324d362f7d53f14c5c44907a6b38b32c703ff85e4805
languageName: node
linkType: hard

Expand All @@ -2234,10 +2234,10 @@ __metadata:
languageName: node
linkType: hard

"@humanwhocodes/object-schema@npm:^1.2.1":
version: 1.2.1
resolution: "@humanwhocodes/object-schema@npm:1.2.1"
checksum: a824a1ec31591231e4bad5787641f59e9633827d0a2eaae131a288d33c9ef0290bd16fda8da6f7c0fcb014147865d12118df10db57f27f41e20da92369fcb3f1
"@humanwhocodes/object-schema@npm:^2.0.1":
version: 2.0.1
resolution: "@humanwhocodes/object-schema@npm:2.0.1"
checksum: 24929487b1ed48795d2f08346a0116cc5ee4634848bce64161fb947109352c562310fd159fc64dda0e8b853307f5794605191a9547f7341158559ca3c8262a45
languageName: node
linkType: hard

Expand Down Expand Up @@ -2833,10 +2833,10 @@ __metadata:
co-body: ^6.1.0
dotenv: ^16.3.1
env-var: ^7.4.1
eslint: ^8.51.0
eslint: ^8.52.0
eslint-config-airbnb-base: ^15.0.0
eslint-plugin-import: ^2.28.1
eslint-plugin-jest: ^27.4.2
eslint-plugin-jest: ^27.4.3
express: ^4.18.2
fast-json-patch: ^3.1.1
javascript-state-machine: ^3.1.0
Expand All @@ -2848,7 +2848,7 @@ __metadata:
koa-body: ^6.0.1
lodash: ^4.17.21
module-alias: ^2.2.3
nock: ^13.3.4
nock: ^13.3.6
npm-check-updates: ^16.7.10
oauth2-server: ^4.0.0-dev.2
openapi-jsonschema-parameters: ^12.1.3
Expand Down Expand Up @@ -2890,7 +2890,7 @@ __metadata:
ajv: ^8.12.0
convict: ^6.2.4
copyfiles: ^2.4.1
eslint: ^8.51.0
eslint: ^8.52.0
express: ^4.18.2
jest: ^29.7.0
nodemon: ^3.0.1
Expand Down Expand Up @@ -2927,7 +2927,7 @@ __metadata:
"@typescript-eslint/parser": ^6.8.0
convict: ^6.2.4
copyfiles: ^2.4.1
eslint: ^8.51.0
eslint: ^8.52.0
express: ^4.18.2
jest: ^29.7.0
nodemon: ^3.0.1
Expand Down Expand Up @@ -2955,7 +2955,7 @@ __metadata:
"@mojaloop/platform-shared-lib-nodejs-kafka-client-lib": 0.2.15
"@types/node": ^20.8.7
ajv: ^8.12.0
eslint: ^8.51.0
eslint: ^8.52.0
jest: ^29.7.0
npm-check-updates: ^16.7.10
redis: ^4.6.10
Expand All @@ -2977,7 +2977,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^6.8.0
"@typescript-eslint/parser": ^6.8.0
audit-ci: ^6.6.1
eslint: ^8.51.0
eslint: ^8.52.0
eslint-config-airbnb-typescript: ^17.1.0
eslint-plugin-import: latest
husky: ^8.0.3
Expand Down Expand Up @@ -4216,6 +4216,13 @@ __metadata:
languageName: node
linkType: hard

"@ungap/structured-clone@npm:^1.2.0":
version: 1.2.0
resolution: "@ungap/structured-clone@npm:1.2.0"
checksum: 4f656b7b4672f2ce6e272f2427d8b0824ed11546a601d8d5412b9d7704e83db38a8d9f402ecdf2b9063fc164af842ad0ec4a55819f621ed7e7ea4d1efcc74524
languageName: node
linkType: hard

"@yarnpkg/lockfile@npm:^1.1.0":
version: 1.1.0
resolution: "@yarnpkg/lockfile@npm:1.1.0"
Expand Down Expand Up @@ -7224,9 +7231,9 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-jest@npm:^27.4.2":
version: 27.4.2
resolution: "eslint-plugin-jest@npm:27.4.2"
"eslint-plugin-jest@npm:^27.4.3":
version: 27.4.3
resolution: "eslint-plugin-jest@npm:27.4.3"
dependencies:
"@typescript-eslint/utils": ^5.10.0
peerDependencies:
Expand All @@ -7238,7 +7245,7 @@ __metadata:
optional: true
jest:
optional: true
checksum: 99a8301ae00c37da97866b8b13c89a077716d2c653b26bc417d242e7300a43237c0017fd488c43966fa38585f19050facdbbc71d03ca36a1ce6f2ba930a9143e
checksum: de062a04f30d72535aecfd6594aa302cf350d62e86805c8f0edbb3dce4cde5b557766e7acfd0f87709a9b70854cc2522c04b875337925c64d0d9bc1118ef4693
languageName: node
linkType: hard

Expand Down Expand Up @@ -7301,17 +7308,18 @@ __metadata:
languageName: node
linkType: hard

"eslint@npm:^8.51.0":
version: 8.51.0
resolution: "eslint@npm:8.51.0"
"eslint@npm:^8.52.0":
version: 8.52.0
resolution: "eslint@npm:8.52.0"
dependencies:
"@eslint-community/eslint-utils": ^4.2.0
"@eslint-community/regexpp": ^4.6.1
"@eslint/eslintrc": ^2.1.2
"@eslint/js": 8.51.0
"@humanwhocodes/config-array": ^0.11.11
"@eslint/js": 8.52.0
"@humanwhocodes/config-array": ^0.11.13
"@humanwhocodes/module-importer": ^1.0.1
"@nodelib/fs.walk": ^1.2.8
"@ungap/structured-clone": ^1.2.0
ajv: ^6.12.4
chalk: ^4.0.0
cross-spawn: ^7.0.2
Expand Down Expand Up @@ -7344,7 +7352,7 @@ __metadata:
text-table: ^0.2.0
bin:
eslint: bin/eslint.js
checksum: 214fa5d1fcb67af1b8992ce9584ccd85e1aa7a482f8b8ea5b96edc28fa838a18a3b69456db45fc1ed3ef95f1e9efa9714f737292dc681e572d471d02fda9649c
checksum: fd22d1e9bd7090e31b00cbc7a3b98f3b76020a4c4641f987ae7d0c8f52e1b88c3b268bdfdabac2e1a93513e5d11339b718ff45cbff48a44c35d7e52feba510ed
languageName: node
linkType: hard

Expand Down Expand Up @@ -11359,15 +11367,14 @@ __metadata:
languageName: node
linkType: hard

"nock@npm:^13.3.4":
version: 13.3.4
resolution: "nock@npm:13.3.4"
"nock@npm:^13.3.6":
version: 13.3.6
resolution: "nock@npm:13.3.6"
dependencies:
debug: ^4.1.0
json-stringify-safe: ^5.0.1
lodash: ^4.17.21
propagate: ^2.0.0
checksum: 34ba5fdc025db1f6eb3ea5e3067489e37d6982534ad23d2c1e9fe33ab844c73ed9161012ce4c116c7aa9b765e5a9cfb1541163c936e06fb3331d51c61e2869f7
checksum: 795f334a17ed294b829968c177190571720492cc5113e2aa5b9d382c6508d81c8f79f6afae32009abce94213b0b7c1a474d582acf87e2c169d620314ac0ae60c
languageName: node
linkType: hard

Expand Down

0 comments on commit 5a523e4

Please sign in to comment.