From 3e84560cb0149915a52151ffa9b3655cbf5c8fc6 Mon Sep 17 00:00:00 2001 From: fboucquez Date: Wed, 19 May 2021 18:04:19 -0300 Subject: [PATCH] Added configurable rest extensions (#251) fix: added cmc and configurable extensions to rest.json template --- config/rest-gateway/rest.json.mustache | 14 +-- presets/shared.yml | 1 + src/service/BootstrapUtils.ts | 18 +++- .../bootstrap-voting/rest-gateway-0-rest.json | 87 +++++++++++++++++++ .../rest-gateway-rest.json | 87 +++++++++++++++++++ .../mainnet-dual/rest-gateway-rest.json | 87 +++++++++++++++++++ .../testnet-api/rest-gateway-rest.json | 87 +++++++++++++++++++ .../rest-gateway-rest.json | 87 +++++++++++++++++++ test/service/ReportService.test.ts | 19 +++- 9 files changed, 472 insertions(+), 15 deletions(-) create mode 100644 test/reports/bootstrap-voting/rest-gateway-0-rest.json create mode 100644 test/reports/mainnet-dual-voting/rest-gateway-rest.json create mode 100644 test/reports/mainnet-dual/rest-gateway-rest.json create mode 100644 test/reports/testnet-api/rest-gateway-rest.json create mode 100644 test/reports/testnet-dual-voting/rest-gateway-rest.json diff --git a/config/rest-gateway/rest.json.mustache b/config/rest-gateway/rest.json.mustache index 5054b8210..9ad4b6860 100644 --- a/config/rest-gateway/rest.json.mustache +++ b/config/rest-gateway/rest.json.mustache @@ -9,19 +9,7 @@ "allowedHosts": ["*"], "allowedMethods": ["GET", "POST", "PUT", "OPTIONS"] }, - "extensions": [ - "accountLink", - "aggregate", - "lockHash", - "lockSecret", - "mosaic", - "metadata", - "multisig", - "namespace", - "receipts", - "restrictions", - "transfer" - ], + "extensions": {{{toJson (splitCsv restExtensions)}}}, "db": { "url": "mongodb://{{{databaseHost}}}:27017/", "name": "catapult", diff --git a/presets/shared.yml b/presets/shared.yml index 5c3e1c0df..7fbe569c5 100644 --- a/presets/shared.yml +++ b/presets/shared.yml @@ -211,6 +211,7 @@ maxConnectionAttempts: 15 baseRetryDelay: 750 connectionPoolSize: 10 maxSubscriptions: 300 +restExtensions: 'accountLink, aggregate, lockHash, lockSecret, mosaic, metadata, multisig, namespace, receipts, restrictions, transfer, cmc' #voting votingKeyStartEpoch: 1 diff --git a/src/service/BootstrapUtils.ts b/src/service/BootstrapUtils.ts index dc313f2e2..c5f9567e1 100644 --- a/src/service/BootstrapUtils.ts +++ b/src/service/BootstrapUtils.ts @@ -378,7 +378,13 @@ export class BootstrapUtils { if (isMustache) { const template = await BootstrapUtils.readTextFile(fromPath); const renderedTemplate = this.runTemplate(template, templateContext); - await fsPromises.writeFile(destinationFile, renderedTemplate); + + await fsPromises.writeFile( + destinationFile, + destinationFile.toLowerCase().endsWith('.json') + ? BootstrapUtils.formatJson(renderedTemplate) + : renderedTemplate, + ); } else { await fsPromises.copyFile(fromPath, destinationFile); } @@ -633,6 +639,7 @@ export class BootstrapUtils { Handlebars.registerHelper('toSimpleHex', BootstrapUtils.toSimpleHex); Handlebars.registerHelper('toSeconds', BootstrapUtils.toSeconds); Handlebars.registerHelper('toJson', BootstrapUtils.toJson); + Handlebars.registerHelper('splitCsv', BootstrapUtils.splitCsv); Handlebars.registerHelper('add', BootstrapUtils.add); Handlebars.registerHelper('minus', BootstrapUtils.minus); Handlebars.registerHelper('computerMemory', BootstrapUtils.computerMemory); @@ -683,6 +690,15 @@ export class BootstrapUtils { return JSON.stringify(object, null, 2); } + public static formatJson(string: string): string { + // Validates and format the json string. + return JSON.stringify(JSON.parse(string), null, 2); + } + + public static splitCsv(object: string): string[] { + return (object || '').split(',').map((c) => c.trim()); + } + public static toSeconds(serverDuration: string): number { return DtoMapping.parseServerDuration(serverDuration).seconds(); } diff --git a/test/reports/bootstrap-voting/rest-gateway-0-rest.json b/test/reports/bootstrap-voting/rest-gateway-0-rest.json new file mode 100644 index 000000000..98d1f5935 --- /dev/null +++ b/test/reports/bootstrap-voting/rest-gateway-0-rest.json @@ -0,0 +1,87 @@ +{ + "network": { + "name": "publicTest", + "description": "catapult development network" + }, + "port": 3000, + "crossDomain": { + "allowedHosts": [ + "*" + ], + "allowedMethods": [ + "GET", + "POST", + "PUT", + "OPTIONS" + ] + }, + "extensions": [ + "accountLink", + "aggregate", + "lockHash", + "lockSecret", + "mosaic", + "metadata", + "multisig", + "namespace", + "receipts", + "restrictions", + "transfer", + "cmc" + ], + "db": { + "url": "mongodb://db-0:27017/", + "name": "catapult", + "pageSizeMin": 10, + "pageSizeMax": 100, + "maxConnectionAttempts": 15, + "baseRetryDelay": 750, + "connectionPoolSize": 10 + }, + "apiNode": { + "host": "api-node-0", + "port": 7900, + "tlsClientCertificatePath": "/symbol-workdir/api-node-config/cert/node.crt.pem", + "tlsClientKeyPath": "/symbol-workdir/api-node-config/cert/node.key.pem", + "tlsCaCertificatePath": "/symbol-workdir/api-node-config/cert/ca.cert.pem", + "timeout": 1000, + "networkPropertyFilePath": "/symbol-workdir/api-node-config/config-network.properties", + "nodePropertyFilePath": "/symbol-workdir/api-node-config/config-node.properties" + }, + "websocket": { + "mq": { + "host": "api-node-broker-0", + "port": 7902, + "monitorInterval": 500, + "connectTimeout": 10000, + "monitorLoggingThrottle": 60000, + "maxSubscriptions": 300 + }, + "allowOptionalAddress": true + }, + "throttling": { + "burst": 80, + "rate": 60 + }, + "logging": { + "console": { + "formats": [ + "colorize", + "simple" + ], + "level": "verbose", + "handleExceptions": true + }, + "file": { + "formats": [ + "prettyPrint" + ], + "level": "verbose", + "handleExceptions": true, + "filename": "/symbol-workdir/logs/catapult-rest.log", + "maxsize": 20971520, + "maxFiles": 100 + } + }, + "numBlocksTransactionFeeStats": 300 +} \ No newline at end of file diff --git a/test/reports/mainnet-dual-voting/rest-gateway-rest.json b/test/reports/mainnet-dual-voting/rest-gateway-rest.json new file mode 100644 index 000000000..0b1676e71 --- /dev/null +++ b/test/reports/mainnet-dual-voting/rest-gateway-rest.json @@ -0,0 +1,87 @@ +{ + "network": { + "name": "public", + "description": "catapult public main network" + }, + "port": 3000, + "crossDomain": { + "allowedHosts": [ + "*" + ], + "allowedMethods": [ + "GET", + "POST", + "PUT", + "OPTIONS" + ] + }, + "extensions": [ + "accountLink", + "aggregate", + "lockHash", + "lockSecret", + "mosaic", + "metadata", + "multisig", + "namespace", + "receipts", + "restrictions", + "transfer", + "cmc" + ], + "db": { + "url": "mongodb://db:27017/", + "name": "catapult", + "pageSizeMin": 10, + "pageSizeMax": 100, + "maxConnectionAttempts": 15, + "baseRetryDelay": 750, + "connectionPoolSize": 10 + }, + "apiNode": { + "host": "node", + "port": 7900, + "tlsClientCertificatePath": "/symbol-workdir/api-node-config/cert/node.crt.pem", + "tlsClientKeyPath": "/symbol-workdir/api-node-config/cert/node.key.pem", + "tlsCaCertificatePath": "/symbol-workdir/api-node-config/cert/ca.cert.pem", + "timeout": 1000, + "networkPropertyFilePath": "/symbol-workdir/api-node-config/config-network.properties", + "nodePropertyFilePath": "/symbol-workdir/api-node-config/config-node.properties" + }, + "websocket": { + "mq": { + "host": "broker", + "port": 7902, + "monitorInterval": 500, + "connectTimeout": 10000, + "monitorLoggingThrottle": 60000, + "maxSubscriptions": 300 + }, + "allowOptionalAddress": true + }, + "throttling": { + "burst": 80, + "rate": 60 + }, + "logging": { + "console": { + "formats": [ + "colorize", + "simple" + ], + "level": "verbose", + "handleExceptions": true + }, + "file": { + "formats": [ + "prettyPrint" + ], + "level": "verbose", + "handleExceptions": true, + "filename": "/symbol-workdir/logs/catapult-rest.log", + "maxsize": 20971520, + "maxFiles": 100 + } + }, + "numBlocksTransactionFeeStats": 300 +} \ No newline at end of file diff --git a/test/reports/mainnet-dual/rest-gateway-rest.json b/test/reports/mainnet-dual/rest-gateway-rest.json new file mode 100644 index 000000000..0b1676e71 --- /dev/null +++ b/test/reports/mainnet-dual/rest-gateway-rest.json @@ -0,0 +1,87 @@ +{ + "network": { + "name": "public", + "description": "catapult public main network" + }, + "port": 3000, + "crossDomain": { + "allowedHosts": [ + "*" + ], + "allowedMethods": [ + "GET", + "POST", + "PUT", + "OPTIONS" + ] + }, + "extensions": [ + "accountLink", + "aggregate", + "lockHash", + "lockSecret", + "mosaic", + "metadata", + "multisig", + "namespace", + "receipts", + "restrictions", + "transfer", + "cmc" + ], + "db": { + "url": "mongodb://db:27017/", + "name": "catapult", + "pageSizeMin": 10, + "pageSizeMax": 100, + "maxConnectionAttempts": 15, + "baseRetryDelay": 750, + "connectionPoolSize": 10 + }, + "apiNode": { + "host": "node", + "port": 7900, + "tlsClientCertificatePath": "/symbol-workdir/api-node-config/cert/node.crt.pem", + "tlsClientKeyPath": "/symbol-workdir/api-node-config/cert/node.key.pem", + "tlsCaCertificatePath": "/symbol-workdir/api-node-config/cert/ca.cert.pem", + "timeout": 1000, + "networkPropertyFilePath": "/symbol-workdir/api-node-config/config-network.properties", + "nodePropertyFilePath": "/symbol-workdir/api-node-config/config-node.properties" + }, + "websocket": { + "mq": { + "host": "broker", + "port": 7902, + "monitorInterval": 500, + "connectTimeout": 10000, + "monitorLoggingThrottle": 60000, + "maxSubscriptions": 300 + }, + "allowOptionalAddress": true + }, + "throttling": { + "burst": 80, + "rate": 60 + }, + "logging": { + "console": { + "formats": [ + "colorize", + "simple" + ], + "level": "verbose", + "handleExceptions": true + }, + "file": { + "formats": [ + "prettyPrint" + ], + "level": "verbose", + "handleExceptions": true, + "filename": "/symbol-workdir/logs/catapult-rest.log", + "maxsize": 20971520, + "maxFiles": 100 + } + }, + "numBlocksTransactionFeeStats": 300 +} \ No newline at end of file diff --git a/test/reports/testnet-api/rest-gateway-rest.json b/test/reports/testnet-api/rest-gateway-rest.json new file mode 100644 index 000000000..3512ecdb0 --- /dev/null +++ b/test/reports/testnet-api/rest-gateway-rest.json @@ -0,0 +1,87 @@ +{ + "network": { + "name": "publicTest", + "description": "catapult public test network" + }, + "port": 3000, + "crossDomain": { + "allowedHosts": [ + "*" + ], + "allowedMethods": [ + "GET", + "POST", + "PUT", + "OPTIONS" + ] + }, + "extensions": [ + "accountLink", + "aggregate", + "lockHash", + "lockSecret", + "mosaic", + "metadata", + "multisig", + "namespace", + "receipts", + "restrictions", + "transfer", + "cmc" + ], + "db": { + "url": "mongodb://db:27017/", + "name": "catapult", + "pageSizeMin": 10, + "pageSizeMax": 100, + "maxConnectionAttempts": 15, + "baseRetryDelay": 750, + "connectionPoolSize": 10 + }, + "apiNode": { + "host": "node", + "port": 7900, + "tlsClientCertificatePath": "/symbol-workdir/api-node-config/cert/node.crt.pem", + "tlsClientKeyPath": "/symbol-workdir/api-node-config/cert/node.key.pem", + "tlsCaCertificatePath": "/symbol-workdir/api-node-config/cert/ca.cert.pem", + "timeout": 1000, + "networkPropertyFilePath": "/symbol-workdir/api-node-config/config-network.properties", + "nodePropertyFilePath": "/symbol-workdir/api-node-config/config-node.properties" + }, + "websocket": { + "mq": { + "host": "broker", + "port": 7902, + "monitorInterval": 500, + "connectTimeout": 10000, + "monitorLoggingThrottle": 60000, + "maxSubscriptions": 300 + }, + "allowOptionalAddress": true + }, + "throttling": { + "burst": 80, + "rate": 60 + }, + "logging": { + "console": { + "formats": [ + "colorize", + "simple" + ], + "level": "verbose", + "handleExceptions": true + }, + "file": { + "formats": [ + "prettyPrint" + ], + "level": "verbose", + "handleExceptions": true, + "filename": "/symbol-workdir/logs/catapult-rest.log", + "maxsize": 20971520, + "maxFiles": 100 + } + }, + "numBlocksTransactionFeeStats": 300 +} \ No newline at end of file diff --git a/test/reports/testnet-dual-voting/rest-gateway-rest.json b/test/reports/testnet-dual-voting/rest-gateway-rest.json new file mode 100644 index 000000000..3512ecdb0 --- /dev/null +++ b/test/reports/testnet-dual-voting/rest-gateway-rest.json @@ -0,0 +1,87 @@ +{ + "network": { + "name": "publicTest", + "description": "catapult public test network" + }, + "port": 3000, + "crossDomain": { + "allowedHosts": [ + "*" + ], + "allowedMethods": [ + "GET", + "POST", + "PUT", + "OPTIONS" + ] + }, + "extensions": [ + "accountLink", + "aggregate", + "lockHash", + "lockSecret", + "mosaic", + "metadata", + "multisig", + "namespace", + "receipts", + "restrictions", + "transfer", + "cmc" + ], + "db": { + "url": "mongodb://db:27017/", + "name": "catapult", + "pageSizeMin": 10, + "pageSizeMax": 100, + "maxConnectionAttempts": 15, + "baseRetryDelay": 750, + "connectionPoolSize": 10 + }, + "apiNode": { + "host": "node", + "port": 7900, + "tlsClientCertificatePath": "/symbol-workdir/api-node-config/cert/node.crt.pem", + "tlsClientKeyPath": "/symbol-workdir/api-node-config/cert/node.key.pem", + "tlsCaCertificatePath": "/symbol-workdir/api-node-config/cert/ca.cert.pem", + "timeout": 1000, + "networkPropertyFilePath": "/symbol-workdir/api-node-config/config-network.properties", + "nodePropertyFilePath": "/symbol-workdir/api-node-config/config-node.properties" + }, + "websocket": { + "mq": { + "host": "broker", + "port": 7902, + "monitorInterval": 500, + "connectTimeout": 10000, + "monitorLoggingThrottle": 60000, + "maxSubscriptions": 300 + }, + "allowOptionalAddress": true + }, + "throttling": { + "burst": 80, + "rate": 60 + }, + "logging": { + "console": { + "formats": [ + "colorize", + "simple" + ], + "level": "verbose", + "handleExceptions": true + }, + "file": { + "formats": [ + "prettyPrint" + ], + "level": "verbose", + "handleExceptions": true, + "filename": "/symbol-workdir/logs/catapult-rest.log", + "maxsize": 20971520, + "maxFiles": 100 + } + }, + "numBlocksTransactionFeeStats": 300 +} \ No newline at end of file diff --git a/test/service/ReportService.test.ts b/test/service/ReportService.test.ts index f3422b07c..8305497dd 100644 --- a/test/service/ReportService.test.ts +++ b/test/service/ReportService.test.ts @@ -43,6 +43,23 @@ describe('ReportService', () => { `, ).to.be.eq(expectedReport.trim()); }); + + for (const gateway of configResult.presetData.gateways || []) { + const currentRestJsonFile = BootstrapUtils.getTargetGatewayFolder(params.target, true, gateway.name, 'rest.json'); + const currentRestJson = await BootstrapUtils.readTextFile(currentRestJsonFile); + const expectedRestJsonFile = join(expectedReportFolder, `${gateway.name}-rest.json`); + if (!existsSync(expectedRestJsonFile)) { + await BootstrapUtils.writeTextFile(expectedRestJsonFile, currentRestJson); + } + const expectedRestJson = await BootstrapUtils.readTextFile(expectedRestJsonFile); + expect( + currentRestJson.trim(), + `Rest ${currentRestJsonFile} doesn't match + +`, + ).to.be.eq(expectedRestJson.trim()); + } + await Promise.all(promises); }; @@ -59,7 +76,7 @@ describe('ReportService', () => { }; const params = { ...ConfigService.defaultParams, - reset: false, + upgrade: true, preset: Preset.testnet, customPresetObject: customPresetObject, assembly: 'dual',