class CredStashHelper {

    @Retryable(maxAttempts = 3, value = CredStashGetCredentialFailedException.class, backoff = @Backoff(delay = 5000, multiplier = 2))
    @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME)
    public String getCredentialFromCredStash(String credStashEncryptionContext, String credentialName) throws CredStashGetCredentialFailedException
    {
        // Get AWS region and table name for the credstash.
        String credStashAwsRegion = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_AWS_REGION_NAME);
        String credStashTableName = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_TABLE_NAME);

        // Log configuration values and input parameters.
        LOGGER.info("credStashAwsRegion={} credStashTableName={} credStashEncryptionContext={} credentialName={}", credStashAwsRegion, credStashTableName,
            credStashEncryptionContext, credentialName);

        // Get the AWS client configuration.
        ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsHelper.getAwsParamsDto());

        // Get the credstash interface for getting a credential from credstash.
        CredStash credstash = credStashFactory.getCredStash(credStashAwsRegion, credStashTableName, clientConfiguration);

        // Try to obtain the credential from credstash.
        String password = null;
        String errorMessage = null;
        try
        {
            // Convert the JSON config file version of the encryption context to a Java Map class.
            @SuppressWarnings("unchecked")
            Map<String, String> credstashEncryptionContextMap = jsonHelper.unmarshallJsonToObject(Map.class, credStashEncryptionContext);
            // Get password value from the credstash.
            password = credstash.getCredential(credentialName, credstashEncryptionContextMap);
        }
        catch (Exception exception)
        {
            LOGGER.error("Caught exception when attempting to get a credential value from CredStash.", exception);
            errorMessage = exception.getMessage();
        }

        // If password value is empty and could not be obtained as credential from the credstash, then throw a CredStashGetCredentialFailedException.
        if (StringUtils.isEmpty(password))
        {
            throw new CredStashGetCredentialFailedException(String.format("Failed to obtain credential from credstash.%s " +
                    "credStashAwsRegion=%s credStashTableName=%s credStashEncryptionContext=%s credentialName=%s",
                StringUtils.isNotBlank(errorMessage) ? " Reason: " + errorMessage : "", credStashAwsRegion, credStashTableName, credStashEncryptionContext,
                credentialName));
        }

        // Return the retrieved password value.
        return password;
    }

}