Skip to content

Commit

Permalink
Merge 62446df into c405caa
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega authored May 6, 2024
2 parents c405caa + 62446df commit 3e63399
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix default express limit to 1Mb instead default 100Kb and allow change it throught a conf env var 'IOTA_EXPRESS_LIMIT' (#telefonicaid/iotagent-json#827)
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var config = {
subservice: '/gardens',
providerUrl: 'http://192.168.56.1:4041',
deviceRegistrationDuration: 'P1M',
defaultType: 'Thing'
defaultType: 'Thing',
expressLimit: '1Mb'
};

module.exports = config;
21 changes: 14 additions & 7 deletions doc/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ the `mongob` section (as described bellow). E.g.:

It configures the MongoDB driver for those repositories with 'mongodb' type. If the `host` parameter is a list of
comma-separated IPs, they will be considered to be part of a Replica Set. In that case, the optional property
`replicaSet` should contain the Replica Set name. If the database requires authentication, username (`user`),
password (`password`) and authSource (`authSource`) can be set. If the database requires TLS/SSL connection but any
validation of the certificate chain is not mandatory, all you need is to set the ssl (`ssl`) option as `true` to connect
the database. If you need to add more complex option(s) such as `retryWrites=true` or `w=majority` when connection
database, extraArgs (`extraArgs`) can be used to perform it. For The MongoBD driver will retry the connection at startup
time `retries` times, waiting `retryTime` seconds between attempts, if those attributes are present (default values are
5 and 5 respectively). E.g.:
`replicaSet` should contain the Replica Set name. If the database requires authentication, username (`user`), password
(`password`) and authSource (`authSource`) can be set. If the database requires TLS/SSL connection but any validation of
the certificate chain is not mandatory, all you need is to set the ssl (`ssl`) option as `true` to connect the database.
If you need to add more complex option(s) such as `retryWrites=true` or `w=majority` when connection database, extraArgs
(`extraArgs`) can be used to perform it. For The MongoBD driver will retry the connection at startup time `retries`
times, waiting `retryTime` seconds between attempts, if those attributes are present (default values are 5 and 5
respectively). E.g.:

```javascript
{
Expand Down Expand Up @@ -421,6 +421,12 @@ characters (such as semi-colons) which are
specification. When provisioning devices, it is necessary that the developer provides valid `objectId`-`name` mappings
whenever relaxed mode is used, to prevent the consumption of forbidden characters.

#### `expressLimit`

IotAgents, as all Express applications that use the body-parser middleware, have a default limit to the request body
size that the application will handle. This default limit for ioiotagnets are 1Mb. So, if your IotAgent receives a
request with a body that exceeds this limit, the application will throw a “Error: Request entity too large”.

### Configuration using environment variables

Some of the configuration parameters can be overriden with environment variables, to ease the use of those parameters
Expand Down Expand Up @@ -482,6 +488,7 @@ overrides.
| IOTA_EXPLICIT_ATTRS | `explicitAttrs` |
| IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION | `defaultEntityNameConjunction` |
| IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
| IOTA_EXPRESS_LIMIT | `expressLimit` |

Note:

Expand Down
8 changes: 7 additions & 1 deletion lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function processEnvironmentVariables() {
'IOTA_FALLBACK_TENANT',
'IOTA_FALLBACK_PATH',
'IOTA_LD_SUPPORT_NULL',
'IOTA_LD_SUPPORT_DATASET_ID'
'IOTA_LD_SUPPORT_DATASET_ID',
'IOTA_EXPRESS_LIMIT'
];
const iotamVariables = [
'IOTA_IOTAM_URL',
Expand Down Expand Up @@ -468,6 +469,11 @@ function processEnvironmentVariables() {
? config.defaultEntityNameConjunction
: ':';
}
if (process.env.IOTA_EXPRESS_LIMIT) {
config.expressLimit = process.env.IOTA_EXPRESS_LIMIT;
} else {
config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
}
}

function setConfig(newConfig) {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/northBound/northboundServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function start(config, callback) {
northboundServer.app.set('port', config.server.port);
northboundServer.app.set('host', config.server.host || '0.0.0.0');
northboundServer.app.use(domainUtils.requestDomain);
northboundServer.app.use(bodyParser.json());
northboundServer.app.use(bodyParser.json({ type: 'application/*+json' }));
northboundServer.app.use(bodyParser.json({ limit: config.expressLimit }));
northboundServer.app.use(bodyParser.json({ type: 'application/*+json', limit: config.expressLimit }));

if (config.logLevel && config.logLevel === 'DEBUG') {
northboundServer.app.use(middlewares.traceRequest);
Expand Down

0 comments on commit 3e63399

Please sign in to comment.