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());
}
use of com.amazonaws.ClientConfiguration in project camel by apache.
the class SnsEndpoint method createSNSClient.
/**
* Provide the possibility to override this method for an mock implementation
*
* @return AmazonSNSClient
*/
AmazonSNS createSNSClient() {
AmazonSNS client = null;
ClientConfiguration clientConfiguration = null;
boolean isClientConfigFound = false;
if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost(configuration.getProxyHost());
clientConfiguration.setProxyPort(configuration.getProxyPort());
isClientConfigFound = true;
}
if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
if (isClientConfigFound) {
client = new AmazonSNSClient(credentials, clientConfiguration);
} else {
client = new AmazonSNSClient(credentials);
}
} else {
if (isClientConfigFound) {
client = new AmazonSNSClient();
} else {
client = new AmazonSNSClient(clientConfiguration);
}
}
return client;
}
use of com.amazonaws.ClientConfiguration in project nifi by apache.
the class AbstractAWSProcessor method createConfiguration.
protected ClientConfiguration createConfiguration(final ProcessContext context) {
final ClientConfiguration config = new ClientConfiguration();
config.setMaxConnections(context.getMaxConcurrentTasks());
config.setMaxErrorRetry(0);
config.setUserAgent(DEFAULT_USER_AGENT);
// If this is changed to be a property, ensure other uses are also changed
config.setProtocol(DEFAULT_PROTOCOL);
final int commsTimeout = context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
config.setConnectionTimeout(commsTimeout);
config.setSocketTimeout(commsTimeout);
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
if (sslContextService != null) {
final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.NONE);
// NIFI-3788: Changed hostnameVerifier from null to DHV (BrowserCompatibleHostnameVerifier is deprecated)
SdkTLSSocketFactory sdkTLSSocketFactory = new SdkTLSSocketFactory(sslContext, new DefaultHostnameVerifier());
config.getApacheHttpClientConfig().setSslSocketFactory(sdkTLSSocketFactory);
}
if (context.getProperty(PROXY_HOST).isSet()) {
String proxyHost = context.getProperty(PROXY_HOST).evaluateAttributeExpressions().getValue();
config.setProxyHost(proxyHost);
Integer proxyPort = context.getProperty(PROXY_HOST_PORT).evaluateAttributeExpressions().asInteger();
config.setProxyPort(proxyPort);
}
return config;
}
use of com.amazonaws.ClientConfiguration in project nifi by apache.
the class TestAWSCredentials method setUp.
@Before
public void setUp() {
mockAwsProcessor = new AbstractAWSCredentialsProviderProcessor<AmazonS3Client>() {
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
return Arrays.asList(AbstractAWSCredentialsProviderProcessor.AWS_CREDENTIALS_PROVIDER_SERVICE, AbstractAWSProcessor.CREDENTIALS_FILE, AbstractAWSProcessor.ACCESS_KEY, AbstractAWSProcessor.SECRET_KEY, AbstractAWSProcessor.TIMEOUT);
}
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
awsCredentials = credentials;
clientConfiguration = config;
final AmazonS3Client s3 = new AmazonS3Client(credentials, config);
return s3;
}
@Override
protected AmazonS3Client createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config) {
awsCredentialsProvider = credentialsProvider;
clientConfiguration = config;
final AmazonS3Client s3 = new AmazonS3Client(credentialsProvider, config);
return s3;
}
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
}
};
runner = TestRunners.newTestRunner(mockAwsProcessor);
}
use of com.amazonaws.ClientConfiguration in project georocket by georocket.
the class S3Store method getS3Client.
/**
* Get or initialize the S3 client.
* Note: this method must be synchronized because we're accessing the
* {@link #s3Client} field and we're calling this method from a worker thread.
* @return the S3 client
*/
private synchronized AmazonS3 getS3Client() {
if (s3Client == null) {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials));
if (forceSignatureV2) {
ClientConfigurationFactory configFactory = new ClientConfigurationFactory();
ClientConfiguration config = configFactory.getConfig();
config.setSignerOverride("S3SignerType");
builder = builder.withClientConfiguration(config);
}
String endpoint = "http://" + host + ":" + port;
String clientRegion = null;
if (!ServiceUtils.isS3USStandardEndpoint(endpoint)) {
clientRegion = AwsHostNameUtils.parseRegion(host, AmazonS3Client.S3_SERVICE_NAME);
}
builder = builder.withEndpointConfiguration(new EndpointConfiguration(endpoint, clientRegion));
builder = builder.withPathStyleAccessEnabled(pathStyleAccess);
s3Client = builder.build();
}
return s3Client;
}
Aggregations