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