Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,10 @@ yarn-error.log*

# Docusaurus website
website/build
website/.docusaurus
website/.docusaurus

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

# Jetbrains IDE
.idea
14 changes: 13 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"description": "API Rate limiting configuration.",
"type": "object",
"properties": {
"windowMs": {
"windowMs": {
"type": "number",
"description": "How long to remember requests for, in milliseconds (default 10 mins)."
},
Expand Down Expand Up @@ -112,6 +112,18 @@
"cert": { "type": "string" }
},
"required": ["enabled", "key", "cert"]
},
"configurationSources": {
"enabled": { "type": "boolean" },
"reloadIntervalSeconds": { "type": "number" },
"merge": { "type": "boolean" },
"sources": {
"type": "array",
"items": {
"type": "object",
"description": "Configuration source"
}
}
}
},
"definitions": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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
31 changes: 30 additions & 1 deletion packages/git-proxy-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const util = require('util');

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

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

Expand Down Expand Up @@ -306,6 +307,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 +460,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;
35 changes: 34 additions & 1 deletion proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,47 @@
}
]
},
"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"
}
}
]
},
"domains": {},
"privateOrganizations": [],
"urlShortener": "",
"contactEmail": "",
"csrfProtection": true,
"plugins": [],
"tls": {
"enabled": true,
"enabled": false,
"key": "certs/key.pem",
"cert": "certs/cert.pem"
}
Expand Down
Loading
Loading