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());
}
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());
}
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();
}
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);
}
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;
}
Aggregations