Search in sources :

Example 1 with AWSSessionCredentials

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);
}
Also used : AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSCredentialsConfig(io.druid.common.aws.AWSCredentialsConfig) File(java.io.File) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with AWSSessionCredentials

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);
        }
    };
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with AWSSessionCredentials

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);
}
Also used : AWSClientConfig(org.apache.druid.common.aws.AWSClientConfig) AWSCredentialsConfig(org.apache.druid.common.aws.AWSCredentialsConfig) AWSCredentials(com.amazonaws.auth.AWSCredentials) BufferedWriter(java.io.BufferedWriter) AWSEndpointConfig(org.apache.druid.common.aws.AWSEndpointConfig) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSProxyConfig(org.apache.druid.common.aws.AWSProxyConfig) DefaultPasswordProvider(org.apache.druid.metadata.DefaultPasswordProvider) File(java.io.File) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 4 with AWSSessionCredentials

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());
}
Also used : FileSessionCredentialsProvider(org.apache.druid.common.aws.FileSessionCredentialsProvider) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 5 with AWSSessionCredentials

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;
}
Also used : SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) JschSshClientModule(org.jclouds.ssh.jsch.config.JschSshClientModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Module(com.google.inject.Module) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) JschSshClientModule(org.jclouds.ssh.jsch.config.JschSshClientModule) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Credentials(org.jclouds.domain.Credentials) SessionCredentials(org.jclouds.aws.domain.SessionCredentials) LoginCredentials(org.jclouds.domain.LoginCredentials)

Aggregations

AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)11 AWSCredentials (com.amazonaws.auth.AWSCredentials)5 File (java.io.File)4 Test (org.junit.Test)4 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)3 IOException (java.io.IOException)3 SessionCredentials (org.jclouds.aws.domain.SessionCredentials)3 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)2 BufferedWriter (java.io.BufferedWriter)2 PrintWriter (java.io.PrintWriter)2 Credentials (org.jclouds.domain.Credentials)2 Supplier (shaded.com.google.common.base.Supplier)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeReservedInstancesResult (com.amazonaws.services.ec2.model.DescribeReservedInstancesResult)1 ReservedInstances (com.amazonaws.services.ec2.model.ReservedInstances)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 Module (com.google.inject.Module)1 Account (com.netflix.ice.tag.Account)1