Search in sources :

Example 6 with SystemPropertiesCredentialsProvider

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

the class AWSUtilTest method testGetCredentialsProviderSystemProperties.

@Test
public void testGetCredentialsProviderSystemProperties() {
    Properties testConfig = new Properties();
    testConfig.setProperty(AWS_CREDENTIALS_PROVIDER, "SYS_PROP");
    AWSCredentialsProvider credentialsProvider = AWSUtil.getCredentialsProvider(testConfig);
    assertTrue(credentialsProvider instanceof SystemPropertiesCredentialsProvider);
}
Also used : SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) Properties(java.util.Properties) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with SystemPropertiesCredentialsProvider

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

the class AWSUtil method getCredentialsProvider.

/**
 * If the provider is ASSUME_ROLE, then the credentials for assuming this role are determined
 * recursively.
 *
 * @param configProps the configuration properties
 * @param configPrefix the prefix of the config properties for this credentials provider, e.g.
 *     aws.credentials.provider for the base credentials provider,
 *     aws.credentials.provider.role.provider for the credentials provider for assuming a role,
 *     and so on.
 */
private static AWSCredentialsProvider getCredentialsProvider(final Properties configProps, final String configPrefix) {
    CredentialProvider credentialProviderType = AWSAsyncSinkUtil.getCredentialProviderType(configProps, configPrefix);
    switch(credentialProviderType) {
        case ENV_VAR:
            return new EnvironmentVariableCredentialsProvider();
        case SYS_PROP:
            return new SystemPropertiesCredentialsProvider();
        case PROFILE:
            String profileName = configProps.getProperty(AWSConfigConstants.profileName(configPrefix), null);
            String profileConfigPath = configProps.getProperty(AWSConfigConstants.profilePath(configPrefix), null);
            return (profileConfigPath == null) ? new ProfileCredentialsProvider(profileName) : new ProfileCredentialsProvider(profileConfigPath, profileName);
        case BASIC:
            return new AWSCredentialsProvider() {

                @Override
                public AWSCredentials getCredentials() {
                    return new BasicAWSCredentials(configProps.getProperty(AWSConfigConstants.accessKeyId(configPrefix)), configProps.getProperty(AWSConfigConstants.secretKey(configPrefix)));
                }

                @Override
                public void refresh() {
                // do nothing
                }
            };
        case ASSUME_ROLE:
            final AWSSecurityTokenService baseCredentials = AWSSecurityTokenServiceClientBuilder.standard().withCredentials(getCredentialsProvider(configProps, AWSConfigConstants.roleCredentialsProvider(configPrefix))).withRegion(configProps.getProperty(AWSConfigConstants.AWS_REGION)).build();
            return new STSAssumeRoleSessionCredentialsProvider.Builder(configProps.getProperty(AWSConfigConstants.roleArn(configPrefix)), configProps.getProperty(AWSConfigConstants.roleSessionName(configPrefix))).withExternalId(configProps.getProperty(AWSConfigConstants.externalId(configPrefix))).withStsClient(baseCredentials).build();
        case WEB_IDENTITY_TOKEN:
            return WebIdentityTokenCredentialsProvider.builder().roleArn(configProps.getProperty(AWSConfigConstants.roleArn(configPrefix), null)).roleSessionName(configProps.getProperty(AWSConfigConstants.roleSessionName(configPrefix), null)).webIdentityTokenFile(configProps.getProperty(AWSConfigConstants.webIdentityTokenFile(configPrefix), null)).build();
        case AUTO:
            return new DefaultAWSCredentialsProviderChain();
        default:
            throw new IllegalArgumentException("Credential provider not supported: " + credentialProviderType);
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) STSAssumeRoleSessionCredentialsProvider(com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) CredentialProvider(org.apache.flink.connector.aws.config.AWSConfigConstants.CredentialProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSSecurityTokenService(com.amazonaws.services.securitytoken.AWSSecurityTokenService) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 8 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider in project beam by apache.

the class AwsModuleTest method testSingletonAWSCredentialsProviderSerializationDeserialization.

@Test
public void testSingletonAWSCredentialsProviderSerializationDeserialization() throws Exception {
    AWSCredentialsProvider credentialsProvider;
    String serializedCredentialsProvider;
    AWSCredentialsProvider deserializedCredentialsProvider;
    credentialsProvider = new DefaultAWSCredentialsProviderChain();
    serializedCredentialsProvider = serialize(credentialsProvider);
    deserializedCredentialsProvider = deserializeCredentialsProvider(serializedCredentialsProvider);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new EnvironmentVariableCredentialsProvider();
    serializedCredentialsProvider = serialize(credentialsProvider);
    deserializedCredentialsProvider = deserializeCredentialsProvider(serializedCredentialsProvider);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new SystemPropertiesCredentialsProvider();
    serializedCredentialsProvider = serialize(credentialsProvider);
    deserializedCredentialsProvider = deserializeCredentialsProvider(serializedCredentialsProvider);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new ProfileCredentialsProvider();
    serializedCredentialsProvider = serialize(credentialsProvider);
    deserializedCredentialsProvider = deserializeCredentialsProvider(serializedCredentialsProvider);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
    credentialsProvider = new EC2ContainerCredentialsProviderWrapper();
    serializedCredentialsProvider = serialize(credentialsProvider);
    deserializedCredentialsProvider = deserializeCredentialsProvider(serializedCredentialsProvider);
    assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) EC2ContainerCredentialsProviderWrapper(com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper) Test(org.junit.Test)

Example 9 with SystemPropertiesCredentialsProvider

use of com.amazonaws.auth.SystemPropertiesCredentialsProvider in project beam by apache.

the class AwsSerializableUtilsTest method testSystemPropertiesCredentialsProviderSerialization.

@Test
public void testSystemPropertiesCredentialsProviderSerialization() {
    AWSCredentialsProvider credentialsProvider = new SystemPropertiesCredentialsProvider();
    String expectedSerializedProvider = "{\"@type\":\"SystemPropertiesCredentialsProvider\"}";
    String serializedProvider = serialize(credentialsProvider);
    assertEquals(expectedSerializedProvider, serializedProvider);
    assertEquals(expectedSerializedProvider, serialize(deserialize(serializedProvider)));
}
Also used : SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Aggregations

SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)9 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)8 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)5 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)5 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)4 Test (org.junit.Test)4 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 EC2ContainerCredentialsProviderWrapper (com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)1 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)1 PropertiesFileCredentialsProvider (com.amazonaws.auth.PropertiesFileCredentialsProvider)1 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)1 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1