Search in sources :

Example 1 with BasicAWSCredentialsProvider

use of org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider in project kylo by Teradata.

the class S3FileSystemProvider method getBasicCredentialsProvider.

/**
 * Gets a basic credentials provider from the specified Hadoop configuration.
 */
@Nonnull
@VisibleForTesting
Optional<AWSCredentialsProvider> getBasicCredentialsProvider(@Nonnull final URI uri, @Nonnull final Configuration conf) {
    // Read credentials from configuration
    String scheme = uri.getScheme();
    final String accessKeyProperty = "fs." + scheme + ".awsAccessKeyId";
    final String accessKey = conf.get(accessKeyProperty);
    final String secretKeyProperty = "fs." + scheme + ".awsSecretAccessKey";
    final String secretKey = conf.get(secretKeyProperty);
    // Return credentials provider
    if (accessKey != null && secretKey != null) {
        return Optional.of(new BasicAWSCredentialsProvider(accessKey, secretKey));
    } else if (secretKey != null) {
        throw new CatalogException("catalog.fs.s3.missingAccessKeyProperty", accessKeyProperty);
    } else if (accessKey != null) {
        throw new CatalogException("catalog.fs.s3.missingSecretAccessKeyProperty", secretKeyProperty);
    } else {
        log.info("AWS Access Key ID and Secret Access Key must be specified by setting the {} and {} properties (respectively).", accessKeyProperty, secretKeyProperty);
        return Optional.empty();
    }
}
Also used : CatalogException(com.thinkbiganalytics.kylo.catalog.CatalogException) BasicAWSCredentialsProvider(org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Nonnull(javax.annotation.Nonnull)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CatalogException (com.thinkbiganalytics.kylo.catalog.CatalogException)1 Nonnull (javax.annotation.Nonnull)1 BasicAWSCredentialsProvider (org.apache.hadoop.fs.s3a.BasicAWSCredentialsProvider)1