use of com.amazonaws.auth.AWSSessionCredentials 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("");
EasyMock.expect(config.getSecretKey()).andReturn("");
File file = folder.newFile();
PrintWriter out = new PrintWriter(file.getAbsolutePath());
out.println("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample");
out.close();
EasyMock.expect(config.getFileSessionCredentials()).andReturn(file.getAbsolutePath()).atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
assertTrue(credentials instanceof AWSSessionCredentials);
AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) credentials;
assertEquals(sessionCredentials.getAWSAccessKeyId(), "accessKeySample");
assertEquals(sessionCredentials.getAWSSecretKey(), "secretKeySample");
assertEquals(sessionCredentials.getSessionToken(), "sessionTokenSample");
// try to create
s3Module.getRestS3Service(provider);
}
use of com.amazonaws.auth.AWSSessionCredentials in project zipkin by openzipkin.
the class ZipkinElasticsearchAwsStorageAutoConfiguration method credentials.
/** By default, get credentials from the {@link DefaultAWSCredentialsProviderChain} */
@Bean
@ConditionalOnMissingBean
AWSCredentials.Provider credentials() {
return new AWSCredentials.Provider() {
AWSCredentialsProvider delegate = new DefaultAWSCredentialsProviderChain();
@Override
public AWSCredentials get() {
com.amazonaws.auth.AWSCredentials result = delegate.getCredentials();
String sessionToken = result instanceof AWSSessionCredentials ? ((AWSSessionCredentials) result).getSessionToken() : null;
return new AWSCredentials(result.getAWSAccessKeyId(), result.getAWSSecretKey(), sessionToken);
}
};
}
use of com.amazonaws.auth.AWSSessionCredentials 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.AWSSessionCredentials in project druid by druid-io.
the class TestFileSessionCredentialsProvider method test.
@Test
public void test() throws IOException {
File file = folder.newFile();
try (BufferedWriter out = Files.newWriter(file, StandardCharsets.UTF_8)) {
out.write("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample\n");
}
FileSessionCredentialsProvider provider = new FileSessionCredentialsProvider(file.getAbsolutePath());
AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) provider.getCredentials();
Assert.assertEquals("sessionTokenSample", sessionCredentials.getSessionToken());
Assert.assertEquals("accessKeySample", sessionCredentials.getAWSAccessKeyId());
Assert.assertEquals("secretKeySample", sessionCredentials.getAWSSecretKey());
}
use of com.amazonaws.auth.AWSSessionCredentials in project SimianArmy by Netflix.
the class AWSClient method getJcloudsComputeService.
/**
* {@inheritDoc}
*/
@Override
public ComputeService getJcloudsComputeService() {
if (jcloudsComputeService == null) {
synchronized (this) {
if (jcloudsComputeService == null) {
AWSCredentials awsCredentials = awsCredentialsProvider.getCredentials();
String username = awsCredentials.getAWSAccessKeyId();
String password = awsCredentials.getAWSSecretKey();
Credentials credentials;
if (awsCredentials instanceof AWSSessionCredentials) {
AWSSessionCredentials awsSessionCredentials = (AWSSessionCredentials) awsCredentials;
credentials = SessionCredentials.builder().accessKeyId(username).secretAccessKey(password).sessionToken(awsSessionCredentials.getSessionToken()).build();
} else {
credentials = new Credentials(username, password);
}
ComputeServiceContext jcloudsContext = ContextBuilder.newBuilder("aws-ec2").credentialsSupplier(Suppliers.ofInstance(credentials)).modules(ImmutableSet.<Module>of(new SLF4JLoggingModule(), new JschSshClientModule())).buildView(ComputeServiceContext.class);
this.jcloudsComputeService = jcloudsContext.getComputeService();
}
}
}
return jcloudsComputeService;
}
Aggregations