use of com.amazonaws.auth.EnvironmentVariableCredentialsProvider in project hadoop by apache.
the class S3AUtils method createAWSCredentialProviderSet.
/**
* Create the AWS credentials from the providers and the URI.
* @param binding Binding URI, may contain user:pass login details
* @param conf filesystem configuration
* @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(SharedInstanceProfileCredentialsProvider.getInstance());
} else {
for (Class<?> aClass : awsClasses) {
if (aClass == InstanceProfileCredentialsProvider.class) {
LOG.debug("Found {}, but will use {} instead.", aClass.getName(), SharedInstanceProfileCredentialsProvider.class.getName());
aClass = SharedInstanceProfileCredentialsProvider.class;
}
credentials.add(createAWSCredentialProvider(conf, aClass, fsURI));
}
}
return credentials;
}
use of com.amazonaws.auth.EnvironmentVariableCredentialsProvider 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;
}
Aggregations