use of com.amazonaws.ClientConfiguration in project herd by FINRAOS.
the class S3DaoTest method testGetAmazonS3AssertProxyIsNotSetWhenProxyHostIsBlank.
@Test
public void testGetAmazonS3AssertProxyIsNotSetWhenProxyHostIsBlank() {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
String s3BucketName = "s3BucketName";
String s3KeyPrefix = "s3KeyPrefix";
String httpProxyHost = "";
Integer httpProxyPort = 1234;
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
s3FileTransferRequestParamsDto.setHttpProxyHost(httpProxyHost);
s3FileTransferRequestParamsDto.setHttpProxyPort(httpProxyPort);
when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {
@Override
public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
AmazonS3Client amazonS3Client = invocation.getArgument(1);
ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonS3Client, "clientConfiguration");
assertNull(clientConfiguration.getProxyHost());
return new PutObjectResult();
}
});
s3Dao.createDirectory(s3FileTransferRequestParamsDto);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
use of com.amazonaws.ClientConfiguration in project herd by FINRAOS.
the class CredStashHelper method getCredentialFromCredStash.
/**
* Gets a password from the credstash.
*
* @param credStashEncryptionContext the encryption context
* @param credentialName the credential name
*
* @return the password
* @throws CredStashGetCredentialFailedException if CredStash fails to get a credential
*/
@Retryable(maxAttempts = 3, value = CredStashGetCredentialFailedException.class, backoff = @Backoff(delay = 5000, multiplier = 2))
public String getCredentialFromCredStash(String credStashEncryptionContext, String credentialName) throws CredStashGetCredentialFailedException {
// Get the credstash table name and credential names for the keystore and truststore.
String credStashAwsRegion = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_AWS_REGION_NAME);
String credStashTableName = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_TABLE_NAME);
// Log configuration values and input parameters.
LOGGER.info("credStashAwsRegion={} credStashTableName={} credStashEncryptionContext={} credentialName={}", credStashAwsRegion, credStashTableName, credStashEncryptionContext, credentialName);
// Get the AWS client configuration.
ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsHelper.getAwsParamsDto());
// Get the keystore and truststore passwords from Credstash.
CredStash credstash = credStashFactory.getCredStash(credStashAwsRegion, credStashTableName, clientConfiguration);
// Try to obtain the credentials from cred stash.
String password = null;
String errorMessage = null;
try {
// Convert the JSON config file version of the encryption context to a Java Map class.
@SuppressWarnings("unchecked") Map<String, String> credstashEncryptionContextMap = jsonHelper.unmarshallJsonToObject(Map.class, credStashEncryptionContext);
// Get the keystore and truststore passwords from credstash.
password = credstash.getCredential(credentialName, credstashEncryptionContextMap);
} catch (Exception exception) {
LOGGER.error("Caught exception when attempting to get a credential value from CredStash.", exception);
errorMessage = exception.getMessage();
}
// as credentials from cred stash, then throw a CredStashGetCredentialFailedException.
if (StringUtils.isEmpty(password)) {
throw new CredStashGetCredentialFailedException(String.format("Failed to obtain the keystore or truststore credential from credstash.%s " + "credStashAwsRegion=%s credStashTableName=%s credStashEncryptionContext=%s credentialName=%s", StringUtils.isNotBlank(errorMessage) ? " Reason: " + errorMessage : "", credStashAwsRegion, credStashTableName, credStashEncryptionContext, credentialName));
}
// Return the keystore and truststore passwords in a map.
return password;
}
use of com.amazonaws.ClientConfiguration in project photon-model by vmware.
the class AWSUtils method getStatsAsyncClient.
/**
* Method to get a CloudWatch Async Client.
*
* Note: ARN-based credentials will not work unless they have already been exchanged to
* AWS for session credentials. If unset, this method will fail. To enable ARN-based
* credentials, migrate to {@link #getCloudWatchStatsAsyncClient(AuthCredentialsServiceState,
* String, ExecutorService, boolean)}.
*
* @param credentials An {@link AuthCredentialsServiceState} object.
* @param region The region to get the AWS client in.
* @param executorService The executor service to run async services in.
*/
public static AmazonCloudWatchAsyncClient getStatsAsyncClient(AuthCredentialsServiceState credentials, String region, ExecutorService executorService, boolean isMockRequest) {
ClientConfiguration configuration = createClientConfiguration();
AmazonCloudWatchAsyncClientBuilder amazonCloudWatchAsyncClientBuilder = AmazonCloudWatchAsyncClientBuilder.standard().withClientConfiguration(configuration).withCredentials(getAwsStaticCredentialsProvider(credentials)).withExecutorFactory(() -> executorService);
if (region == null) {
region = Regions.DEFAULT_REGION.getName();
}
if (isAwsClientMock()) {
configuration.addHeader(AWS_REGION_HEADER, region);
amazonCloudWatchAsyncClientBuilder.setClientConfiguration(configuration);
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(getAWSMockHost() + AWS_MOCK_CLOUDWATCH_ENDPOINT, region);
amazonCloudWatchAsyncClientBuilder.setEndpointConfiguration(endpointConfiguration);
} else {
amazonCloudWatchAsyncClientBuilder.setRegion(region);
}
return (AmazonCloudWatchAsyncClient) amazonCloudWatchAsyncClientBuilder.build();
}
use of com.amazonaws.ClientConfiguration in project photon-model by vmware.
the class AWSUtils method getAsyncClient.
/**
* Method to get an EC2 Async Client.
*
* Note: ARN-based credentials will not work unless they have already been exchanged to
* AWS for session credentials. If unset, this method will fail. To enable ARN-based
* credentials, migrate to {@link #getEc2AsyncClient(AuthCredentialsServiceState, String,
* ExecutorService)}.
*
* @param credentials An {@link AuthCredentialsServiceState} object.
* @param region The region to get the AWS client in.
* @param executorService The executor service to run async services in.
*/
public static AmazonEC2AsyncClient getAsyncClient(AuthCredentialsServiceState credentials, String region, ExecutorService executorService) {
ClientConfiguration configuration = createClientConfiguration().withMaxConnections(100);
AmazonEC2AsyncClientBuilder ec2AsyncClientBuilder = AmazonEC2AsyncClientBuilder.standard().withClientConfiguration(configuration).withCredentials(getAwsStaticCredentialsProvider(credentials)).withExecutorFactory(() -> executorService);
if (region == null) {
region = Regions.DEFAULT_REGION.getName();
}
if (isAwsClientMock()) {
configuration.addHeader(AWS_REGION_HEADER, region);
ec2AsyncClientBuilder.setClientConfiguration(configuration);
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(getAWSMockHost() + AWS_MOCK_EC2_ENDPOINT, region);
ec2AsyncClientBuilder.setEndpointConfiguration(endpointConfiguration);
} else {
ec2AsyncClientBuilder.setRegion(region);
}
return (AmazonEC2AsyncClient) ec2AsyncClientBuilder.build();
}
use of com.amazonaws.ClientConfiguration in project neo4j-apoc-procedures by neo4j-contrib.
the class S3URLConnection method buildClientConfig.
public static ClientConfiguration buildClientConfig() {
final String userAgent = System.getProperty(PROP_S3_HANDLER_USER_AGENT, null);
final String protocol = System.getProperty(PROP_S3_HANDLER_PROTOCOL, "https").toLowerCase();
final String signerOverride = System.getProperty(PROP_S3_HANDLER_SIGNER_OVERRIDE, null);
final ClientConfiguration clientConfig = new ClientConfiguration().withProtocol("https".equals(protocol) ? Protocol.HTTPS : Protocol.HTTP);
if (userAgent != null) {
clientConfig.setUserAgentPrefix(userAgent);
}
if (signerOverride != null) {
clientConfig.setSignerOverride(signerOverride);
}
return clientConfig;
}
Aggregations