List of usage examples for com.amazonaws ClientConfiguration withProtocol
public ClientConfiguration withProtocol(Protocol protocol)
From source file:io.confluent.connect.s3.storage.S3Storage.java
License:Open Source License
/** * Creates S3 client's configuration.//from w w w. ja va 2 s . c om * This method currently configures the AWS client retry policy to use full jitter. * Visible for testing. * * @param config the S3 configuration. * @return S3 client's configuration */ public ClientConfiguration newClientConfiguration(S3SinkConnectorConfig config) { String version = String.format(VERSION_FORMAT, Version.getVersion()); ClientConfiguration clientConfiguration = PredefinedClientConfigurations.defaultConfig(); clientConfiguration.withUserAgentPrefix(version).withRetryPolicy(newFullJitterRetryPolicy(config)); if (StringUtils.isNotBlank(config.getString(S3_PROXY_URL_CONFIG))) { S3ProxyConfig proxyConfig = new S3ProxyConfig(config); clientConfiguration.withProtocol(proxyConfig.protocol()).withProxyHost(proxyConfig.host()) .withProxyPort(proxyConfig.port()).withProxyUsername(proxyConfig.user()) .withProxyPassword(proxyConfig.pass()); } clientConfiguration.withUseExpectContinue(config.useExpectContinue()); return clientConfiguration; }
From source file:org.apache.heron.uploader.s3.S3Uploader.java
License:Apache License
@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"); }/*w w w .jav a 2 s. co m*/ // If an accessKey is specified, use it. Otherwise check if an aws profile // is specified. If neither was set just use the DefaultAWSCredentialsProviderChain // 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()); }