Search in sources :

Example 1 with TrustStoreType

use of tech.pegasys.signers.hashicorp.TrustStoreType in project signers by ConsenSys.

the class TomlConfigLoader method loadTlsOptions.

private Optional<TlsOptions> loadTlsOptions(final TomlTable tomlInput) {
    final boolean tlsEnabled = tomlInput.getBoolean(PROP_HASHICORP_TLS_ENABLE, () -> true);
    final String trustStoreString = tomlInput.getString(PROP_HASHICORP_TLS_TS_TYPE);
    final String trustStorePath = tomlInput.getString(PROP_HASHICORP_TLS_TS_PATH);
    final String trustStorePassword = tomlInput.getString(PROP_HASHICORP_TLS_TS_PASSWORD);
    if (!tlsEnabled) {
        return Optional.empty();
    }
    final TrustStoreType trustStoreType = decodeTrustStoreType(trustStoreString);
    if (trustStoreType != null) {
        if (trustStorePath == null) {
            final String error = String.format("%s must be specified if custom trust store (%s) is specified", PROP_HASHICORP_TLS_TS_PATH, PROP_HASHICORP_TLS_TS_TYPE);
            throw new HashicorpException(error);
        }
        if (trustStoreType.isPasswordRequired() && (trustStorePassword == null)) {
            final String error = String.format("%s must be specified if custom trust store (%s) is specified", PROP_HASHICORP_TLS_TS_PASSWORD, trustStoreType.name());
            throw new HashicorpException(constructErrorMessage(error));
        }
    }
    return Optional.of(new TlsOptions(Optional.ofNullable(trustStoreType), trustStorePath == null ? null : Path.of(trustStorePath), trustStorePassword));
}
Also used : HashicorpException(tech.pegasys.signers.hashicorp.HashicorpException) TrustStoreType(tech.pegasys.signers.hashicorp.TrustStoreType) TlsOptions(tech.pegasys.signers.hashicorp.config.TlsOptions)

Aggregations

HashicorpException (tech.pegasys.signers.hashicorp.HashicorpException)1 TrustStoreType (tech.pegasys.signers.hashicorp.TrustStoreType)1 TlsOptions (tech.pegasys.signers.hashicorp.config.TlsOptions)1