@@ -7,7 +7,8 @@ const util = require('util');
77
88const 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
1213const 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
310334yargs ( 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 ;
0 commit comments