All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ml.comet.experiment.env.EnvironmentVariableExtractor Maven / Gradle / Ivy

There is a newer version: 1.1.14
Show newest version
package ml.comet.experiment.env;

import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;

@UtilityClass
public class EnvironmentVariableExtractor {

    private static final String API_KEY = "COMET_API_KEY";
    private static final String PROJECT_NAME = "COMET_PROJECT_NAME";
    private static final String WORKSPACE_NAME = "COMET_WORKSPACE_NAME";

    public String getApiKeyOrThrow() {
        return getEnvVariableOrThrow(API_KEY);
    }

    public String getProjectNameOrThrow() {
        return getEnvVariableOrThrow(PROJECT_NAME);
    }

    public String getWorkspaceNameOrThrow() {
        return getEnvVariableOrThrow(WORKSPACE_NAME);
    }

    private String getEnvVariableOrThrow(String variableName) {
        String res = System.getenv(variableName);
        if (StringUtils.isEmpty(res)) {
            throw new IllegalStateException("No environment variable with name " + variableName);
        }
        return res;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy