Skip to content

Commit e820169

Browse files
committed
feat: implements config loader to enable remote or external configs
feat: converted to typescript fix: config loader clone command issue fix: adds input validation, uses array arguments, prevented shell spawn fix: adds failsafe checking for directory location and structure fix: env-paths change to v2.2.1 which support require and minor code fix fix: improves test coverage Adds additional tests for better cove fix: fixed creating cache directory
1 parent e6d7446 commit e820169

File tree

14 files changed

+1293
-51
lines changed

14 files changed

+1293
-51
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,10 @@ yarn-error.log*
263263

264264
# Docusaurus website
265265
website/build
266-
website/.docusaurus
266+
website/.docusaurus
267+
268+
# git-config-cache
269+
.git-config-cache
270+
271+
# Jetbrains IDE
272+
.idea

config.schema.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"description": "API Rate limiting configuration.",
2929
"type": "object",
3030
"properties": {
31-
"windowMs": {
31+
"windowMs": {
3232
"type": "number",
3333
"description": "How long to remember requests for, in milliseconds (default 10 mins)."
3434
},
@@ -112,6 +112,18 @@
112112
"cert": { "type": "string" }
113113
},
114114
"required": ["enabled", "key", "cert"]
115+
},
116+
"configurationSources": {
117+
"enabled": { "type": "boolean" },
118+
"reloadIntervalSeconds": { "type": "number" },
119+
"merge": { "type": "boolean" },
120+
"sources": {
121+
"type": "array",
122+
"items": {
123+
"type": "object",
124+
"description": "Configuration source"
125+
}
126+
}
115127
}
116128
},
117129
"definitions": {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"connect-mongo": "^5.1.0",
5151
"cors": "^2.8.5",
5252
"diff2html": "^3.4.33",
53+
"env-paths": "^2.2.1",
5354
"express": "^4.18.2",
5455
"express-http-proxy": "^2.0.0",
5556
"express-rate-limit": "^7.1.5",

packages/git-proxy-cli/index.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const util = require('util');
77

88
const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie';
99
// GitProxy UI HOST and PORT (configurable via environment variable)
10-
const { GIT_PROXY_UI_HOST: uiHost = 'http://localhost', GIT_PROXY_UI_PORT: uiPort = 8080 } = process.env;
10+
const { GIT_PROXY_UI_HOST: uiHost = 'http://localhost', GIT_PROXY_UI_PORT: uiPort = 8080 } =
11+
process.env;
1112

1213
const baseUrl = `${uiHost}:${uiPort}`;
1314

@@ -306,6 +307,29 @@ async function logout() {
306307
console.log('Logout: OK');
307308
}
308309

310+
/**
311+
* Reloads the GitProxy configuration without restarting the process
312+
*/
313+
async function reloadConfig() {
314+
if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) {
315+
console.error('Error: Reload config: Authentication required');
316+
process.exitCode = 1;
317+
return;
318+
}
319+
320+
try {
321+
const cookies = JSON.parse(fs.readFileSync(GIT_PROXY_COOKIE_FILE, 'utf8'));
322+
323+
await axios.post(`${baseUrl}/api/v1/admin/reload-config`, {}, { headers: { Cookie: cookies } });
324+
325+
console.log('Configuration reloaded successfully');
326+
} catch (error) {
327+
const errorMessage = `Error: Reload config: '${error.message}'`;
328+
process.exitCode = 2;
329+
console.error(errorMessage);
330+
}
331+
}
332+
309333
// Parsing command line arguments
310334
yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused-expressions
311335
.command({
@@ -436,6 +460,11 @@ yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused
436460
rejectGitPush(argv.id);
437461
},
438462
})
463+
.command({
464+
command: 'reload-config',
465+
description: 'Reload GitProxy configuration without restarting',
466+
action: reloadConfig,
467+
})
439468
.demandCommand(1, 'You need at least one command before moving on')
440469
.strict()
441470
.help().argv;

proxy.config.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,39 @@
9696
}
9797
]
9898
},
99+
"configurationSources": {
100+
"enabled": false,
101+
"reloadIntervalSeconds": 60,
102+
"merge": false,
103+
"sources": [
104+
{
105+
"type": "file",
106+
"enabled": false,
107+
"path": "./external-config.json"
108+
},
109+
{
110+
"type": "http",
111+
"enabled": false,
112+
"url": "http://config-service/git-proxy-config",
113+
"headers": {},
114+
"auth": {
115+
"type": "bearer",
116+
"token": ""
117+
}
118+
},
119+
{
120+
"type": "git",
121+
"enabled": false,
122+
"repository": "https://git-server.com/project/git-proxy-config",
123+
"branch": "main",
124+
"path": "git-proxy/config.json",
125+
"auth": {
126+
"type": "ssh",
127+
"privateKeyPath": "/path/to/.ssh/id_rsa"
128+
}
129+
}
130+
]
131+
},
99132
"domains": {},
100133
"privateOrganizations": [],
101134
"urlShortener": "",

0 commit comments

Comments
 (0)