Skip to content

Allow server details to be set through configuration in addition to environment variables #1553

@kriswest

Description

@kriswest

Is your feature request related to a problem? Please describe.

The key server settings below are not configurable via the git proxy config file, they a can be set via environment variables and defaults for them are set in source code, rather than in the same place as all other config settings:

const {
GIT_PROXY_SERVER_PORT = 8000,
GIT_PROXY_HTTPS_SERVER_PORT = 8443,
GIT_PROXY_UI_HOST = 'http://localhost',
GIT_PROXY_UI_PORT = 8080,
GIT_PROXY_HTTPS_UI_PORT = 8444,
GIT_PROXY_COOKIE_SECRET,
GIT_PROXY_MONGO_CONNECTION_STRING = 'mongodb://localhost:27017/git-proxy',
} = process.env;

These are likely the oldest settings for git proxy and the difference in how they are configured is a legacy/tech debt. The difference in how they are set is confusing and creates complexity for those running Git Proxy installations for no real benefit.

Describe the solution you'd like

These settings should be added to the config schema and read from the default and user config files for consistency with the rest of the configuration.

GIT_PROXY_COOKIE_SECRET is the one variable that is currently settable from both config file and environment variable and can be used as an example:

see:

cookieSecret:
serverConfig.GIT_PROXY_COOKIE_SECRET ||
userSettings.cookieSecret ||
defaultConfig.cookieSecret,

and:

export const getCookieSecret = (): string => {
const config = loadFullConfiguration();
if (!config.cookieSecret) {
throw new Error('cookieSecret is not set!');
}
return config.cookieSecret;
};

Usage of the config settings will need to shift to using get* functions rather than direct import of the variables from env.ts. I.e. replace:

const { GIT_PROXY_UI_PORT: uiPort, GIT_PROXY_HTTPS_UI_PORT: uiHttpsPort } = serverConfig;

const { GIT_PROXY_SERVER_PORT: proxyHttpPort, GIT_PROXY_HTTPS_SERVER_PORT: proxyHttpsPort } =
serverConfig;

const { GIT_PROXY_SERVER_PORT: PROXY_HTTP_PORT, GIT_PROXY_UI_PORT: UI_PORT } = serverConfig;

We could deprecate the environment variables or maintain support for them with primacy over the config file (as is the case for GIT_PROXY_COOKIE_SECRET.

Describe alternatives you've considered

Continue on with most config going through the config file, but key server settings only being settable via environment variables.

Additional context

Identified as necessary when reviewing #1542, which sought to export the server config and would have locked in this pattern by enabling external use.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions