Search in sources :

Example 96 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project SimianArmy by Netflix.

the class TestBasicContext method testIsAbleToUseProxyByConfiguration.

@Test
public void testIsAbleToUseProxyByConfiguration() {
    BasicSimianArmyContext ctx = new BasicSimianArmyContext("proxy.properties");
    ClientConfiguration awsClientConfig = ctx.getAwsClientConfig();
    Assert.assertEquals(awsClientConfig.getProxyHost(), "127.0.0.1");
    Assert.assertEquals(awsClientConfig.getProxyPort(), 80);
    Assert.assertEquals(awsClientConfig.getProxyUsername(), "fakeUser");
    Assert.assertEquals(awsClientConfig.getProxyPassword(), "fakePassword");
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.testng.annotations.Test)

Example 97 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project SimianArmy by Netflix.

the class TestBasicContext method testIsNotUsingProxyByDefault.

@Test
public void testIsNotUsingProxyByDefault() {
    BasicSimianArmyContext ctx = new BasicSimianArmyContext();
    ClientConfiguration awsClientConfig = ctx.getAwsClientConfig();
    Assert.assertNull(awsClientConfig.getProxyHost());
    Assert.assertEquals(awsClientConfig.getProxyPort(), -1);
    Assert.assertNull(awsClientConfig.getProxyUsername());
    Assert.assertNull(awsClientConfig.getProxyPassword());
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.testng.annotations.Test)

Example 98 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project aws-doc-sdk-examples by awsdocs.

the class S3EncryptV2 method putEncryptedData1.

public static void putEncryptedData1() throws NoSuchAlgorithmException {
    // snippet-start:[s3.java.s3_cse_v2.symmetric]
    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
    keyGenerator.init(256);
    // generate a symmetric encryption key for testing
    SecretKey secretKey = keyGenerator.generateKey();
    // snippet-start:[s3.java.s3_cse_v2.strictauth]
    String s3ObjectKey = "EncryptedContent1.txt";
    String s3ObjectContent = "This is the 1st content to encrypt";
    AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard().withRegion(Regions.DEFAULT_REGION).withClientConfiguration(new ClientConfiguration()).withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode(CryptoMode.StrictAuthenticatedEncryption)).withEncryptionMaterialsProvider(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey))).build();
    s3Encryption.putObject(bucketName, s3ObjectKey, s3ObjectContent);
    // snippet-end:[s3.java.s3_cse_v2.strictauth]
    System.out.println(s3Encryption.getObjectAsString(bucketName, s3ObjectKey));
    s3Encryption.shutdown();
// snippet-end:[s3.java.s3_cse_v2.symmetric]
}
Also used : AmazonS3EncryptionV2(com.amazonaws.services.s3.AmazonS3EncryptionV2) SecretKey(javax.crypto.SecretKey) EncryptionMaterials(com.amazonaws.services.s3.model.EncryptionMaterials) CryptoConfigurationV2(com.amazonaws.services.s3.model.CryptoConfigurationV2) StaticEncryptionMaterialsProvider(com.amazonaws.services.s3.model.StaticEncryptionMaterialsProvider) KeyGenerator(javax.crypto.KeyGenerator) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 99 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project beam by apache.

the class AwsModuleTest method testAwsHttpClientConfigurationSerializationDeserializationProto.

@Test
public void testAwsHttpClientConfigurationSerializationDeserializationProto() throws Exception {
    AwsOptions awsOptions = PipelineOptionsTranslation.fromProto(PipelineOptionsTranslation.toProto(PipelineOptionsFactory.fromArgs("--clientConfiguration={ \"connectionTimeout\": 100, \"connectionMaxIdleTime\": 1000, \"socketTimeout\": 300, \"proxyPort\": -1, \"requestTimeout\": 1500 }").create())).as(AwsOptions.class);
    ClientConfiguration clientConfigurationDeserialized = awsOptions.getClientConfiguration();
    assertEquals(100, clientConfigurationDeserialized.getConnectionTimeout());
    assertEquals(1000, clientConfigurationDeserialized.getConnectionMaxIdleMillis());
    assertEquals(300, clientConfigurationDeserialized.getSocketTimeout());
    assertEquals(-1, clientConfigurationDeserialized.getProxyPort());
    assertEquals(1500, clientConfigurationDeserialized.getRequestTimeout());
}
Also used : ClientConfiguration(com.amazonaws.ClientConfiguration) Test(org.junit.Test)

Example 100 with ClientConfiguration

use of com.amazonaws.ClientConfiguration in project heron by twitter.

the class S3Uploader method initialize.

@Override
public void initialize(Config config) {
    bucket = S3Context.bucket(config);
    String accessKey = S3Context.accessKey(config);
    String accessSecret = S3Context.secretKey(config);
    String awsProfile = S3Context.awsProfile(config);
    String proxy = S3Context.proxyUri(config);
    String endpoint = S3Context.uri(config);
    String customRegion = S3Context.region(config);
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    if (Strings.isNullOrEmpty(bucket)) {
        throw new RuntimeException("Missing heron.uploader.s3.bucket config value");
    }
    // by not specifying a CredentialsProvider.
    if (!Strings.isNullOrEmpty(accessKey) || !Strings.isNullOrEmpty(accessSecret)) {
        if (!Strings.isNullOrEmpty(awsProfile)) {
            throw new RuntimeException("Please provide access_key/secret_key " + "or aws_profile, not both.");
        }
        if (Strings.isNullOrEmpty(accessKey)) {
            throw new RuntimeException("Missing heron.uploader.s3.access_key config value");
        }
        if (Strings.isNullOrEmpty(accessSecret)) {
            throw new RuntimeException("Missing heron.uploader.s3.secret_key config value");
        }
        builder.setCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, accessSecret)));
    } else if (!Strings.isNullOrEmpty(awsProfile)) {
        builder.setCredentials(new ProfileCredentialsProvider(awsProfile));
    }
    if (!Strings.isNullOrEmpty(proxy)) {
        URI proxyUri;
        try {
            proxyUri = new URI(proxy);
        } catch (URISyntaxException e) {
            throw new RuntimeException("Invalid heron.uploader.s3.proxy_uri config value: " + proxy, e);
        }
        ClientConfiguration clientCfg = new ClientConfiguration();
        clientCfg.withProtocol(Protocol.HTTPS).withProxyHost(proxyUri.getHost()).withProxyPort(proxyUri.getPort());
        if (!Strings.isNullOrEmpty(proxyUri.getUserInfo())) {
            String[] info = proxyUri.getUserInfo().split(":", 2);
            clientCfg.setProxyUsername(info[0]);
            if (info.length > 1) {
                clientCfg.setProxyPassword(info[1]);
            }
        }
        builder.setClientConfiguration(clientCfg);
    }
    s3Client = builder.withRegion(customRegion).withPathStyleAccessEnabled(true).withChunkedEncodingDisabled(true).withPayloadSigningEnabled(true).build();
    if (!Strings.isNullOrEmpty(endpoint)) {
        s3Client.setEndpoint(endpoint);
    }
    final String topologyName = Context.topologyName(config);
    final String topologyPackageLocation = Context.topologyPackageFile(config);
    pathPrefix = S3Context.pathPrefix(config);
    packageFileHandler = new File(topologyPackageLocation);
    // The path the packaged topology will be uploaded to
    remoteFilePath = generateS3Path(pathPrefix, topologyName, packageFileHandler.getName());
    // Generate the location of the backup file incase we need to revert the deploy
    previousVersionFilePath = generateS3Path(pathPrefix, topologyName, "previous_" + packageFileHandler.getName());
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

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