Skip to content

Commit

Permalink
Merge pull request #50 from ceelsoin/master
Browse files Browse the repository at this point in the history
hotfix: change protected fields to allow scoped fields
  • Loading branch information
ceelsoin committed May 23, 2023
2 parents 984d7fd + 675935d commit 9297c26
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
18 changes: 11 additions & 7 deletions lib/http/SchemaResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ class SchemaResponse {
this.functionsRequest = functionsRequest;
this.res = res;
this.schemaName = schemaName;
this.protectedFields = config.responseProtectedFields;
this.allowedFields = config.responseAllowedFields;
}

removeProtectedFields(data) {
for (const field of this.protectedFields) {
delete data[field];
};
};
removeNotAllowedFields(data) {
const { env } = data;
if(env && env.length){
const fieldsToRemove = Object.keys(env.filter(field => !this.allowedFields.includes(field)));
for (const field of fieldsToRemove) {
delete data.env[field];
}
}
}

json(data) {
this.removeProtectedFields(data);
this.removeNotAllowedFields(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
2 changes: 1 addition & 1 deletion lib/support/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +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']),
responseAllowedFields: ConfigDiscovery.getList('RESPONSE_ALLOWED_FIELDS', ['BACKSTAGE_CLIENT_ID']),
metric: {
client: process.env.METRIC_CLIENT,
udpHost: process.env.METRIC_UDP_HOST,
Expand Down
8 changes: 4 additions & 4 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@globocom/backstage-functions",
"version": "0.4.1",
"version": "0.6.0-rc.4",
"description": "Remote serverless code executor",
"main": "index.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
"author": "Backstage Team <backstage@corp.globo.com>",
"license": "MIT",
"dependencies": {
"@globocom/backstage-functions-sandbox": "^0.5.4-next.0",
"@globocom/backstage-functions-sandbox": "^0.5.3",
"@opentelemetry/api": "^0.18.1",
"@opentelemetry/core": "^0.19.0",
"@opentelemetry/exporter-collector-grpc": "^0.19.0",
Expand Down

0 comments on commit 9297c26

Please sign in to comment.