use of org.jets3t.service.security.AWSCredentials in project hadoop by apache.
the class Jets3tNativeFileSystemStore method initialize.
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
S3Credentials s3Credentials = new S3Credentials();
s3Credentials.initialize(uri, conf);
try {
AWSCredentials awsCredentials = new AWSCredentials(s3Credentials.getAccessKey(), s3Credentials.getSecretAccessKey());
this.s3Service = new RestS3Service(awsCredentials);
} catch (S3ServiceException e) {
handleException(e);
}
multipartEnabled = conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
multipartBlockSize = Math.min(conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024), MAX_PART_SIZE);
multipartCopyBlockSize = Math.min(conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE), MAX_PART_SIZE);
serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm");
bucket = new S3Bucket(uri.getHost());
}
use of org.jets3t.service.security.AWSCredentials in project alluxio by Alluxio.
the class S3UnderFileSystem method createInstance.
/**
* Constructs a new instance of {@link S3UnderFileSystem}.
*
* @param uri the {@link AlluxioURI} for this UFS
* @return the created {@link S3UnderFileSystem} instance
* @throws ServiceException when a connection to S3 could not be created
*/
public static S3UnderFileSystem createInstance(AlluxioURI uri) throws ServiceException {
String bucketName = uri.getHost();
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.S3N_ACCESS_KEY), "Property " + PropertyKey.S3N_ACCESS_KEY + " is required to connect to S3");
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.S3N_SECRET_KEY), "Property " + PropertyKey.S3N_SECRET_KEY + " is required to connect to S3");
AWSCredentials awsCredentials = new AWSCredentials(Configuration.get(PropertyKey.S3N_ACCESS_KEY), Configuration.get(PropertyKey.S3N_SECRET_KEY));
Jets3tProperties props = new Jets3tProperties();
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_HOST)) {
props.setProperty("httpclient.proxy-autodetect", "false");
props.setProperty("httpclient.proxy-host", Configuration.get(PropertyKey.UNDERFS_S3_PROXY_HOST));
props.setProperty("httpclient.proxy-port", Configuration.get(PropertyKey.UNDERFS_S3_PROXY_PORT));
}
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_PROXY_HTTPS_ONLY)) {
props.setProperty("s3service.https-only", Boolean.toString(Configuration.getBoolean(PropertyKey.UNDERFS_S3_PROXY_HTTPS_ONLY)));
}
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_ENDPOINT)) {
props.setProperty("s3service.s3-endpoint", Configuration.get(PropertyKey.UNDERFS_S3_ENDPOINT));
if (Configuration.getBoolean(PropertyKey.UNDERFS_S3_PROXY_HTTPS_ONLY)) {
props.setProperty("s3service.s3-endpoint-https-port", Configuration.get(PropertyKey.UNDERFS_S3_ENDPOINT_HTTPS_PORT));
} else {
props.setProperty("s3service.s3-endpoint-http-port", Configuration.get(PropertyKey.UNDERFS_S3_ENDPOINT_HTTP_PORT));
}
}
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_DISABLE_DNS_BUCKETS)) {
props.setProperty("s3service.disable-dns-buckets", Configuration.get(PropertyKey.UNDERFS_S3_DISABLE_DNS_BUCKETS));
}
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_UPLOAD_THREADS_MAX)) {
props.setProperty("threaded-service.max-thread-count", Configuration.get(PropertyKey.UNDERFS_S3_UPLOAD_THREADS_MAX));
}
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_ADMIN_THREADS_MAX)) {
props.setProperty("threaded-service.admin-max-thread-count", Configuration.get(PropertyKey.UNDERFS_S3_ADMIN_THREADS_MAX));
}
if (Configuration.containsKey(PropertyKey.UNDERFS_S3_THREADS_MAX)) {
props.setProperty("httpclient.max-connections", Configuration.get(PropertyKey.UNDERFS_S3_THREADS_MAX));
}
LOG.debug("Initializing S3 underFs with properties: {}", props.getProperties());
RestS3Service restS3Service = new RestS3Service(awsCredentials, null, null, props);
String accountOwnerId = restS3Service.getAccountOwner().getId();
// Gets the owner from user-defined static mapping from S3 canonical user id to Alluxio
// user name.
String owner = CommonUtils.getValueFromStaticMapping(Configuration.get(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING), accountOwnerId);
// If there is no user-defined mapping, use the display name.
if (owner == null) {
owner = restS3Service.getAccountOwner().getDisplayName();
}
String accountOwner = owner == null ? accountOwnerId : owner;
AccessControlList acl = restS3Service.getBucketAcl(bucketName);
short bucketMode = S3Utils.translateBucketAcl(acl, accountOwnerId);
return new S3UnderFileSystem(uri, restS3Service, bucketName, bucketMode, accountOwner);
}
Aggregations