Skip to content

Commit

Permalink
Merge pull request #210 from bcgov/bugfix/explicitjsonparsing
Browse files Browse the repository at this point in the history
Refactor express.json middleware to be route explicit
  • Loading branch information
TimCsaky authored Sep 14, 2023
2 parents b94bb30 + 806f7fc commit fcf706c
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 39 deletions.
1 change: 0 additions & 1 deletion .github/actions/deploy-to-environment/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ runs:
--set image.repository=ghcr.io/${{ github.repository_owner }}
--set image.tag=sha-$(git rev-parse --short HEAD)
--set route.host=${{ inputs.acronym }}-${{ inputs.namespace_environment }}-${{ inputs.job_name }}.apps.silver.devops.gov.bc.ca
--set config.configMap.OBJECTSTORAGE_KEY=${{ inputs.acronym }}/${{ inputs.namespace_environment }}
--timeout 10m
--wait
Expand Down
1 change: 0 additions & 1 deletion .github/environments/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ config:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuy7zfh2ZgpDV5mH/aXyLDTddZK81rGakJcTy4KvCNOkDDxt1KAhW02lmbCo8YhHCOzjNZBp1+Vi6QiMRgBqAe2GTPZYEiV70aXfROGZe3Nvwcjbtki6HoyRte3SpqLJEIPL2F+hjJkw1UPGnjPTWZkEx9p74b9i3BjuE8RnjJ0Sza2MWw83zoQUZEJRGiopSL0yuVej6t2LO2btVdVf7QuZfPt9ehkcQYlPKpVvJA+pfeqPAdnNt7OjEIeYxinjurZr8Z04hz8UhkRefcWlSbFzFQYmL7O7iArjW0bsSvq8yNUd5r0KCOQkFduwZy26yTzTxj8OLFT91fEmbBBl4rQIDAQAB
KC_REALM: standard
KC_SERVERURL: "https://dev.loginproxy.gov.bc.ca/auth"
SERVER_BODYLIMIT: 30mb
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_PORT: "3000"
Expand Down
1 change: 0 additions & 1 deletion .github/environments/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ config:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmHiuPKOkpkq4GXN1ktr23rJtDl6Vdu/Y37ZAd3PnQ8/IDfAODvy1Y81aAUZicKe9egolv+OTRANN3yOg+TAbRhkeXLE5p/473EK0aQ0NazTCuWo6Am3oDQ7Yt8x0pw56/qcLtkTuXNyo5EnVV2Z2BzCnnaL31JOhyitolku0DNT6GDoRBmT4o2ItqEVHk5nM25cf1t2zbwI2790W6if1B2qVRkxxivS8tbH7nYC61Is3XCPockKptkH22cm2ZQJmtYd5sZKuXaGsvtyzHmn8/l0Kd1xnHmUu4JNuQ67YiNZGu3hOkrF0Js3BzAk1Qm4kvYRaxbJFCs/qokLZ4Z0W9wIDAQAB
KC_REALM: standard
KC_SERVERURL: "https://loginproxy.gov.bc.ca/auth"
SERVER_BODYLIMIT: 30mb
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_PORT: "3000"
Expand Down
1 change: 0 additions & 1 deletion .github/environments/values.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ config:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiFdv9GA83uHuy8Eu9yiZHGGF9j6J8t7FkbcpaN81GDjwbjsIJ0OJO9dKRAx6BAtTC4ubJTBJMPvQER5ikOhIeBi4o25fg61jpgsU6oRZHkCXc9gX6mrjMjbsPaf3/bjjYxP5jicBDJQeD1oRa24+tiGggoQ7k6gDEN+cRYqqNpzC/GQbkUPk8YsgroncEgu8ChMh/3ERsLV2zorchMANUq76max16mHrhtWIQxrb/STpSt4JuSlUzzBV/dcXjJe5gywZHe0jAutFhNqjHzHdgyaC4RAd3eYQo+Kl/JOgy2AZrnx+CiPmvOJKe9tAW4k4H087ng8aVE40v4HW/FEbnwIDAQAB
KC_REALM: standard
KC_SERVERURL: "https://test.loginproxy.gov.bc.ca/auth"
SERVER_BODYLIMIT: 30mb
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: http
SERVER_PORT: "3000"
Expand Down
10 changes: 0 additions & 10 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const compression = require('compression');
const config = require('config');
const cors = require('cors');
const express = require('express');
const { unless } = require('express-unless');
const { ValidationError } = require('express-validation');

const { AuthMode, DEFAULTCORS } = require('./src/components/constants');
Expand Down Expand Up @@ -31,17 +30,8 @@ let probeId;
let queueId;

const app = express();
const jsonParser = express.json({ limit: config.get('server.bodyLimit') });
jsonParser.unless = unless;
app.use(compression());
app.use(cors(DEFAULTCORS));
app.use(jsonParser.unless({
path: [{
// Matches on only the createObject and updateObject endpoints
url: /.*(?<!permission)\/object(\/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})?(\/)?(\?.*)?$/i,
methods: ['PUT']
}]
}));
app.use(express.urlencoded({ extended: true }));

// Skip if running tests
Expand Down
1 change: 0 additions & 1 deletion app/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"secretAccessKey": "OBJECTSTORAGE_SECRETACCESSKEY"
},
"server": {
"bodyLimit": "SERVER_BODYLIMIT",
"defaultTempExpiresIn": "SERVER_TEMP_EXPIRESIN",
"hardReset": "SERVER_HARDRESET",
"logFile": "SERVER_LOGFILE",
Expand Down
1 change: 0 additions & 1 deletion app/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"username": "app"
},
"server": {
"bodyLimit": "30mb",
"defaultTempExpiresIn": "300",
"logLevel": "http",
"maxRetries": "3",
Expand Down
11 changes: 0 additions & 11 deletions app/package-lock.json

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

1 change: 0 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"date-fns": "^2.30.0",
"express": "^4.18.2",
"express-basic-auth": "^1.2.1",
"express-unless": "^2.1.3",
"express-validation": "^4.1.0",
"express-winston": "^4.2.0",
"js-yaml": "^4.1.0",
Expand Down
7 changes: 4 additions & 3 deletions app/src/routes/v1/bucket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const router = require('express').Router();
const express = require('express');
const router = express.Router();

const { Permissions } = require('../../components/constants');
const { bucketController, syncController } = require('../../controllers');
Expand All @@ -10,7 +11,7 @@ router.use(checkAppMode);
router.use(requireSomeAuth);

/** Creates a bucket */
router.put('/', bucketValidator.createBucket, (req, res, next) => {
router.put('/', express.json(), bucketValidator.createBucket, (req, res, next) => {
bucketController.createBucket(req, res, next);
});

Expand All @@ -35,7 +36,7 @@ router.get('/', bucketValidator.searchBuckets, (req, res, next) => {
});

/** Updates a bucket */
router.patch('/:bucketId', bucketValidator.updateBucket, hasPermission(Permissions.UPDATE), (req, res, next) => {
router.patch('/:bucketId', express.json(), bucketValidator.updateBucket, hasPermission(Permissions.UPDATE), (req, res, next) => {
bucketController.updateBucket(req, res, next);
});

Expand Down
5 changes: 3 additions & 2 deletions app/src/routes/v1/permission/bucketPermission.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const router = require('express').Router();
const express = require('express');
const router = express.Router();

const { Permissions } = require('../../../components/constants');
const { bucketPermissionController } = require('../../../controllers');
Expand All @@ -20,7 +21,7 @@ router.get('/:bucketId', bucketPermissionValidator.listPermissions, currentObjec
});

/** Grants bucket permissions to users */
router.put('/:bucketId', bucketPermissionValidator.addPermissions, currentObject, hasPermission(Permissions.MANAGE), (req, res, next) => {
router.put('/:bucketId', express.json(), bucketPermissionValidator.addPermissions, currentObject, hasPermission(Permissions.MANAGE), (req, res, next) => {
bucketPermissionController.addPermissions(req, res, next);
});

Expand Down
5 changes: 3 additions & 2 deletions app/src/routes/v1/permission/objectPermission.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const router = require('express').Router();
const express = require('express');
const router = express.Router();

const { Permissions } = require('../../../components/constants');
const { objectPermissionController } = require('../../../controllers');
Expand All @@ -20,7 +21,7 @@ router.get('/:objectId', objectPermissionValidator.listPermissions, currentObjec
});

/** Grants object permissions to users */
router.put('/:objectId', objectPermissionValidator.addPermissions, currentObject, hasPermission(Permissions.MANAGE), (req, res, next) => {
router.put('/:objectId', express.json(), objectPermissionValidator.addPermissions, currentObject, hasPermission(Permissions.MANAGE), (req, res, next) => {
objectPermissionController.addPermissions(req, res, next);
});

Expand Down
2 changes: 1 addition & 1 deletion charts/coms/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: common-object-management-service
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.18
version: 0.0.19
kubeVersion: ">= 1.13.0"
description: A microservice for managing access control to S3 Objects
# A chart can be either an 'application' or a 'library' chart.
Expand Down
4 changes: 2 additions & 2 deletions charts/coms/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# common-object-management-service

![Version: 0.0.18](https://img.shields.io/badge/Version-0.0.18-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.6.0](https://img.shields.io/badge/AppVersion-0.6.0-informational?style=flat-square)
![Version: 0.0.19](https://img.shields.io/badge/Version-0.0.19-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.6.0](https://img.shields.io/badge/AppVersion-0.6.0-informational?style=flat-square)

A microservice for managing access control to S3 Objects

Expand Down Expand Up @@ -35,7 +35,7 @@ Kubernetes: `>= 1.13.0`
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| basicAuthSecretOverride.password | string | `nil` | |
| basicAuthSecretOverride.username | string | `nil` | |
| config.configMap | object | `{"DB_PORT":"5432","KC_IDENTITYKEY":null,"KC_PUBLICKEY":null,"KC_REALM":null,"KC_SERVERURL":null,"OBJECTSTORAGE_BUCKET":null,"OBJECTSTORAGE_ENDPOINT":null,"OBJECTSTORAGE_KEY":null,"SERVER_BODYLIMIT":"30mb","SERVER_LOGLEVEL":"http","SERVER_PORT":"3000","SERVER_TEMP_EXPIRESIN":"300"}` | These values will be wholesale added to the configmap as is; refer to the coms documentation for what each of these values mean and whether you need them defined. Ensure that all values are represented explicitly as strings, as non-string values will not translate over as expected into container environment variables. For configuration keys named `*_ENABLED`, either leave them commented/undefined, or set them to string value "true". |
| config.configMap | object | `{"DB_PORT":"5432","KC_IDENTITYKEY":null,"KC_PUBLICKEY":null,"KC_REALM":null,"KC_SERVERURL":null,"OBJECTSTORAGE_BUCKET":null,"OBJECTSTORAGE_ENDPOINT":null,"OBJECTSTORAGE_KEY":null,"SERVER_LOGLEVEL":"http","SERVER_PORT":"3000","SERVER_TEMP_EXPIRESIN":"300"}` | These values will be wholesale added to the configmap as is; refer to the coms documentation for what each of these values mean and whether you need them defined. Ensure that all values are represented explicitly as strings, as non-string values will not translate over as expected into container environment variables. For configuration keys named `*_ENABLED`, either leave them commented/undefined, or set them to string value "true". |
| config.enabled | bool | `false` | |
| config.releaseScoped | bool | `false` | This should be set to true if and only if you require configmaps and secrets to be release scoped. In the event you want all instances in the same namespace to share a similar configuration, this should be set to false |
| dbSecretOverride.password | string | `nil` | |
Expand Down
1 change: 0 additions & 1 deletion charts/coms/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ config:
OBJECTSTORAGE_ENDPOINT: ~
OBJECTSTORAGE_KEY: ~

SERVER_BODYLIMIT: "30mb"
# SERVER_HARDRESET: "true"
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: "http"
Expand Down

0 comments on commit fcf706c

Please sign in to comment.