use of tech.pegasys.signers.hashicorp.HashicorpException in project signers by ConsenSys.
the class TomlConfigLoader method parse.
public HashicorpKeyConfig parse(final String tableName) {
final TomlParser tomlParser = new TomlParser();
final TomlParseResult tomlResult = tomlParser.getTomlParseResult(fileToParse);
TomlTable tableToParse = tomlResult;
if (tableName != null) {
tableToParse = tomlResult.getTable(tableName);
}
if (tableToParse == null) {
final String error = String.format("Toml table %s is missing", tableName);
throw new HashicorpException(constructErrorMessage(error));
}
final KeyDefinition keyDefinition = loadKeyDefinition(tableToParse);
final ConnectionParameters connectionsParams = loadConnectionParams(tableToParse);
return new HashicorpKeyConfig(connectionsParams, keyDefinition);
}
use of tech.pegasys.signers.hashicorp.HashicorpException 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));
}
use of tech.pegasys.signers.hashicorp.HashicorpException in project signers by ConsenSys.
the class HashicorpSignerFactory method create.
public Signer create(final HashicorpKeyConfig keyConfig) {
try {
final HashicorpConnectionFactory connectionFactory = new HashicorpConnectionFactory(vertx);
final HashicorpConnection connection = connectionFactory.create(keyConfig.getConnectionParams());
final String secret = connection.fetchKey(keyConfig.getKeyDefinition());
final Credentials credentials = Credentials.create(secret);
return new CredentialSigner(credentials);
} catch (final HashicorpException e) {
throw new SignerInitializationException("Failed to extract secret from Hashicorp vault.", e);
}
}
Aggregations