Search in sources :

Example 66 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project crate by crate.

the class AwsS3ServiceImplTests method launchAWSConfigurationTest.

private void launchAWSConfigurationTest(Settings settings, Protocol expectedProtocol, String expectedProxyHost, int expectedProxyPort, String expectedProxyUsername, String expectedProxyPassword, Integer expectedMaxRetries, boolean expectedUseThrottleRetries, int expectedReadTimeout) {
    final S3ClientSettings clientSettings = S3ClientSettings.getClientSettings(settings);
    final ClientConfiguration configuration = S3Service.buildConfiguration(clientSettings);
    assertThat(configuration.getResponseMetadataCacheSize(), is(0));
    assertThat(configuration.getProtocol(), is(expectedProtocol));
    assertThat(configuration.getProxyHost(), is(expectedProxyHost));
    assertThat(configuration.getProxyPort(), is(expectedProxyPort));
    assertThat(configuration.getProxyUsername(), is(expectedProxyUsername));
    assertThat(configuration.getProxyPassword(), is(expectedProxyPassword));
    assertThat(configuration.getMaxErrorRetry(), is(expectedMaxRetries));
    assertThat(configuration.useThrottledRetries(), is(expectedUseThrottleRetries));
    assertThat(configuration.getSocketTimeout(), is(expectedReadTimeout));
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 67 with ClientConfiguration

use of com.amazonaws.ClientConfiguration 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 68 with ClientConfiguration

use of com.amazonaws.ClientConfiguration 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 69 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project aws-xray-sdk-java by aws.

the class TracingHandlerTest method mockHttpClient.

private void mockHttpClient(Object client, String responseContent) {
    AmazonHttpClient amazonHttpClient = new AmazonHttpClient(new ClientConfiguration());
    ConnectionManagerAwareHttpClient apacheHttpClient = Mockito.mock(ConnectionManagerAwareHttpClient.class);
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    BasicHttpEntity responseBody = new BasicHttpEntity();
    InputStream in = EmptyInputStream.INSTANCE;
    if (null != responseContent && !responseContent.isEmpty()) {
        in = new ByteArrayInputStream(responseContent.getBytes(StandardCharsets.UTF_8));
    }
    responseBody.setContent(in);
    httpResponse.setEntity(responseBody);
    try {
        Mockito.doReturn(httpResponse).when(apacheHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(HttpContext.class));
    } catch (IOException e) {
    // Ignore
    }
    Whitebox.setInternalState(amazonHttpClient, "httpClient", apacheHttpClient);
    Whitebox.setInternalState(client, "client", amazonHttpClient);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) EmptyInputStream(org.apache.http.impl.io.EmptyInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AmazonHttpClient(com.amazonaws.http.AmazonHttpClient) HttpContext(org.apache.http.protocol.HttpContext) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) IOException(java.io.IOException) ConnectionManagerAwareHttpClient(com.amazonaws.http.apache.client.impl.ConnectionManagerAwareHttpClient) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 70 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project pipeline-aws-plugin by jenkinsci.

the class ProxyTest method shouldParseProxyLowerCase.

@Test
public void shouldParseProxyLowerCase() throws Exception {
    EnvVars vars = new EnvVars();
    vars.put(ProxyConfiguration.HTTPS_PROXY_LC, "http://127.0.0.1:8888/");
    ClientConfiguration config = new ClientConfiguration();
    config.setProtocol(Protocol.HTTPS);
    ProxyConfiguration.configure(vars, config);
    Assert.assertNull(config.getProxyUsername());
    Assert.assertNull(config.getProxyPassword());
    Assert.assertEquals("127.0.0.1", config.getProxyHost());
    Assert.assertEquals(8888, config.getProxyPort());
}
Also used : EnvVars(hudson.EnvVars) ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (com.amazonaws.ClientConfiguration)134 Test (org.junit.Test)35 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)29 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)17 AWSCredentials (com.amazonaws.auth.AWSCredentials)14 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)13 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)13 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)10 AwsParamsDto (org.finra.herd.model.dto.AwsParamsDto)8 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)7 EnvVars (hudson.EnvVars)7 File (java.io.File)7 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)6 Configuration (org.apache.hadoop.conf.Configuration)6 AmazonClientException (com.amazonaws.AmazonClientException)5 DefaultAWSCredentialsProviderChain (com.amazonaws.auth.DefaultAWSCredentialsProviderChain)5 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)5 URI (java.net.URI)5 Properties (java.util.Properties)5 Test (org.testng.annotations.Test)5