Search in sources :

Example 56 with AWSCredentialsProvider

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());
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) SystemPropertiesCredentialsProvider(com.amazonaws.auth.SystemPropertiesCredentialsProvider) EnvironmentVariableCredentialsProvider(com.amazonaws.auth.EnvironmentVariableCredentialsProvider) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) EC2ContainerCredentialsProviderWrapper(com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper) Test(org.junit.Test)

Example 57 with AWSCredentialsProvider

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;
}
Also used : ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DruidModule(org.apache.druid.initialization.DruidModule) Provides(com.google.inject.Provides) Module(com.fasterxml.jackson.databind.Module) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) DruidModule(org.apache.druid.initialization.DruidModule) ObjectMapperModule(com.fasterxml.jackson.module.guice.ObjectMapperModule) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 58 with AWSCredentialsProvider

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);
}
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 59 with AWSCredentialsProvider

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

Example 60 with AWSCredentialsProvider

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));
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Aggregations

AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)125 Test (org.junit.Test)75 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)26 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)20 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)19 AWSCredentials (com.amazonaws.auth.AWSCredentials)16 TestRunner (org.apache.nifi.util.TestRunner)15 ClientConfiguration (com.amazonaws.ClientConfiguration)12 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)12 STSAssumeRoleSessionCredentialsProvider (com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider)8 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)7 ClasspathPropertiesFileCredentialsProvider (com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider)7 EnvironmentVariableCredentialsProvider (com.amazonaws.auth.EnvironmentVariableCredentialsProvider)7 SystemPropertiesCredentialsProvider (com.amazonaws.auth.SystemPropertiesCredentialsProvider)7 ArrayList (java.util.ArrayList)7 Properties (java.util.Properties)7 Configuration (org.apache.hadoop.conf.Configuration)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7