Skip to content
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

Make configurable via Environment Vars #3

Open
benbourner opened this issue Sep 1, 2022 · 0 comments
Open

Make configurable via Environment Vars #3

benbourner opened this issue Sep 1, 2022 · 0 comments

Comments

@benbourner
Copy link

Hello, thanks for this project! I wasn't sure how to make a PR, but I solved this for myself and thought I'd quickly share back the code here.

Allowing override of any config file variable with an associated environment variable makes running in a dynamically provisioned container much easier.

This minor adaption will enable override of, e.g. gitea.personal_access_token by setting ${KOODER_GITEA_PERSONAL_ACCESS_TOKEN}

In Configuration.java:

    // allow override of any config vars with environment vars
    private String getEnvironmentVarName(String key) {
        return "KOODER_" + key.replace('.', '_').toUpperCase();
    }

    public String getProperty(String key) {
        // allow override with environment vars
        String value = System.getenv(getEnvironmentVarName(key));
        if(value != null) {
            return value;
        }

        return this.props.getProperty(key);
    }
   [... do the same in each getProperty(...) ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant