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

dev.sixpack.generator.SupplierConfig Maven / Gradle / Ivy

The newest version!
package dev.sixpack.generator;

import lombok.Data;

import static dev.sixpack.utils.FormatUtils.mFormat;
import static java.lang.System.getenv;

@Data
public class SupplierConfig {
    public static final String SIXPACK_URL = "SIXPACK_URL";
    public static final String SIXPACK_ACCOUNT = "SIXPACK_ACCOUNT";
    public static final String SIXPACK_CLIENT_CERT_PATH = "SIXPACK_CLIENT_CERT_PATH";
    public static final String SIXPACK_CLIENT_KEY_PATH = "SIXPACK_CLIENT_KEY_PATH";
    public static final String SIXPACK_ENVIRONMENT = "SIXPACK_ENVIRONMENT";
    private String sixpackUrl;
    private String account;
    private String clientCertificatePath;
    private String clientKeyPath;
    private String environment;
    private Generator[] generators;
    private Class[] orchestrators;

    public SupplierConfig(String sixpackUrl,
                          String account,
                          String clientCertificatePath,
                          String clientKeyPath,
                          String environment) {
        this.sixpackUrl = sixpackUrl;
        this.account = account;
        this.clientCertificatePath = clientCertificatePath;
        this.clientKeyPath = clientKeyPath;
        this.environment = environment;
    }

    public static SupplierConfig fromEnv() {
        return new SupplierConfig(
                getenv(SIXPACK_URL),
                getenv(SIXPACK_ACCOUNT),
                getenv(SIXPACK_CLIENT_CERT_PATH),
                getenv(SIXPACK_CLIENT_KEY_PATH),
                getenv(SIXPACK_ENVIRONMENT));
    }

    public void verify() {
        verifyNonNull(sixpackUrl, SIXPACK_URL);
        verifyNonNull(account, SIXPACK_ACCOUNT);
        verifyNonNull(clientCertificatePath, SIXPACK_CLIENT_CERT_PATH);
        verifyNonNull(clientKeyPath, SIXPACK_CLIENT_KEY_PATH);
        verifyNonNull(environment, SIXPACK_ENVIRONMENT);
    }

    private static final String emptyParameterError = "The environment variable {} must be set or the respective setter on your supplier needs to be called before bootstrapping the supplier";

    private void verifyNonNull(String property, String envName) {
        if (property == null) {
            throw new IllegalArgumentException(mFormat(emptyParameterError, envName));
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy