Skip to content

Commit cc49057

Browse files
committed
feat: add configurable cache limits via proxy.config.json
1 parent 956f388 commit cc49057

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

config.schema.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,26 @@
198198
}
199199
}
200200
}
201+
},
202+
"cache": {
203+
"description": "Configuration for bare repository cache (hybrid cache system)",
204+
"type": "object",
205+
"properties": {
206+
"maxSizeGB": {
207+
"type": "number",
208+
"description": "Maximum cache size in gigabytes (default 2GB)"
209+
},
210+
"maxRepositories": {
211+
"type": "number",
212+
"description": "Maximum number of repositories in cache (default 50)"
213+
},
214+
"cacheDir": {
215+
"type": "string",
216+
"description": "Directory path for bare repository cache (default ./.remote/cache)"
217+
}
218+
},
219+
"required": ["maxSizeGB", "maxRepositories", "cacheDir"],
220+
"additionalProperties": false
201221
}
202222
},
203223
"definitions": {

proxy.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,10 @@
182182
"loginRequired": true
183183
}
184184
]
185+
},
186+
"cache": {
187+
"maxSizeGB": 2,
188+
"maxRepositories": 50,
189+
"cacheDir": "./.remote/cache"
185190
}
186191
}

src/config/generated/config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export interface GitProxyConfig {
3535
* List of repositories that are authorised to be pushed to through the proxy.
3636
*/
3737
authorisedList?: AuthorisedRepo[];
38+
/**
39+
* Configuration for bare repository cache (hybrid cache system)
40+
*/
41+
cache?: Cache;
3842
/**
3943
* Enforce rules and patterns on commits including e-mail and message
4044
*/
@@ -264,6 +268,24 @@ export interface AuthorisedRepo {
264268
[property: string]: any;
265269
}
266270

271+
/**
272+
* Configuration for bare repository cache (hybrid cache system)
273+
*/
274+
export interface Cache {
275+
/**
276+
* Directory path for bare repository cache (default ./.remote/cache)
277+
*/
278+
cacheDir: string;
279+
/**
280+
* Maximum number of repositories in cache (default 50)
281+
*/
282+
maxRepositories: number;
283+
/**
284+
* Maximum cache size in gigabytes (default 2GB)
285+
*/
286+
maxSizeGB: number;
287+
}
288+
267289
/**
268290
* API Rate limiting configuration.
269291
*/
@@ -530,6 +552,7 @@ const typeMap: any = {
530552
typ: u(undefined, a(r('AuthenticationElement'))),
531553
},
532554
{ json: 'authorisedList', js: 'authorisedList', typ: u(undefined, a(r('AuthorisedRepo'))) },
555+
{ json: 'cache', js: 'cache', typ: u(undefined, r('Cache')) },
533556
{ json: 'commitConfig', js: 'commitConfig', typ: u(undefined, m('any')) },
534557
{ json: 'configurationSources', js: 'configurationSources', typ: u(undefined, 'any') },
535558
{ json: 'contactEmail', js: 'contactEmail', typ: u(undefined, '') },
@@ -617,6 +640,14 @@ const typeMap: any = {
617640
],
618641
'any',
619642
),
643+
Cache: o(
644+
[
645+
{ json: 'cacheDir', js: 'cacheDir', typ: '' },
646+
{ json: 'maxRepositories', js: 'maxRepositories', typ: 3.14 },
647+
{ json: 'maxSizeGB', js: 'maxSizeGB', typ: 3.14 },
648+
],
649+
false,
650+
),
620651
RateLimit: o(
621652
[
622653
{ json: 'limit', js: 'limit', typ: 3.14 },

src/config/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ function mergeConfigurations(
103103
commitConfig: { ...defaultConfig.commitConfig, ...userSettings.commitConfig },
104104
attestationConfig: { ...defaultConfig.attestationConfig, ...userSettings.attestationConfig },
105105
rateLimit: userSettings.rateLimit || defaultConfig.rateLimit,
106+
cache: userSettings.cache
107+
? { ...defaultConfig.cache, ...userSettings.cache }
108+
: defaultConfig.cache,
106109
tls: tlsConfig,
107110
tempPassword: { ...defaultConfig.tempPassword, ...userSettings.tempPassword },
108111
// Preserve legacy SSL fields
@@ -196,6 +199,7 @@ export const logConfiguration = () => {
196199
console.log(`data sink = ${JSON.stringify(getDatabase())}`);
197200
console.log(`authentication = ${JSON.stringify(getAuthMethods())}`);
198201
console.log(`rateLimit = ${JSON.stringify(getRateLimit())}`);
202+
console.log(`cache = ${JSON.stringify(getCacheConfig())}`);
199203
};
200204

201205
export const getAPIs = () => {
@@ -285,6 +289,17 @@ export const getRateLimit = () => {
285289
return config.rateLimit;
286290
};
287291

292+
export const getCacheConfig = () => {
293+
const config = loadFullConfiguration();
294+
return (
295+
config.cache || {
296+
maxSizeGB: 2,
297+
maxRepositories: 50,
298+
cacheDir: './.remote/cache',
299+
}
300+
);
301+
};
302+
288303
// Function to handle configuration updates
289304
const handleConfigUpdate = async (newConfig: Configuration) => {
290305
console.log('Configuration updated from external source');

src/config/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface UserSettings {
2323
csrfProtection: boolean;
2424
domains: Record<string, unknown>;
2525
rateLimit: RateLimitConfig;
26+
cache: CacheConfig;
2627
}
2728

2829
export interface TLSConfig {
@@ -59,3 +60,9 @@ export interface TempPasswordConfig {
5960
export type RateLimitConfig = Partial<
6061
Pick<RateLimitOptions, 'windowMs' | 'limit' | 'message' | 'statusCode'>
6162
>;
63+
64+
export interface CacheConfig {
65+
maxSizeGB: number;
66+
maxRepositories: number;
67+
cacheDir: string;
68+
}

0 commit comments

Comments
 (0)