List of usage examples for com.amazonaws.auth EnvironmentVariableCredentialsProvider EnvironmentVariableCredentialsProvider
EnvironmentVariableCredentialsProvider
From source file:org.apache.flink.streaming.connectors.kinesis.util.AWSUtil.java
License:Apache License
/** * Return a {@link AWSCredentialsProvider} instance corresponding to the configuration properties. * * @param configProps the configuration properties * @return The corresponding AWS Credentials Provider instance *///from w ww.ja v a2s. co m 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; }
From source file:org.apache.hadoop.fs.s3a.S3AUtils.java
License:Apache License
/** * Create the AWS credentials from the providers and the URI. * @param binding Binding URI, may contain user:pass login details * @param conf filesystem configuration/*from w ww . j a va2s . c o m*/ * @param fsURI fS URI after any login details have been stripped. * @return a credentials provider list * @throws IOException Problems loading the providers (including reading * secrets from credential files). */ public static AWSCredentialProviderList createAWSCredentialProviderSet(URI binding, Configuration conf, URI fsURI) throws IOException { AWSCredentialProviderList credentials = new AWSCredentialProviderList(); Class<?>[] awsClasses; try { awsClasses = conf.getClasses(AWS_CREDENTIALS_PROVIDER); } catch (RuntimeException e) { Throwable c = e.getCause() != null ? e.getCause() : e; throw new IOException("From option " + AWS_CREDENTIALS_PROVIDER + ' ' + c, c); } if (awsClasses.length == 0) { S3xLoginHelper.Login creds = getAWSAccessKeys(binding, conf); credentials.add(new BasicAWSCredentialsProvider(creds.getUser(), creds.getPassword())); credentials.add(new EnvironmentVariableCredentialsProvider()); credentials.add(new InstanceProfileCredentialsProvider()); } else { for (Class<?> aClass : awsClasses) { credentials.add(createAWSCredentialProvider(conf, aClass, fsURI)); } } return credentials; }
From source file:org.apache.storm.kinesis.spout.CredentialsProviderChain.java
License:Apache License
public CredentialsProviderChain() { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(), new ProfileCredentialsProvider()); }
From source file:org.elasticsearch.cloud.aws.AwsEc2Service.java
License:Apache License
public synchronized AmazonEC2 client() { if (client != null) { return client; }/*from ww w .j av a 2 s. co m*/ ClientConfiguration clientConfiguration = new ClientConfiguration(); String protocol = componentSettings.get("protocol", "http").toLowerCase(); if ("http".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTP); } else if ("https".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTPS); } else { throw new ElasticsearchIllegalArgumentException( "No protocol supported [" + protocol + "], can either be [http] or [https]"); } String account = componentSettings.get("access_key", settings.get("cloud.account")); String key = componentSettings.get("secret_key", settings.get("cloud.key")); String proxyHost = componentSettings.get("proxy_host"); if (proxyHost != null) { String portString = componentSettings.get("proxy_port", "80"); Integer proxyPort; try { proxyPort = Integer.parseInt(portString, 10); } catch (NumberFormatException ex) { throw new ElasticsearchIllegalArgumentException( "The configured proxy port value [" + portString + "] is invalid", ex); } clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } AWSCredentialsProvider credentials; if (account == null && key == null) { credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); } else { credentials = new AWSCredentialsProviderChain( new StaticCredentialsProvider(new BasicAWSCredentials(account, key))); } this.client = new AmazonEC2Client(credentials, clientConfiguration); if (componentSettings.get("ec2.endpoint") != null) { String endpoint = componentSettings.get("ec2.endpoint"); logger.debug("using explicit ec2 endpoint [{}]", endpoint); client.setEndpoint(endpoint); } else if (componentSettings.get("region") != null) { String region = componentSettings.get("region").toLowerCase(); String endpoint; if (region.equals("us-east-1") || region.equals("us-east")) { endpoint = "ec2.us-east-1.amazonaws.com"; } else if (region.equals("us-west") || region.equals("us-west-1")) { endpoint = "ec2.us-west-1.amazonaws.com"; } else if (region.equals("us-west-2")) { endpoint = "ec2.us-west-2.amazonaws.com"; } else if (region.equals("ap-southeast") || region.equals("ap-southeast-1")) { endpoint = "ec2.ap-southeast-1.amazonaws.com"; } else if (region.equals("ap-southeast-2")) { endpoint = "ec2.ap-southeast-2.amazonaws.com"; } else if (region.equals("ap-northeast") || region.equals("ap-northeast-1")) { endpoint = "ec2.ap-northeast-1.amazonaws.com"; } else if (region.equals("eu-west") || region.equals("eu-west-1")) { endpoint = "ec2.eu-west-1.amazonaws.com"; } else if (region.equals("sa-east") || region.equals("sa-east-1")) { endpoint = "ec2.sa-east-1.amazonaws.com"; } else { throw new ElasticsearchIllegalArgumentException( "No automatic endpoint could be derived from region [" + region + "]"); } if (endpoint != null) { logger.debug("using ec2 region [{}], with endpoint [{}]", region, endpoint); client.setEndpoint(endpoint); } } return this.client; }
From source file:org.elasticsearch.cloud.aws.AwsS3Service.java
License:Apache License
private synchronized AmazonS3 getClient(String endpoint, String account, String key) { Tuple<String, String> clientDescriptor = new Tuple<String, String>(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { return client; }// www . j av a 2 s . com ClientConfiguration clientConfiguration = new ClientConfiguration(); String protocol = componentSettings.get("protocol", "http").toLowerCase(); if ("http".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTP); } else if ("https".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTPS); } else { throw new ElasticsearchIllegalArgumentException( "No protocol supported [" + protocol + "], can either be [http] or [https]"); } String proxyHost = componentSettings.get("proxy_host"); if (proxyHost != null) { String portString = componentSettings.get("proxy_port", "80"); Integer proxyPort; try { proxyPort = Integer.parseInt(portString, 10); } catch (NumberFormatException ex) { throw new ElasticsearchIllegalArgumentException( "The configured proxy port value [" + portString + "] is invalid", ex); } clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } AWSCredentialsProvider credentials; if (account == null && key == null) { credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); } else { credentials = new AWSCredentialsProviderChain( new StaticCredentialsProvider(new BasicAWSCredentials(account, key))); } client = new AmazonS3Client(credentials, clientConfiguration); if (endpoint != null) { client.setEndpoint(endpoint); } clients.put(clientDescriptor, client); return client; }
From source file:org.elasticsearch.cloud.aws.InternalAwsS3Service.java
License:Apache License
private synchronized AmazonS3 getClient(String endpoint, String protocol, String account, String key, Integer maxRetries) {/*from w w w. java2 s . c om*/ Tuple<String, String> clientDescriptor = new Tuple<String, String>(endpoint, account); AmazonS3Client client = clients.get(clientDescriptor); if (client != null) { return client; } ClientConfiguration clientConfiguration = new ClientConfiguration(); // the response metadata cache is only there for diagnostics purposes, // but can force objects from every response to the old generation. clientConfiguration.setResponseMetadataCacheSize(0); if (protocol == null) { protocol = settings.get("cloud.aws.protocol", "https").toLowerCase(); protocol = settings.get("cloud.aws.s3.protocol", protocol).toLowerCase(); } if ("http".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTP); } else if ("https".equals(protocol)) { clientConfiguration.setProtocol(Protocol.HTTPS); } else { throw new IllegalArgumentException( "No protocol supported [" + protocol + "], can either be [http] or [https]"); } String proxyHost = settings.get("cloud.aws.proxy_host"); proxyHost = settings.get("cloud.aws.s3.proxy_host", proxyHost); if (proxyHost != null) { String portString = settings.get("cloud.aws.proxy_port", "80"); portString = settings.get("cloud.aws.s3.proxy_port", portString); Integer proxyPort; try { proxyPort = Integer.parseInt(portString, 10); } catch (NumberFormatException ex) { throw new IllegalArgumentException( "The configured proxy port value [" + portString + "] is invalid", ex); } clientConfiguration.withProxyHost(proxyHost).setProxyPort(proxyPort); } if (maxRetries != null) { // If not explicitly set, default to 3 with exponential backoff policy clientConfiguration.setMaxErrorRetry(maxRetries); } // #155: we might have 3rd party users using older S3 API version String awsSigner = settings.get("cloud.aws.s3.signer", settings.get("cloud.aws.signer")); if (awsSigner != null) { logger.debug("using AWS API signer [{}]", awsSigner); try { AwsSigner.configureSigner(awsSigner, clientConfiguration); } catch (IllegalArgumentException e) { logger.warn("wrong signer set for [cloud.aws.s3.signer] or [cloud.aws.signer]: [{}]", awsSigner); } } AWSCredentialsProvider credentials; if (account == null && key == null) { credentials = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); } else { credentials = new AWSCredentialsProviderChain( new StaticCredentialsProvider(new BasicAWSCredentials(account, key))); } client = new AmazonS3Client(credentials, clientConfiguration); if (endpoint != null) { client.setEndpoint(endpoint); } clients.put(clientDescriptor, client); return client; }
From source file:org.eluder.logback.ext.aws.core.AwsSupport.java
License:Open Source License
public AWSCredentialsProvider getCredentials(AWSCredentials credentials) { return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new StaticCredentialsProvider(credentials == null ? new NullCredentials() : credentials), new ProfileCredentialsProvider(), new InstanceProfileCredentialsProvider()); }
From source file:org.jooby.internal.aws.CredentialsFactory.java
License:Apache License
private static LinkedList<AWSCredentialsProvider> chain() { LinkedList<AWSCredentialsProvider> chain = new LinkedList<>(); chain.add(new EnvironmentVariableCredentialsProvider()); chain.add(new SystemPropertiesCredentialsProvider()); chain.add(new ProfileCredentialsProvider()); chain.add(new EC2ContainerCredentialsProviderWrapper()); return chain; }
From source file:org.kuali.maven.wagon.auth.MavenAwsCredentialsProviderChain.java
License:Educational Community License
private static AWSCredentialsProvider[] getProviders(Optional<AuthenticationInfo> auth) { List<AWSCredentialsProvider> providers = new ArrayList<AWSCredentialsProvider>(); // System properties always win providers.add(new SystemPropertiesCredentialsProvider()); // Then fall through to environment variables providers.add(new EnvironmentVariableCredentialsProvider()); // Then fall through to settings.xml providers.add(new AuthenticationInfoCredentialsProvider(auth)); // Then fall through to Amazon's EC2 Instance Metadata Service // http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-roles.html // This allows you setup an IAM role, attach that role to an EC2 Instance at launch time, // and thus automatically provide the wagon with the credentials it needs providers.add(new InstanceProfileCredentialsProvider()); return providers.toArray(new AWSCredentialsProvider[providers.size()]); }
From source file:org.lambadaframework.wagon.AuthenticationInfoAWSCredentialsProviderChain.java
License:Apache License
AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) { super(new InstanceProfileCredentialsProvider(), new ProfileCredentialsProvider(), new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider()); }