Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support more than one currency for FXP participants #88

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connection-manager-api",
"version": "2.3.1",
"version": "2.4.0",
"description": "ModusBox Connection Manager API",
"license": "Apache-2.0",
"author": "ModusBox",
Expand Down Expand Up @@ -71,7 +71,7 @@
"passport-jwt": "^4.0.1",
"request": "^2.88.2",
"request-promise-native": "^1.0.9",
"soap": "^1.1.1",
"soap": "^1.1.2",
"winston": "^3.14.2",
"xml2js": "^0.6.2"
},
Expand All @@ -85,7 +85,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.4.0",
"husky": "^9.1.4",
"husky": "^9.1.5",
"jshint": "^2.13.6",
"mocha": "^10.7.3",
"npm-audit-resolver": "3.0.0-RC.0",
Expand Down
5 changes: 5 additions & 0 deletions src/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,11 @@ components:
monetaryZoneId:
type: string
description: The monetary Zone
fxpCurrencies:
type: array
description: List of FX currencies
items:
type: string
kalinkrustev marked this conversation as resolved.
Show resolved Hide resolved
isProxy:
type: boolean
description: Proxy flag
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
exports.up = function (knex, Promise) {
return knex.schema.createTable('fxp_supported_currencies', (table) => {
table.increments('id').primary();
table.integer('dfspId').unsigned().notNullable();
table.string('monetaryZoneId', 3);
table.foreign('monetaryZoneId').references('monetaryZoneId').inTable('monetaryZone');
table.foreign('dfspId', 'FK_CURR_DFSP_ID').references('dfsps.id').onDelete('CASCADE').onUpdate('NO ACTION');
table.index('dfspId', 'FK_CURR_DFSP_ID_idx');
table.unique(['dfspId', 'monetaryZoneId']);
if (!process.env.TEST) table.engine('InnoDB');
if (!process.env.TEST) table.charset('utf8mb4');
});
};

kalinkrustev marked this conversation as resolved.
Show resolved Hide resolved
exports.down = function (knex, Promise) {
return knex.schema.dropTableIfExists('fxp_supported_currencies');
};
18 changes: 17 additions & 1 deletion src/db/seeds/03_dfsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,28 @@ exports.seed = async (knex) => {
dfsps.map(([dfsp_id, monetaryZoneId, isProxy]) => ({
dfsp_id,
name: dfsp_id,
monetaryZoneId: monetaryZoneId || null,
monetaryZoneId: monetaryZoneId?.length === 3 ? monetaryZoneId : null,
security_group: `Application/DFSP:${dfsp_id}`,
isProxy: isProxy === 'proxy'
}))
).onConflict('dfsp_id').merge();

for (const [dfsp_id, monetaryZones] of dfsps) {
const supportedCurrencies = monetaryZones.split('/').map(s => s.trim()).filter(s => s.length === 3);
const dfspId = (await knex('dfsps').where({dfsp_id}).first('id')).id;
if (supportedCurrencies.length > 1) {
for (const monetaryZoneId of supportedCurrencies) {
await knex('fxp_supported_currencies').insert({
dfspId,
monetaryZoneId
}).onConflict(['dfspId', 'monetaryZoneId']).ignore();
}
await knex('fxp_supported_currencies').whereNotIn('monetaryZoneId', supportedCurrencies).andWhere({dfspId}).del();
} else {
await knex('fxp_supported_currencies').where({dfspId}).del();
}
}

const pkiEngine = new PKIEngine(Constants.vault);
await pkiEngine.connect();
for (const [dfsp_id] of dfsps) {
Expand Down
18 changes: 18 additions & 0 deletions src/models/DFSPModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ exports.getDfspsByMonetaryZones = async (monetaryZoneId) => {
return findAllByField('monetaryZoneId', monetaryZoneId);
};

exports.getFxpSupportedCurrencies = async (dfspId) => {
return (await
knex
.table('fxp_supported_currencies')
.join(DFSP_TABLE, 'fxp_supported_currencies.dfspId', 'dfsps.id')
.where(DFSP_TABLE + '.dfsp_id', dfspId)
.select('fxp_supported_currencies.monetaryZoneId')
).map((row) => row.monetaryZoneId);
};

const findByField = async (columnName, value) => {
const rows = await knex.table(DFSP_TABLE).where(columnName, value).select();
if (rows.length === 0) {
Expand All @@ -65,6 +75,14 @@ exports.create = async (values) => {
return knex.table(DFSP_TABLE).insert(values);
};

exports.createFxpSupportedCurrencies = async (dfsp_id, monetaryZoneIds) => {
if (!monetaryZoneIds?.length) return;
const dfspId = await findIdByDfspId(dfsp_id);
return knex.table('fxp_supported_currencies').insert(
monetaryZoneIds.map((monetaryZoneId) => ({ dfspId, monetaryZoneId }))
);
};

exports.deleteByRawId = async (id) => {
return knex.table(DFSP_TABLE).where({ id }).del();
};
Expand Down
3 changes: 2 additions & 1 deletion src/pki_engine/VaultPKIEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class VaultPKIEngine extends PKIEngine {
}
// endregion

async populateDFSPClientCertBundle (dfspId, dfspName, dfspMonetaryZoneId, isProxy) {
async populateDFSPClientCertBundle (dfspId, dfspName, dfspMonetaryZoneId, isProxy, fxpCurrencies) {
this.validateId(dfspId, 'dfspId');
const dfspCA = await this.getDFSPCA(dfspId);
const enrollments = await this.getDFSPOutboundEnrollments(dfspId);
Expand All @@ -321,6 +321,7 @@ class VaultPKIEngine extends PKIEngine {
fqdn: cert.subject.CN,
host: dfspName,
currency_code: dfspMonetaryZoneId,
fxpCurrencies: fxpCurrencies.join(' '),
isProxy,
};
await this.client.write(`${this.mounts.dfspClientCertBundle}/${dfspName}`, bundle);
Expand Down
3 changes: 2 additions & 1 deletion src/service/DfspOnboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ exports.onboardDFSP = async (ctx, dfspId) => {
await PkiService.validateDfsp(ctx, dfspId);
const { pkiEngine } = ctx;
const { id, monetaryZoneId, isProxy } = await DFSPModel.findByDfspId(dfspId);
await pkiEngine.populateDFSPClientCertBundle(id, dfspId, monetaryZoneId, !!isProxy);
const fxpCurrencies = await DFSPModel.getFxpSupportedCurrencies(dfspId);
await pkiEngine.populateDFSPClientCertBundle(id, dfspId, monetaryZoneId, !!isProxy, fxpCurrencies);

const ipsBundle = await getIPsBundle();
await pkiEngine.populateDFSPInternalIPWhitelistBundle(ipsBundle);
Expand Down
1 change: 1 addition & 0 deletions src/service/PkiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports.createDFSP = async (ctx, body) => {

try {
await DFSPModel.create(values);
await DFSPModel.createFxpSupportedCurrencies(body.dfspId, body.fxpCurrencies);
return { id: body.dfspId };
} catch (err) {
console.error(err);
Expand Down
Loading