Search in sources :

Example 51 with AmazonS3Client

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project acs-aem-commons by Adobe-Consulting-Services.

the class S3AssetIngestor method buildProcess.

@Override
public void buildProcess(ProcessInstance instance, ResourceResolver rr) throws LoginException, RepositoryException {
    if (StringUtils.isNotBlank(s3BasePath) && !s3BasePath.endsWith("/")) {
        s3BasePath = s3BasePath + "/";
    }
    instance.getInfo().setDescription(baseItemName + "->" + jcrBasePath);
    instance.defineCriticalAction("Create Folders", rr, this::createFolders);
    instance.defineCriticalAction("Import Assets", rr, this::importAssets);
    s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey));
    if (StringUtils.isNotBlank(endpointUrl)) {
        s3Client.setEndpoint(endpointUrl);
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 52 with AmazonS3Client

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project simplejpa by appoxy.

the class EntityManagerFactoryImpl method createClients.

private void createClients() {
    AWSCredentials awsCredentials = null;
    InputStream credentialsFile = getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties");
    if (credentialsFile != null) {
        logger.info("Loading credentials from AwsCredentials.properties");
        try {
            awsCredentials = new PropertiesCredentials(credentialsFile);
        } catch (IOException e) {
            throw new PersistenceException("Failed loading credentials from AwsCredentials.properties.", e);
        }
    } else {
        logger.info("Loading credentials from simplejpa.properties");
        String awsAccessKey = (String) this.props.get(AWSACCESS_KEY_PROP_NAME);
        String awsSecretKey = (String) this.props.get(AWSSECRET_KEY_PROP_NAME);
        if (awsAccessKey == null || awsAccessKey.length() == 0) {
            throw new PersistenceException("AWS Access Key not found. It is a required property.");
        }
        if (awsSecretKey == null || awsSecretKey.length() == 0) {
            throw new PersistenceException("AWS Secret Key not found. It is a required property.");
        }
        awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    }
    this.simpleDbClient = new AmazonSimpleDBClient(awsCredentials, createConfiguration(sdbSecure));
    this.simpleDbClient.setEndpoint(sdbEndpoint);
    this.s3Client = new AmazonS3Client(awsCredentials, createConfiguration(s3Secure));
    this.s3Client.setEndpoint(s3Endpoint);
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) InputStream(java.io.InputStream) PersistenceException(javax.persistence.PersistenceException) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 53 with AmazonS3Client

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project archaius by Netflix.

the class S3ConfigurationSourceTest method setup.

@Before
public void setup() throws Exception {
    fakeS3 = createHttpServer();
    client = new AmazonS3Client(new StaticCredentialsProvider(new AnonymousAWSCredentials()));
    client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
    client.setEndpoint("http://localhost:8069");
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) S3ClientOptions(com.amazonaws.services.s3.S3ClientOptions) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) Before(org.junit.Before)

Example 54 with AmazonS3Client

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project ice by Netflix.

the class AwsUtils method downloadFileIfChangedSince.

public static boolean downloadFileIfChangedSince(String bucketName, String bucketFilePrefix, File file, long milles, String accountId, String assumeRole, String externalId) {
    AmazonS3Client s3Client = AwsUtils.s3Client;
    try {
        if (!StringUtils.isEmpty(accountId) && !StringUtils.isEmpty(assumeRole)) {
            Credentials assumedCredentials = getAssumedCredentials(accountId, assumeRole, externalId);
            s3Client = new AmazonS3Client(new BasicSessionCredentials(assumedCredentials.getAccessKeyId(), assumedCredentials.getSecretAccessKey(), assumedCredentials.getSessionToken()), clientConfig);
        }
        ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, bucketFilePrefix + file.getName());
        boolean download = !file.exists() || metadata.getLastModified().getTime() > milles;
        if (download) {
            return download(s3Client, bucketName, bucketFilePrefix + file.getName(), file);
        } else
            return download;
    } finally {
        if (s3Client != AwsUtils.s3Client)
            s3Client.shutdown();
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) Credentials(com.amazonaws.services.securitytoken.model.Credentials)

Example 55 with AmazonS3Client

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3Client in project ice by Netflix.

the class AwsUtils method init.

/**
     * This method must be called before all methods can be used.
     * @param credentialsProvider
     */
public static void init(AWSCredentialsProvider credentialsProvider) {
    awsCredentialsProvider = credentialsProvider;
    clientConfig = new ClientConfiguration();
    String proxyHost = System.getProperty("https.proxyHost");
    String proxyPort = System.getProperty("https.proxyPort");
    if (proxyHost != null && proxyPort != null) {
        clientConfig.setProxyHost(proxyHost);
        clientConfig.setProxyPort(Integer.parseInt(proxyPort));
    }
    s3Client = new AmazonS3Client(awsCredentialsProvider, clientConfig);
    securityClient = new AWSSecurityTokenServiceClient(awsCredentialsProvider, clientConfig);
    if (System.getProperty("EC2_REGION") != null && !"us-east-1".equals(System.getProperty("EC2_REGION"))) {
        if ("global".equals(System.getProperty("EC2_REGION"))) {
            s3Client.setEndpoint("s3.amazonaws.com");
        } else {
            s3Client.setEndpoint("s3-" + System.getProperty("EC2_REGION") + ".amazonaws.com");
        }
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AWSSecurityTokenServiceClient(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient) ClientConfiguration(com.amazonaws.ClientConfiguration)

Aggregations

AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)107 Test (org.junit.Test)23 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)20 AmazonClientException (com.amazonaws.AmazonClientException)16 ClientConfiguration (com.amazonaws.ClientConfiguration)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 AmazonS3 (com.amazonaws.services.s3.AmazonS3)12 File (java.io.File)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)11 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)11 AWSCredentials (com.amazonaws.auth.AWSCredentials)10 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)10 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)10 AmazonServiceException (com.amazonaws.AmazonServiceException)9 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)9 InternalEvent (com.nextdoor.bender.InternalEvent)9 TestContext (com.nextdoor.bender.aws.TestContext)9 IOException (java.io.IOException)9