Search in sources :

Example 61 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project zeppelin by apache.

the class S3NotebookRepo method init.

public void init(ZeppelinConfiguration conf) throws IOException {
    this.conf = conf;
    bucketName = conf.getS3BucketName();
    user = conf.getS3User();
    rootFolder = user + "/notebook";
    useServerSideEncryption = conf.isS3ServerSideEncryption();
    if (StringUtils.isNotBlank(conf.getS3CannedAcl())) {
        objectCannedAcl = CannedAccessControlList.valueOf(conf.getS3CannedAcl());
    }
    // always use the default provider chain
    AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
    CryptoConfiguration cryptoConf = new CryptoConfiguration();
    String keyRegion = conf.getS3KMSKeyRegion();
    if (StringUtils.isNotBlank(keyRegion)) {
        cryptoConf.setAwsKmsRegion(Region.getRegion(Regions.fromName(keyRegion)));
    }
    ClientConfiguration cliConf = createClientConfiguration();
    // see if we should be encrypting data in S3
    String kmsKeyID = conf.getS3KMSKeyID();
    if (kmsKeyID != null) {
        // use the AWS KMS to encrypt data
        KMSEncryptionMaterialsProvider emp = new KMSEncryptionMaterialsProvider(kmsKeyID);
        this.s3client = new AmazonS3EncryptionClient(credentialsProvider, emp, cliConf, cryptoConf);
    } else if (conf.getS3EncryptionMaterialsProviderClass() != null) {
        // use a custom encryption materials provider class
        EncryptionMaterialsProvider emp = createCustomProvider(conf);
        this.s3client = new AmazonS3EncryptionClient(credentialsProvider, emp, cliConf, cryptoConf);
    } else {
        // regular S3
        this.s3client = new AmazonS3Client(credentialsProvider, cliConf);
    }
    s3client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(conf.isS3PathStyleAccess()).build());
    // set S3 endpoint to use
    s3client.setEndpoint(conf.getS3Endpoint());
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonS3EncryptionClient(com.amazonaws.services.s3.AmazonS3EncryptionClient) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) EncryptionMaterialsProvider(com.amazonaws.services.s3.model.EncryptionMaterialsProvider) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) CryptoConfiguration(com.amazonaws.services.s3.model.CryptoConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 62 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project druid by druid-io.

the class AWSRDSTokenPasswordProviderTest method testSerde.

@Test
public void testSerde() throws IOException {
    ObjectMapper jsonMapper = new ObjectMapper();
    for (Module module : new AWSRDSModule().getJacksonModules()) {
        jsonMapper.registerModule(module);
    }
    jsonMapper.setInjectableValues(new InjectableValues.Std().addValue(AWSCredentialsProvider.class, new AWSCredentialsProvider() {

        @Override
        public AWSCredentials getCredentials() {
            return null;
        }

        @Override
        public void refresh() {
        }
    }));
    String jsonStr = "{\n" + "  \"type\": \"aws-rds-token\",\n" + "  \"user\": \"testuser\",\n" + "  \"host\": \"testhost\",\n" + "  \"port\": 5273,\n" + "  \"region\": \"testregion\"\n" + "}\n";
    PasswordProvider pp = jsonMapper.readValue(jsonMapper.writeValueAsString(jsonMapper.readValue(jsonStr, PasswordProvider.class)), PasswordProvider.class);
    AWSRDSTokenPasswordProvider awsPwdProvider = (AWSRDSTokenPasswordProvider) pp;
    Assert.assertEquals("testuser", awsPwdProvider.getUser());
    Assert.assertEquals("testhost", awsPwdProvider.getHost());
    Assert.assertEquals(5273, awsPwdProvider.getPort());
    Assert.assertEquals("testregion", awsPwdProvider.getRegion());
}
Also used : Module(com.fasterxml.jackson.databind.Module) PasswordProvider(org.apache.druid.metadata.PasswordProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 63 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project druid by druid-io.

the class KinesisRecordSupplier method getAmazonKinesisClient.

public static AmazonKinesis getAmazonKinesisClient(String endpoint, AWSCredentialsConfig awsCredentialsConfig, String awsAssumedRoleArn, String awsExternalId) {
    AWSCredentialsProvider awsCredentialsProvider = AWSCredentialsUtils.defaultAWSCredentialsProviderChain(awsCredentialsConfig);
    if (awsAssumedRoleArn != null) {
        log.info("Assuming role [%s] with externalId [%s]", awsAssumedRoleArn, awsExternalId);
        STSAssumeRoleSessionCredentialsProvider.Builder builder = new STSAssumeRoleSessionCredentialsProvider.Builder(awsAssumedRoleArn, StringUtils.format("druid-kinesis-%s", UUID.randomUUID().toString())).withStsClient(AWSSecurityTokenServiceClientBuilder.standard().withCredentials(awsCredentialsProvider).build());
        if (awsExternalId != null) {
            builder.withExternalId(awsExternalId);
        }
        awsCredentialsProvider = builder.build();
    }
    return AmazonKinesisClientBuilder.standard().withCredentials(awsCredentialsProvider).withClientConfiguration(new ClientConfiguration()).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, AwsHostNameUtils.parseRegion(endpoint, null))).build();
}
Also used : STSAssumeRoleSessionCredentialsProvider(com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 64 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("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)

Example 65 with AWSCredentialsProvider

use of com.amazonaws.auth.AWSCredentialsProvider in project elasticsearch by elastic.

the class AwsEc2ServiceImpl method buildCredentials.

protected static AWSCredentialsProvider buildCredentials(Logger logger, Settings settings) {
    AWSCredentialsProvider credentials;
    String key = CLOUD_EC2.KEY_SETTING.get(settings);
    String secret = CLOUD_EC2.SECRET_SETTING.get(settings);
    if (key.isEmpty() && secret.isEmpty()) {
        logger.debug("Using either environment variables, system properties or instance profile credentials");
        credentials = new DefaultAWSCredentialsProviderChain();
    } else {
        logger.debug("Using basic key/secret credentials");
        credentials = new StaticCredentialsProvider(new BasicAWSCredentials(key, secret));
    }
    return credentials;
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) StaticCredentialsProvider(com.amazonaws.internal.StaticCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

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