Search in sources :

Example 1 with DOT

use of com.amazonaws.services.s3.model.InstructionFileId.DOT in project jackrabbit by apache.

the class Utils method openService.

/**
 * Create AmazonS3Client from properties.
 *
 * @param prop properties to configure @link {@link AmazonS3Client}
 * @return {@link AmazonS3Client}
 */
public static AmazonS3Client openService(final Properties prop) {
    String accessKey = prop.getProperty(S3Constants.ACCESS_KEY);
    String secretKey = prop.getProperty(S3Constants.SECRET_KEY);
    AmazonS3Client s3service = null;
    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {
        LOG.info("Configuring Amazon Client from environment");
        s3service = new AmazonS3Client(getClientConfiguration(prop));
    } else {
        LOG.info("Configuring Amazon Client from property file.");
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3service = new AmazonS3Client(credentials, getClientConfiguration(prop));
    }
    String region = prop.getProperty(S3Constants.S3_REGION);
    String endpoint = null;
    String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
    if ((propEndPoint != null) && !"".equals(propEndPoint)) {
        endpoint = propEndPoint;
    } else {
        if (StringUtils.isNullOrEmpty(region)) {
            com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion();
            if (s3Region != null) {
                region = s3Region.getName();
            } else {
                throw new AmazonClientException("parameter [" + S3Constants.S3_REGION + "] not configured and cannot be derived from environment");
            }
        }
        if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
            endpoint = S3 + DOT + AWSDOTCOM;
        } else if (Region.EU_Ireland.toString().equals(region)) {
            endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
        } else {
            endpoint = S3 + DASH + region + DOT + AWSDOTCOM;
        }
    }
    /*
         * setting endpoint to remove latency of redirection. If endpoint is
         * not set, invocation first goes us standard region, which
         * redirects it to correct location.
         */
    s3service.setEndpoint(endpoint);
    LOG.info("S3 service endpoint [{}] ", endpoint);
    s3service.setS3ClientOptions(getS3ClientOptions(prop));
    return s3service;
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonClientException(com.amazonaws.AmazonClientException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with DOT

use of com.amazonaws.services.s3.model.InstructionFileId.DOT in project jackrabbit-oak by apache.

the class Utils method openService.

/**
 * Create AmazonS3Client from properties.
 *
 * @param prop properties to configure @link {@link AmazonS3Client}
 * @return {@link AmazonS3Client}
 */
public static AmazonS3Client openService(final Properties prop) {
    String accessKey = prop.getProperty(S3Constants.ACCESS_KEY);
    String secretKey = prop.getProperty(S3Constants.SECRET_KEY);
    AmazonS3Client s3service = null;
    if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) {
        LOG.info("Configuring Amazon Client from environment");
        s3service = new AmazonS3Client(getClientConfiguration(prop));
    } else {
        LOG.info("Configuring Amazon Client from property file.");
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        s3service = new AmazonS3Client(credentials, getClientConfiguration(prop));
    }
    String region = prop.getProperty(S3Constants.S3_REGION);
    String endpoint = null;
    String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
    if ((propEndPoint != null) & !"".equals(propEndPoint)) {
        endpoint = propEndPoint;
    } else {
        if (StringUtils.isNullOrEmpty(region)) {
            com.amazonaws.regions.Region s3Region = Regions.getCurrentRegion();
            if (s3Region != null) {
                region = s3Region.getName();
            } else {
                throw new AmazonClientException("parameter [" + S3Constants.S3_REGION + "] not configured and cannot be derived from environment");
            }
        }
        if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
            endpoint = S3 + DOT + AWSDOTCOM;
        } else {
            endpoint = S3 + DOT + region + DOT + AWSDOTCOM;
        }
    }
    /*
         * setting endpoint to remove latency of redirection. If endpoint is
         * not set, invocation first goes us standard region, which
         * redirects it to correct location.
         */
    s3service.setEndpoint(endpoint);
    LOG.info("S3 service endpoint [{}] ", endpoint);
    return s3service;
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonClientException(com.amazonaws.AmazonClientException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 3 with DOT

use of com.amazonaws.services.s3.model.InstructionFileId.DOT in project aws-sdk-android by aws-amplify.

the class S3CryptoModuleBase method putObjectUsingInstructionFile.

/**
 * Puts an encrypted object into S3, and puts an instruction file into S3.
 * Encryption info is stored in the instruction file.
 *
 * @param putObjectRequest
 *            The request object containing all the parameters to upload a
 *            new object to Amazon S3.
 * @return A {@link PutObjectResult} object containing the information
 *         returned by Amazon S3 for the new, created object.
 */
private PutObjectResult putObjectUsingInstructionFile(PutObjectRequest putObjectRequest) {
    final File fileOrig = putObjectRequest.getFile();
    final InputStream isOrig = putObjectRequest.getInputStream();
    final PutObjectRequest putInstFileRequest = putObjectRequest.clone().withFile(null).withInputStream(null);
    putInstFileRequest.setKey(putInstFileRequest.getKey() + DOT + DEFAULT_INSTRUCTION_FILE_SUFFIX);
    // Create instruction
    final ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(putObjectRequest);
    // Wraps the object data with a cipher input stream; note the metadata
    // is mutated as a side effect.
    final PutObjectRequest req = wrapWithCipher(putObjectRequest, cekMaterial);
    // Put the encrypted object into S3
    final PutObjectResult result;
    try {
        result = s3.putObject(req);
    } finally {
        cleanupDataSource(putObjectRequest, fileOrig, isOrig, req.getInputStream(), log);
    }
    // Put the instruction file into S3
    s3.putObject(updateInstructionPutRequest(putInstFileRequest, cekMaterial));
    // Return the result of the encrypted object PUT.
    return result;
}
Also used : PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) LengthCheckInputStream(com.amazonaws.util.LengthCheckInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ReleasableInputStream(com.amazonaws.internal.ReleasableInputStream) ResettableInputStream(com.amazonaws.internal.ResettableInputStream) SdkFilterInputStream(com.amazonaws.internal.SdkFilterInputStream) InputStream(java.io.InputStream) InstructionFile(com.amazonaws.services.s3.model.CryptoStorageMode.InstructionFile) File(java.io.File) AbstractPutObjectRequest(com.amazonaws.services.s3.model.AbstractPutObjectRequest) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 ReleasableInputStream (com.amazonaws.internal.ReleasableInputStream)1 ResettableInputStream (com.amazonaws.internal.ResettableInputStream)1 SdkFilterInputStream (com.amazonaws.internal.SdkFilterInputStream)1 AbstractPutObjectRequest (com.amazonaws.services.s3.model.AbstractPutObjectRequest)1 InstructionFile (com.amazonaws.services.s3.model.CryptoStorageMode.InstructionFile)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)1 LengthCheckInputStream (com.amazonaws.util.LengthCheckInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1