Skip to content

Commit

Permalink
Merge pull request #508 from telefonicaid/task/add_disable_domain_fea…
Browse files Browse the repository at this point in the history
…ture

add disable domain feature conf
  • Loading branch information
fgalan authored May 19, 2022
2 parents 2b04b9f + 36c1677 commit 6921fe0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Add: conf and env var (DISABLE_DOMAIN_MIDDLEWARE) to disable domain middleware to reduce overhead (but loosing some info in logs) (#498)
- Upgrade mustache dep from 2.2.1 to 2.3.2
- Upgrade node-cache dep from 1.0.3 to 5.1.2
- Add: new API to retrieve and reset cache stats (GET, DELETE /admin/cacheStats)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ Right Attempt | ResponseStatus=200 | Token=860864fb6d1a4c8a8cb7d59d16daaa52 | Or
* `config.bypassRoleId`: ID of the role that will be considered to have administrative rights over the proxy (so being transparently proxied without validation). Valid values are Role UUIDs. E.g.: `db50362d5f264c8292bebdb5c5783741`.
* `config.dieOnRedirectError`: this flags changes the behavior of the PEP Proxy when an error is received when redirecting a request. If the flag is true, the PEP Proxy process is shut down immediately; if it is false, the behavior is the usual: generate a 501 Code error.
* `config.bodyLimit`: Controls the maximum request body size allowed, in bytes. Default is 1 Mb
* `config.disableDomainMiddleware`:Disable domain middleware used for logging. Disabled will reduce overhead, but loses info (transaction, correlator, service, subservice, etc) in logs. Default is false.
### Authentication configuration
* `config.authentication.checkHeaders`: when the proxy is working with the access control disabled (just user authentication), indicates whether the `fiware-service` and `fiware-servicepath` headers should be checked for existance and validity (checking: the headers exist, thy are not empty and the user is really part of the service and subservice mentioned in the header). This option is ignored when authorization is enabled, and considered to be `true` (as the headers constitute a mandatory part of the authorization process). Default value is `true`.
Expand Down Expand Up @@ -538,8 +539,9 @@ Some of the configuration values for the attributes above mentioned can be overr
| PROXY_PASSWORD | config.authentication.password |
| PROXY_PASSWORD | config.authentication.password |
| COMPONENT_NAME | config.componentName |
| COMPONENT_PLUGIN | config.middlewares and config.componentName if no COMPONENT_NAME provided |
| BODY_LIMIT | config.bodyLimit |
| COMPONENT_PLUGIN | config.middlewares and config.componentName if no COMPONENT_NAME provided |
| BODY_LIMIT | config.bodyLimit |
| DISABLE_DOMAIN_MIDDLEWARE | config.disableDomainMiddleware |
### Component configuration
A special environment variable, called `COMPONENT_PLUGIN` can be set with one of this values: `orion`, `perseo`, `keypass` and `rest`. This variable can be used to select what component plugin to load in order to determine the action of the incoming requests. This variable also rewrites `config.componentName` configuration paramenter.
Expand Down
6 changes: 5 additions & 1 deletion bin/pepProxy
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function loadConfiguration() {
'PROXY_PASSWORD',
'COMPONENT_PLUGIN',
'COMPONENT_NAME',
'BODY_LIMIT'
'BODY_LIMIT',
'DISABLE_DOMAIN_MIDDLEWARE'
];

for (var i = 0; i < environmentValues.length; i++) {
Expand Down Expand Up @@ -147,6 +148,9 @@ function loadConfiguration() {
if (process.env.BODY_LIMIT) {
config.bodyLimit = process.env.BODY_LIMIT;
}
if (process.env.DISABLE_DOMAIN_MIDDLEWARE) {
config.disableDomainMiddleware = process.env.DISABLE_DOMAIN_MIDDLEWARE == 'true';
}
}

loadConfiguration();
Expand Down
6 changes: 5 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ config.maxQueuedClients = 1000;
*/
config.bodyLimit = 1048576;


/**
* Disable domain middleware used for logging. Disabled will reduce overhead, but loses info (transaction, correlator, service,
* subservice, etc) in logs. Default is false.
*/
config.disableDomainMiddleware = false;

module.exports = config;
8 changes: 6 additions & 2 deletions lib/fiware-pep-steelskin.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ function initializeProxy(proxyObj, callback) {
proxyObj.proxy.use(xmlRawBody);
proxyObj.proxy.use(rawBody);
proxyObj.proxy.use(bodyParser.urlencoded({limit: config.bodyLimit ? config.bodyLimit : '1Mb', extended: true}));
proxyObj.proxy.use(domainMiddleware);
if (!config.disableDomainMiddleware) {
proxyObj.proxy.use(domainMiddleware);
}

if (config.logLevel && config.logLevel.toUpperCase() === 'DEBUG') {
proxyObj.proxy.use(traceRequest);
Expand Down Expand Up @@ -314,7 +316,9 @@ function initializeAdmin(proxyObj, callback) {
proxyObj.administration.use(bodyParser.json({limit: config.bodyLimit ? config.bodyLimit : '1Mb'}));
proxyObj.administration.use(bodyParser.urlencoded({limit: config.bodyLimit ? config.bodyLimit : '1Mb',
extended: true}));
proxyObj.administration.use(domainMiddleware);
if (!config.disableDomainMiddleware) {
proxyObj.administration.use(domainMiddleware);
}
proxyObj.administration.use(handleError);

adminMiddleware.loadContextRoutes(proxyObj.administration);
Expand Down
5 changes: 3 additions & 2 deletions lib/services/cacheUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ function createDomainEnabledCacheHandler(domain, processValueFn, cache, cacheTyp
callback(error);
} else {
var currentValue = cache.data[cacheType].get(cacheKey) || value;

domain.enter();
if (!config.disableDomainMiddleware) {
domain.enter();
}
logger.debug('Value found for cache type [%s] key [%s]: %j', cacheType, cacheKey, value);
logger.debug('Processing with value: %s', JSON.stringify(cache.data[cacheType].get(cacheKey)));

Expand Down
4 changes: 3 additions & 1 deletion lib/services/keystoneAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ function extractRoles(req, res, next) {

function domainContinuator(domain, callback) {
return function() {
domain.enter();
if (!config.disableDomainMiddleware) {
domain.enter();
}
callback();
};
}
Expand Down

0 comments on commit 6921fe0

Please sign in to comment.