Skip to content

Commit 551b01d

Browse files
committed
refactor: add limits for some features
1 parent 6a02542 commit 551b01d

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

services/api/src/resources/routes/helpers.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Pool } from 'mariadb';
22
import { query } from '../../util/db';
33
import { Sql } from './sql';
44

5-
import { logger } from '../../loggers/logger';
6-
75
export const Helpers = (sqlClientPool: Pool) => {
86
const removeAllRoutesFromEnvironment = async (environmentId: number) => {
97
await query(
@@ -46,6 +44,12 @@ export const Helpers = (sqlClientPool: Pool) => {
4644
if (exists) {
4745
throw new Error(`Annotation already exists on route`);
4846
} else {
47+
const combinedAnnotationCount = exists.length + 1
48+
// arbitrary limit of 10 annotations, maybe this should be less?
49+
// would prefer that annotations done this way weren't a thing, but here we are
50+
if (combinedAnnotationCount >= 10) {
51+
throw Error(`Limit of 10 annotations per route`)
52+
}
4953
await query(
5054
sqlClientPool,
5155
Sql.insertRouteAnnotation({routeId, key, value})
@@ -61,6 +65,12 @@ export const Helpers = (sqlClientPool: Pool) => {
6165
if (exists) {
6266
throw new Error(`Annotation already exists on route`);
6367
}
68+
const combinedAnnotationCount = exists.length + annotations.length
69+
// arbitrary limit of 10 annotations, maybe this should be less?
70+
// would prefer that annotations done this way weren't a thing, but here we are
71+
if (combinedAnnotationCount >= 10) {
72+
throw Error(`Limit of 10 annotations per route`)
73+
}
6474
}
6575
for(const annotation of annotations) {
6676
await query(
@@ -102,7 +112,10 @@ export function addServicePathRoute(
102112
const exists = pathRoutes.some(
103113
(a) => a.toService === newToService && a.path === newPath
104114
);
105-
115+
const combinedPathRoutesCount = pathRoutes.length + 1
116+
if (combinedPathRoutesCount >= 10) {
117+
throw Error(`Limit of 10 path rotues, consider removing some from this route`)
118+
}
106119
if (!exists) {
107120
return [...pathRoutes, { toService: newToService, path: newPath }];
108121
}

services/api/src/resources/routes/resolvers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,10 @@ export const addRouteAlternativeDomains: ResolverFn = async (
677677
if (!isDNS1123Subdomain(d)) {
678678
throw Error(`'${d}' is not a valid domain`)
679679
}
680+
const combinedAltDomainCount = exists2.length + alternativeNames.length
681+
if (combinedAltDomainCount >= 25) {
682+
throw Error(`Limit of 25 alternative domains, consider removing some from this route, or create a new route`)
683+
}
680684
}
681685
}
682686

0 commit comments

Comments
 (0)