Search in sources :

Example 1 with TomlInvalidTypeException

use of org.apache.tuweni.toml.TomlInvalidTypeException in project signers by ConsenSys.

the class SigningMetadataTomlConfigLoader method getMetadataInfo.

private Optional<SigningMetadataFile> getMetadataInfo(final Path file) {
    final String filename = file.getFileName().toString();
    try {
        final TomlParseResult result = TomlConfigFileParser.loadConfigurationFromFile(file.toAbsolutePath().toString());
        final Optional<TomlTableAdapter> signingTable = getSigningTableFrom(file.getFileName().toString(), result);
        if (signingTable.isEmpty()) {
            return Optional.empty();
        }
        final String type = signingTable.get().getString("type");
        if (SignerType.fromString(type).equals(SignerType.FILE_BASED_SIGNER)) {
            return getFileBasedSigningMetadataFromToml(filename, result);
        } else if (SignerType.fromString(type).equals(SignerType.AZURE_SIGNER)) {
            return getAzureBasedSigningMetadataFromToml(file.getFileName().toString(), result);
        } else if (SignerType.fromString(type).equals(SignerType.HASHICORP_SIGNER)) {
            return getHashicorpMetadataFromToml(file, result);
        } else if (SignerType.fromString(type).equals(SignerType.RAW_SIGNER)) {
            return getRawMetadataFromToml(filename, result);
        } else {
            LOG.error("Unknown signing type in metadata: " + type);
            return Optional.empty();
        }
    } catch (final IllegalArgumentException | TomlInvalidTypeException e) {
        final String errorMsg = String.format("%s failed to decode: %s", filename, e.getMessage());
        LOG.error(errorMsg);
        return Optional.empty();
    } catch (final Exception e) {
        LOG.error("Could not load TOML file " + file, e);
        return Optional.empty();
    }
}
Also used : TomlInvalidTypeException(org.apache.tuweni.toml.TomlInvalidTypeException) TomlInvalidTypeException(org.apache.tuweni.toml.TomlInvalidTypeException) IOException(java.io.IOException) TomlParseResult(org.apache.tuweni.toml.TomlParseResult)

Aggregations

IOException (java.io.IOException)1 TomlInvalidTypeException (org.apache.tuweni.toml.TomlInvalidTypeException)1 TomlParseResult (org.apache.tuweni.toml.TomlParseResult)1