Search in sources :

Example 1 with AccessControlList

use of org.jets3t.service.acl.AccessControlList 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);
}
Also used : AccessControlList(org.jets3t.service.acl.AccessControlList) Jets3tProperties(org.jets3t.service.Jets3tProperties) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) AWSCredentials(org.jets3t.service.security.AWSCredentials)

Example 2 with AccessControlList

use of org.jets3t.service.acl.AccessControlList in project alluxio by Alluxio.

the class S3UtilsTest method before.

@Before
public void before() throws Exception {
    // Setup owner.
    mUserGrantee = new CanonicalGrantee(ID);
    mUserGrantee.setDisplayName(NAME);
    // Setup the acl.
    mAcl = new AccessControlList();
    mAcl.setOwner(new StorageOwner(ID, NAME));
}
Also used : AccessControlList(org.jets3t.service.acl.AccessControlList) StorageOwner(org.jets3t.service.model.StorageOwner) CanonicalGrantee(org.jets3t.service.acl.CanonicalGrantee) Before(org.junit.Before)

Aggregations

AccessControlList (org.jets3t.service.acl.AccessControlList)2 Jets3tProperties (org.jets3t.service.Jets3tProperties)1 CanonicalGrantee (org.jets3t.service.acl.CanonicalGrantee)1 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)1 StorageOwner (org.jets3t.service.model.StorageOwner)1 AWSCredentials (org.jets3t.service.security.AWSCredentials)1 Before (org.junit.Before)1