Search in sources :

Example 1 with AWSCredentialsConfig

use of io.druid.common.aws.AWSCredentialsConfig 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 AWSCredentialsConfig

use of io.druid.common.aws.AWSCredentialsConfig 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("accessKeySample").atLeastOnce();
    EasyMock.expect(config.getSecretKey()).andReturn("secretKeySample").atLeastOnce();
    EasyMock.replay(config);
    AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
    AWSCredentials credentials = provider.getCredentials();
    assertEquals(credentials.getAWSAccessKeyId(), "accessKeySample");
    assertEquals(credentials.getAWSSecretKey(), "secretKeySample");
    // try to create
    s3Module.getRestS3Service(provider);
}
Also used : AWSCredentialsConfig(io.druid.common.aws.AWSCredentialsConfig) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Aggregations

AWSCredentials (com.amazonaws.auth.AWSCredentials)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 AWSCredentialsConfig (io.druid.common.aws.AWSCredentialsConfig)2 Test (org.junit.Test)2 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1