use of com.amazonaws.auth.AWSCredentialsProvider 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 = objectMapper.writeValueAsString(credentialsProvider);
deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
credentialsProvider = new EnvironmentVariableCredentialsProvider();
serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
credentialsProvider = new SystemPropertiesCredentialsProvider();
serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
credentialsProvider = new ProfileCredentialsProvider();
serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
credentialsProvider = new EC2ContainerCredentialsProviderWrapper();
serializedCredentialsProvider = objectMapper.writeValueAsString(credentialsProvider);
deserializedCredentialsProvider = objectMapper.readValue(serializedCredentialsProvider, AWSCredentialsProvider.class);
assertEquals(credentialsProvider.getClass(), deserializedCredentialsProvider.getClass());
}
use of com.amazonaws.auth.AWSCredentialsProvider in project druid by druid-io.
the class S3InputSourceTest method createS3ObjectMapper.
public static ObjectMapper createS3ObjectMapper() {
DruidModule baseModule = new TestS3Module();
final Injector injector = Guice.createInjector(new ObjectMapperModule(), baseModule, new DruidModule() {
@Provides
public AWSCredentialsProvider getAWSCredentialsProvider() {
return AWSCredentialsUtils.defaultAWSCredentialsProviderChain(null);
}
@Override
public List<? extends Module> getJacksonModules() {
return Collections.emptyList();
}
@Override
public void configure(Binder binder) {
}
});
final ObjectMapper baseMapper = injector.getInstance(ObjectMapper.class);
baseModule.getJacksonModules().forEach(baseMapper::registerModule);
return baseMapper;
}
use of com.amazonaws.auth.AWSCredentialsProvider in project druid by druid-io.
the class TestAWSCredentialsProvider method testWithFileSessionCredentials.
@Test
public void testWithFileSessionCredentials() throws IOException {
AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
EasyMock.expect(config.getAccessKey()).andReturn(new DefaultPasswordProvider(""));
EasyMock.expect(config.getSecretKey()).andReturn(new DefaultPasswordProvider(""));
File file = folder.newFile();
try (BufferedWriter out = Files.newWriter(file, StandardCharsets.UTF_8)) {
out.write("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample\n");
}
EasyMock.expect(config.getFileSessionCredentials()).andReturn(file.getAbsolutePath()).atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
Assert.assertTrue(credentials instanceof AWSSessionCredentials);
AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) credentials;
Assert.assertEquals("accessKeySample", sessionCredentials.getAWSAccessKeyId());
Assert.assertEquals("secretKeySample", sessionCredentials.getAWSSecretKey());
Assert.assertEquals("sessionTokenSample", sessionCredentials.getSessionToken());
// try to create
ServerSideEncryptingAmazonS3.Builder amazonS3ClientBuilder = s3Module.getServerSideEncryptingAmazonS3Builder(provider, new AWSProxyConfig(), new AWSEndpointConfig(), new AWSClientConfig(), new S3StorageConfig(new NoopServerSideEncryption()));
s3Module.getAmazonS3Client(amazonS3ClientBuilder);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project druid by druid-io.
the class TestAWSCredentialsProvider method testWithFixedAWSKeys.
@Test
public void testWithFixedAWSKeys() {
AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
EasyMock.expect(config.getAccessKey()).andReturn(new DefaultPasswordProvider("accessKeySample")).atLeastOnce();
EasyMock.expect(config.getSecretKey()).andReturn(new DefaultPasswordProvider("secretKeySample")).atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
Assert.assertEquals("accessKeySample", credentials.getAWSAccessKeyId());
Assert.assertEquals("secretKeySample", credentials.getAWSSecretKey());
// try to create
ServerSideEncryptingAmazonS3.Builder amazonS3ClientBuilder = s3Module.getServerSideEncryptingAmazonS3Builder(provider, new AWSProxyConfig(), new AWSEndpointConfig(), new AWSClientConfig(), new S3StorageConfig(new NoopServerSideEncryption()));
s3Module.getAmazonS3Client(amazonS3ClientBuilder);
}
use of com.amazonaws.auth.AWSCredentialsProvider in project crate by crate.
the class AwsS3ServiceImplTests method testSetDefaultCredential.
@Test
public void testSetDefaultCredential() {
final String awsAccessKey = randomAlphaOfLength(8);
final String awsSecretKey = randomAlphaOfLength(8);
final Settings settings = Settings.builder().put("access_key", awsAccessKey).put("secret_key", awsSecretKey).build();
final S3ClientSettings clientSettings = S3ClientSettings.getClientSettings(settings);
// test default exists and is an Instance provider
final AWSCredentialsProvider defaultCredentialsProvider = S3Service.buildCredentials(logger, clientSettings);
assertThat(defaultCredentialsProvider, instanceOf(AWSStaticCredentialsProvider.class));
assertThat(defaultCredentialsProvider.getCredentials().getAWSAccessKeyId(), is(awsAccessKey));
assertThat(defaultCredentialsProvider.getCredentials().getAWSSecretKey(), is(awsSecretKey));
}
Aggregations