Package br.com.ingenieux.cloudy.awseb.di

Source Code of br.com.ingenieux.cloudy.awseb.di.BeanstalkerCredentialsProviderChain

package br.com.ingenieux.cloudy.awseb.di;


import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;

/**
* <p>
* Elastic Beanstalk Propagates the AWS Credentials in a Way that is not
* supported by the AWS SDK
* </p>
*
* <p>
* We also love having aws.properties for local usage.
* </p>
*
* <p>
* So here's a midterm: Combining AWS Credentials Provider Chain with whatever
* elastic beanstalk needs
* </p>
*
*/
public class BeanstalkerCredentialsProviderChain extends
    AWSCredentialsProviderChain {
  static class ElasticBeanstalkCredentialsProvider implements
      AWSCredentialsProvider {
    @Override
    public AWSCredentials getCredentials() {
      String awsAccessKeyId = System.getProperty("AWS_ACCESS_KEY_ID", "");
      String awsSecretKey = System.getProperty("AWS_SECRET_KEY", "");

      if (awsAccessKeyId.length() > 0 && awsSecretKey.length() > 0)
        return new BasicAWSCredentials(awsAccessKeyId, awsSecretKey);

      throw new AmazonClientException(
          "Unable to load AWS credentials from Java system properties (AWS_ACCESS_KEY_ID and AWS_SECRET_KEY)");
    }

    @Override
    public void refresh() {
    }
  }

  public BeanstalkerCredentialsProviderChain() {
    super(new ElasticBeanstalkCredentialsProvider(),
        new EnvironmentVariableCredentialsProvider(),
        new SystemPropertiesCredentialsProvider(),
        new ClasspathPropertiesFileCredentialsProvider(
            "/aws.properties"),
        new InstanceProfileCredentialsProvider());
  }
}
TOP

Related Classes of br.com.ingenieux.cloudy.awseb.di.BeanstalkerCredentialsProviderChain

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.