Skip to content

Commit

Permalink
Merge pull request #49 from fguisso/protectedEnv
Browse files Browse the repository at this point in the history
feat: add support for removing protected fields from response
  • Loading branch information
FLEME5 authored Apr 20, 2023
2 parents 57ecca9 + 9ab6c85 commit 984d7fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/http/SchemaResponse.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const config = require('../support/config');

class SchemaResponse {
constructor(functionsRequest, res, schemaName) {
this.functionsRequest = functionsRequest;
this.res = res;
this.schemaName = schemaName;
this.protectedFields = config.responseProtectedFields;
}

removeProtectedFields(data) {
for (const field of this.protectedFields) {
delete data[field];
};
};

json(data) {
this.removeProtectedFields(data);
const schemeAndAuthority = this.functionsRequest.schemeAndAuthority();
this.res.set('Content-Type', `application/json; charset=utf-8; profile=${schemeAndAuthority}/_schemas/${this.schemaName}`);
this.res.end(JSON.stringify(data));
Expand Down
1 change: 1 addition & 0 deletions lib/support/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
defaultGlobalModules: ConfigDiscovery.getList('DEFAULT_GLOBAL_MODULES', DEFAULT_GLOBAL_MODULES),
bodyParserLimit: process.env.BODY_PARSER_LIMIT || '1mb',
redisConnectionTimeout: ConfigDiscovery.getInt('REDIS_CONNECTION_TIMEOUT', 2000),
responseProtectedFields: ConfigDiscovery.getList('RESPONSE_PROTECTED_FIELDS', ['env']),
metric: {
client: process.env.METRIC_CLIENT,
udpHost: process.env.METRIC_UDP_HOST,
Expand Down

0 comments on commit 984d7fd

Please sign in to comment.