Skip to content

Commit 903e443

Browse files
committed
feat: implements config loader to enable remote or external configs
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 38791bd commit 903e443

File tree

14 files changed

+1251
-97
lines changed

14 files changed

+1251
-97
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ dist
117117
# Stores VSCode versions used for testing VSCode extensions
118118
.vscode-test
119119

120+
# Jetbrains
121+
.idea
122+
120123
# yarn v2
121124

122125
.yarn/cache
@@ -212,6 +215,9 @@ dist
212215
# https://nextjs.org/blog/next-9-1#public-directory-support
213216
# public
214217

218+
# git-config-cache
219+
.git-config-cache
220+
215221
# vuepress build output
216222
.vuepress/dist
217223

config.schema.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
"description": "Configuration for customizing git-proxy",
66
"type": "object",
77
"properties": {
8+
"configurationSources": {
9+
"enabled": { "type": "boolean" },
10+
"reloadIntervalSeconds": { "type": "number" },
11+
"merge": { "type": "boolean" },
12+
"sources": {
13+
"type": "array",
14+
"items": {
15+
"type": "object",
16+
"description": "Configuration source"
17+
}
18+
}
19+
},
820
"proxyUrl": { "type": "string" },
921
"cookieSecret": { "type": "string" },
1022
"sessionMaxAgeHours": { "type": "number" },

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"connect-mongo": "^5.1.0",
4848
"cors": "^2.8.5",
4949
"diff2html": "^3.4.33",
50+
"env-paths": "^2.2.1",
5051
"express": "^4.18.2",
5152
"express-http-proxy": "^2.0.0",
5253
"express-rate-limit": "^7.1.5",

packages/git-proxy-cli/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,29 @@ async function logout() {
306306
console.log('Logout: OK');
307307
}
308308

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

proxy.config.json

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,44 @@
22
"proxyUrl": "https://github.com",
33
"cookieSecret": "cookie secret",
44
"sessionMaxAgeHours": 12,
5+
"configurationSources": {
6+
"enabled": false,
7+
"reloadIntervalSeconds": 60,
8+
"merge": false,
9+
"sources": [
10+
{
11+
"type": "file",
12+
"enabled": false,
13+
"path": "./external-config.json"
14+
},
15+
{
16+
"type": "http",
17+
"enabled": false,
18+
"url": "http://config-service/git-proxy-config",
19+
"headers": {},
20+
"auth": {
21+
"type": "bearer",
22+
"token": ""
23+
}
24+
},
25+
{
26+
"type": "git",
27+
"enabled": false,
28+
"repository": "https://git-server.com/project/git-proxy-config",
29+
"branch": "main",
30+
"path": "git-proxy/config.json",
31+
"auth": {
32+
"type": "ssh",
33+
"privateKeyPath": "/path/to/.ssh/id_rsa"
34+
}
35+
}
36+
]
37+
},
538
"tempPassword": {
639
"sendEmail": false,
740
"emailConfig": {}
841
},
9-
"authorisedList": [
10-
{
11-
"project": "finos",
12-
"name": "git-proxy",
13-
"url": "https://github.com/finos/git-proxy.git"
14-
}
15-
],
42+
"authorisedList": [],
1643
"sink": [
1744
{
1845
"type": "fs",

0 commit comments

Comments
 (0)