Search in sources :

Example 1 with EnvironmentVariableCredentialsProvider

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;
}
Also used : EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) S3xLoginHelper(org.apache.hadoop.fs.s3native.S3xLoginHelper) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 2 with EnvironmentVariableCredentialsProvider

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;
}
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)

Aggregations

EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)1 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 CredentialProvider (org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants.CredentialProvider)1 S3xLoginHelper (org.apache.hadoop.fs.s3native.S3xLoginHelper)1