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();
}
}
Aggregations