Search in sources :

Example 21 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project ignite by apache.

the class S3CheckpointSpiSelfTest method afterSpiStopped.

/**
     * @throws Exception If error.
     */
@Override
protected void afterSpiStopped() throws Exception {
    AWSCredentials cred = new BasicAWSCredentials(IgniteS3TestSuite.getAccessKey(), IgniteS3TestSuite.getSecretKey());
    AmazonS3 s3 = new AmazonS3Client(cred);
    String bucketName = S3CheckpointSpi.BUCKET_NAME_PREFIX + "unit-test-bucket";
    try {
        ObjectListing list = s3.listObjects(bucketName);
        while (true) {
            for (S3ObjectSummary sum : list.getObjectSummaries()) s3.deleteObject(bucketName, sum.getKey());
            if (list.isTruncated())
                list = s3.listNextBatchOfObjects(list);
            else
                break;
        }
    } catch (AmazonClientException e) {
        throw new IgniteSpiException("Failed to read checkpoint bucket: " + bucketName, e);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 22 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project ignite by apache.

the class S3CheckpointSpiSelfTest method spiConfigure.

/** {@inheritDoc} */
@Override
protected void spiConfigure(S3CheckpointSpi spi) throws Exception {
    AWSCredentials cred = new BasicAWSCredentials(IgniteS3TestSuite.getAccessKey(), IgniteS3TestSuite.getSecretKey());
    spi.setAwsCredentials(cred);
    spi.setBucketNameSuffix("unit-test-bucket");
    super.spiConfigure(spi);
}
Also used : BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 23 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials 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);
    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 24 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project flink by apache.

the class AWSUtil method getCredentialsProvider.

/**
	 * Return a {@link AWSCredentialsProvider} instance corresponding to the configuration properties.
	 *
	 * @param configProps the configuration properties
	 * @return The corresponding AWS Credentials Provider instance
	 */
public static AWSCredentialsProvider getCredentialsProvider(final Properties configProps) {
    CredentialProvider credentialProviderType;
    if (!configProps.containsKey(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER)) {
        if (configProps.containsKey(AWSConfigConstants.AWS_ACCESS_KEY_ID) && configProps.containsKey(AWSConfigConstants.AWS_SECRET_ACCESS_KEY)) {
            // if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
            credentialProviderType = CredentialProvider.BASIC;
        } else {
            // if the credential provider type is not specified, it will default to AUTO
            credentialProviderType = CredentialProvider.AUTO;
        }
    } else {
        credentialProviderType = CredentialProvider.valueOf(configProps.getProperty(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER));
    }
    AWSCredentialsProvider credentialsProvider;
    switch(credentialProviderType) {
        case ENV_VAR:
            credentialsProvider = new EnvironmentVariableCredentialsProvider();
            break;
        case SYS_PROP:
            credentialsProvider = new SystemPropertiesCredentialsProvider();
            break;
        case PROFILE:
            String profileName = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_NAME, null);
            String profileConfigPath = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_PATH, null);
            credentialsProvider = (profileConfigPath == null) ? new ProfileCredentialsProvider(profileName) : new ProfileCredentialsProvider(profileConfigPath, profileName);
            break;
        case BASIC:
            credentialsProvider = new AWSCredentialsProvider() {

                @Override
                public AWSCredentials getCredentials() {
                    return new BasicAWSCredentials(configProps.getProperty(AWSConfigConstants.AWS_ACCESS_KEY_ID), configProps.getProperty(AWSConfigConstants.AWS_SECRET_ACCESS_KEY));
                }

                @Override
                public void refresh() {
                // do nothing
                }
            };
            break;
        default:
        case AUTO:
            credentialsProvider = new DefaultAWSCredentialsProviderChain();
    }
    return credentialsProvider;
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) CredentialProvider(org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.CredentialProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 25 with AWSCredentials

use of com.amazonaws.auth.AWSCredentials in project cas by apereo.

the class DynamoDbServiceRegistryConfiguration method amazonDynamoDbClient.

@RefreshScope
@Bean
public AmazonDynamoDBClient amazonDynamoDbClient() {
    try {
        final DynamoDbServiceRegistryProperties dynamoDbProperties = casProperties.getServiceRegistry().getDynamoDb();
        final ClientConfiguration cfg = new ClientConfiguration();
        cfg.setConnectionTimeout(dynamoDbProperties.getConnectionTimeout());
        cfg.setMaxConnections(dynamoDbProperties.getMaxConnections());
        cfg.setRequestTimeout(dynamoDbProperties.getRequestTimeout());
        cfg.setSocketTimeout(dynamoDbProperties.getSocketTimeout());
        cfg.setUseGzip(dynamoDbProperties.isUseGzip());
        cfg.setUseReaper(dynamoDbProperties.isUseReaper());
        cfg.setUseThrottleRetries(dynamoDbProperties.isUseThrottleRetries());
        cfg.setUseTcpKeepAlive(dynamoDbProperties.isUseTcpKeepAlive());
        cfg.setProtocol(Protocol.valueOf(dynamoDbProperties.getProtocol().toUpperCase()));
        cfg.setClientExecutionTimeout(dynamoDbProperties.getClientExecutionTimeout());
        cfg.setCacheResponseMetadata(dynamoDbProperties.isCacheResponseMetadata());
        if (StringUtils.isNotBlank(dynamoDbProperties.getLocalAddress())) {
            cfg.setLocalAddress(InetAddress.getByName(dynamoDbProperties.getLocalAddress()));
        }
        AWSCredentials credentials = null;
        if (dynamoDbProperties.getCredentialsPropertiesFile() != null) {
            credentials = new PropertiesCredentials(dynamoDbProperties.getCredentialsPropertiesFile().getInputStream());
        } else if (StringUtils.isNotBlank(dynamoDbProperties.getCredentialAccessKey()) && StringUtils.isNotBlank(dynamoDbProperties.getCredentialSecretKey())) {
            credentials = new BasicAWSCredentials(dynamoDbProperties.getCredentialAccessKey(), dynamoDbProperties.getCredentialSecretKey());
        }
        final AmazonDynamoDBClient client;
        if (credentials == null) {
            client = new AmazonDynamoDBClient(cfg);
        } else {
            client = new AmazonDynamoDBClient(credentials, cfg);
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getEndpoint())) {
            client.setEndpoint(dynamoDbProperties.getEndpoint());
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getRegion())) {
            client.setRegion(Region.getRegion(Regions.valueOf(dynamoDbProperties.getRegion())));
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getRegionOverride())) {
            client.setSignerRegionOverride(dynamoDbProperties.getRegionOverride());
        }
        if (StringUtils.isNotBlank(dynamoDbProperties.getServiceNameIntern())) {
            client.setServiceNameIntern(dynamoDbProperties.getServiceNameIntern());
        }
        if (dynamoDbProperties.getTimeOffset() != 0) {
            client.setTimeOffset(dynamoDbProperties.getTimeOffset());
        }
        return client;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : DynamoDbServiceRegistryProperties(org.apereo.cas.configuration.model.support.dynamodb.DynamoDbServiceRegistryProperties) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)40 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)25 ClientConfiguration (com.amazonaws.ClientConfiguration)13 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)12 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)7 File (java.io.File)7 AmazonClientException (com.amazonaws.AmazonClientException)6 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)5 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)4 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)4 IOException (java.io.IOException)4 Instance (com.amazonaws.services.ec2.model.Instance)3 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)3 Region (com.amazonaws.regions.Region)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 RegionRecord (edu.umass.cs.aws.support.RegionRecord)2 AWSCredentialsConfig (io.druid.common.aws.AWSCredentialsConfig)2 Point2D (java.awt.geom.Point2D)2 HashMap (java.util.HashMap)2