Skip to content

feat: implements config loader to enable remote or external configs #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ dist
# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# Jetbrains
.idea

# yarn v2

.yarn/cache
Expand Down Expand Up @@ -212,6 +215,9 @@ dist
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# git-config-cache
.git-config-cache

# vuepress build output
.vuepress/dist

Expand Down
12 changes: 12 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
"description": "Configuration for customizing git-proxy",
"type": "object",
"properties": {
"configurationSources": {
"enabled": { "type": "boolean" },
"reloadIntervalSeconds": { "type": "number" },
"merge": { "type": "boolean" },
"sources": {
"type": "array",
"items": {
"type": "object",
"description": "Configuration source"
}
}
},
"proxyUrl": { "type": "string" },
"cookieSecret": { "type": "string" },
"sessionMaxAgeHours": { "type": "number" },
Expand Down
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import * as fs from 'fs';
import { configFile, setConfigFile, validate } from './src/config/file';
import proxy from './src/proxy';
import * as proxy from './src/proxy';
import service from './src/service';

const argv = yargs(hideBin(process.argv))
Expand All @@ -28,7 +28,7 @@ const argv = yargs(hideBin(process.argv))
.strict()
.parseSync();

setConfigFile(argv.c as string || "");
setConfigFile((argv.c as string) || '');

if (argv.v) {
if (!fs.existsSync(configFile)) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"connect-mongo": "^5.1.0",
"cors": "^2.8.5",
"diff2html": "^3.4.33",
"env-paths": "^2.2.1",
"express": "^4.18.2",
"express-http-proxy": "^2.0.0",
"express-rate-limit": "^7.1.5",
Expand Down
28 changes: 28 additions & 0 deletions packages/git-proxy-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ async function logout() {
console.log('Logout: OK');
}

/**
* Reloads the GitProxy configuration without restarting the process
*/
async function reloadConfig() {
if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) {
console.error('Error: Reload config: Authentication required');
process.exitCode = 1;
return;
}

try {
const cookies = JSON.parse(fs.readFileSync(GIT_PROXY_COOKIE_FILE, 'utf8'));

await axios.post(`${baseUrl}/api/v1/admin/reload-config`, {}, { headers: { Cookie: cookies } });

console.log('Configuration reloaded successfully');
} catch (error) {
const errorMessage = `Error: Reload config: '${error.message}'`;
process.exitCode = 2;
console.error(errorMessage);
}
}

// Parsing command line arguments
yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused-expressions
.command({
Expand Down Expand Up @@ -436,6 +459,11 @@ yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused
rejectGitPush(argv.id);
},
})
.command({
command: 'reload-config',
description: 'Reload GitProxy configuration without restarting',
action: reloadConfig,
})
.demandCommand(1, 'You need at least one command before moving on')
.strict()
.help().argv;
41 changes: 34 additions & 7 deletions proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,44 @@
"proxyUrl": "https://github.com",
"cookieSecret": "cookie secret",
"sessionMaxAgeHours": 12,
"configurationSources": {
"enabled": false,
"reloadIntervalSeconds": 60,
"merge": false,
"sources": [
{
"type": "file",
"enabled": false,
"path": "./external-config.json"
},
{
"type": "http",
"enabled": false,
"url": "http://config-service/git-proxy-config",
"headers": {},
"auth": {
"type": "bearer",
"token": ""
}
},
{
"type": "git",
"enabled": false,
"repository": "https://git-server.com/project/git-proxy-config",
"branch": "main",
"path": "git-proxy/config.json",
"auth": {
"type": "ssh",
"privateKeyPath": "/path/to/.ssh/id_rsa"
}
}
]
},
"tempPassword": {
"sendEmail": false,
"emailConfig": {}
},
"authorisedList": [
{
"project": "finos",
"name": "git-proxy",
"url": "https://github.com/finos/git-proxy.git"
}
],
"authorisedList": [],
"sink": [
{
"type": "fs",
Expand Down
Loading
Loading