Skip to content

Commit

Permalink
Added configurable rest extensions (#251)
Browse files Browse the repository at this point in the history
fix: added cmc and configurable extensions to rest.json template
  • Loading branch information
fboucquez authored May 19, 2021
1 parent e93a481 commit 3e84560
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 15 deletions.
14 changes: 1 addition & 13 deletions config/rest-gateway/rest.json.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions presets/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/service/BootstrapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
87 changes: 87 additions & 0 deletions test/reports/bootstrap-voting/rest-gateway-0-rest.json
Original file line number Diff line number Diff line change
@@ -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
}
87 changes: 87 additions & 0 deletions test/reports/mainnet-dual-voting/rest-gateway-rest.json
Original file line number Diff line number Diff line change
@@ -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
}
87 changes: 87 additions & 0 deletions test/reports/mainnet-dual/rest-gateway-rest.json
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 3e84560

Please sign in to comment.