Skip to content

Commit

Permalink
feat: allow maximum http request size to be configurable (#268)
Browse files Browse the repository at this point in the history
This change allows the maximum HTTP request size to be configurable.
  • Loading branch information
ChristopherFry committed May 25, 2023
1 parent df9ce8f commit 088c268
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions plugins/cad-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ configAsData:
# Determines the GitOps delivery tool to use.
gitOpsDeliveryTool: config-sync

# Optional. Determines the maximum http request body size.
maxRequestSize: 1mb

clusterLocatorMethod:
# Determines how the client will locate the Kubernetes cluster.
type: current-context
Expand All @@ -77,6 +80,9 @@ configAsData:
`gitOpsDeliveryTool` determines what tool to use for GitOps
`maxRequestSize` determines the maximum http request body size. Default is 1mb.
HTTP Status Code 413 will be returned for any requests exceeding this size.
Valid values:
| Values | Description |
| ------ | ----------- |
Expand Down
6 changes: 6 additions & 0 deletions plugins/cad-backend/src/service/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export enum OIDCTokenProvider {
OKTA = 'okta',
}

export const getMaxRequestSize = (config: Config): string => {
const maxRequestSize = config.getOptionalString('maxRequestSize') ?? '1mb';

return maxRequestSize;
};

export const getResourcesNamespace = (config: Config): string => {
const namespace = config.getString('resourcesNamespace');

Expand Down
8 changes: 5 additions & 3 deletions plugins/cad-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
getClusterLocatorMethodServiceAccountToken,
getClusterLocatorMethodType,
getGitOpsDeliveryTool,
getMaxRequestSize,
getResourcesNamespace,
OIDCTokenProvider,
} from './config';
Expand Down Expand Up @@ -74,13 +75,11 @@ export async function createRouter({
config,
logger,
}: RouterOptions): Promise<express.Router> {
const router = Router();
router.use(express.json());

const cadConfig = config.getConfig('configAsData');

const namespace = getResourcesNamespace(cadConfig);
const gitOpsTool = getGitOpsDeliveryTool(cadConfig);
const maxRequestSize = getMaxRequestSize(cadConfig);

const clusterLocatorMethodType = getClusterLocatorMethodType(cadConfig);
const clusterLocatorMethodAuthProvider =
Expand Down Expand Up @@ -184,6 +183,9 @@ export async function createRouter({
});
};

const router = Router();
router.use(express.json({ limit: maxRequestSize }));

router.get('/health', healthCheck);
router.get('/v1/features', getFeatures);
router.get('/v1/function-catalog', getFunctionCatalog);
Expand Down
5 changes: 5 additions & 0 deletions plugins/cad/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface Config {
*/
gitOpsDeliveryTool: 'none' | 'config-sync';

/**
* Optional. Determines the maximum http request body size.
*/
maxRequestSize?: string;

/**
* Determines where to receive the cluster configuration from.
*/
Expand Down

0 comments on commit 088c268

Please sign in to comment.