/** * Create an instance of {@link AwsParamsDto } * */ public AwsParamsDto createAwsParamsDto() { return new AwsParamsDto(); }
public Object copyTo(ObjectLocator locator, Object target, CopyStrategy2 strategy) { final Object draftCopy = ((target == null)?createNewInstance():target); if (draftCopy instanceof AwsParamsDto) { final AwsParamsDto copy = ((AwsParamsDto) draftCopy); if (awsAccessKeyIdShouldBeCopiedAndSet == Boolean.TRUE) { String sourceAwsAccessKeyId; sourceAwsAccessKeyId = this.getAwsAccessKeyId(); String copyAwsAccessKeyId = ((String) strategy.copy(LocatorUtils.property(locator, "awsAccessKeyId", sourceAwsAccessKeyId), sourceAwsAccessKeyId, (this.awsAccessKeyId!= null))); copy.setAwsAccessKeyId(copyAwsAccessKeyId); } else { if (awsAccessKeyIdShouldBeCopiedAndSet == Boolean.FALSE) { if (awsSecretKeyShouldBeCopiedAndSet == Boolean.TRUE) { String sourceAwsSecretKey; sourceAwsSecretKey = this.getAwsSecretKey(); String copyAwsSecretKey = ((String) strategy.copy(LocatorUtils.property(locator, "awsSecretKey", sourceAwsSecretKey), sourceAwsSecretKey, (this.awsSecretKey!= null))); copy.setAwsSecretKey(copyAwsSecretKey); } else { if (awsSecretKeyShouldBeCopiedAndSet == Boolean.FALSE) { if (sessionTokenShouldBeCopiedAndSet == Boolean.TRUE) { String sourceSessionToken; sourceSessionToken = this.getSessionToken(); String copySessionToken = ((String) strategy.copy(LocatorUtils.property(locator, "sessionToken", sourceSessionToken), sourceSessionToken, (this.sessionToken!= null))); copy.setSessionToken(copySessionToken); } else { if (sessionTokenShouldBeCopiedAndSet == Boolean.FALSE) { if (httpProxyHostShouldBeCopiedAndSet == Boolean.TRUE) {
@Test public void testEquals() throws Exception { AwsParamsDto dto1 = new AwsParamsDto(); dto1.setHttpProxyHost("localhost1"); dto1.setHttpProxyPort(8080); AwsParamsDto dto2 = new AwsParamsDto(); dto2.setHttpProxyHost("localhost2"); dto2.setHttpProxyPort(8080); AwsParamsDto dto3 = new AwsParamsDto(); dto3.setHttpProxyHost("localhost1"); dto3.setHttpProxyPort(8080); assertTrue(!dto1.equals(dto2)); assertTrue(dto1.equals(dto3)); }
/** * Constructs awsParamsDto with AWS parameters. * * @return the AWS params DTO object. */ public AwsParamsDto getAwsParamsDto() { // Get HTTP proxy configuration settings. String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST); Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class); // Get AWS region name. String awsRegionName = configurationHelper.getProperty(ConfigurationValue.AWS_REGION_NAME); // Create an AWS parameters DTO. AwsParamsDto awsParamsDto = new AwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); awsParamsDto.setAwsRegionName(awsRegionName); return awsParamsDto; }
/** * Creates a client configuration object that contains client configuration options such as proxy settings and max retry attempts. * * @param awsParamsDto the AWS related parameters that contain optional proxy information * * @return the client configuration object */ public ClientConfiguration getClientConfiguration(AwsParamsDto awsParamsDto) { ClientConfiguration clientConfiguration = new ClientConfiguration(); // Set a retry policy. clientConfiguration.withRetryPolicy(retryPolicyFactory.getRetryPolicy()); // If the proxy hostname and port both are configured, set the HTTP proxy information. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.withProxyHost(awsParamsDto.getHttpProxyHost()).withProxyPort(awsParamsDto.getHttpProxyPort()); } return clientConfiguration; }
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) { theAwsAccessKeyId = this.getAwsAccessKeyId(); strategy.appendField(locator, this, "awsAccessKeyId", buffer, theAwsAccessKeyId, (this.awsAccessKeyId!= null)); theAwsSecretKey = this.getAwsSecretKey(); strategy.appendField(locator, this, "awsSecretKey", buffer, theAwsSecretKey, (this.awsSecretKey!= null)); theSessionToken = this.getSessionToken(); strategy.appendField(locator, this, "sessionToken", buffer, theSessionToken, (this.sessionToken!= null)); theHttpProxyHost = this.getHttpProxyHost(); strategy.appendField(locator, this, "httpProxyHost", buffer, theHttpProxyHost, (this.httpProxyHost!= null)); theHttpProxyPort = this.getHttpProxyPort(); strategy.appendField(locator, this, "httpProxyPort", buffer, theHttpProxyPort, (this.httpProxyPort!= null)); theAwsRegionName = this.getAwsRegionName(); strategy.appendField(locator, this, "awsRegionName", buffer, theAwsRegionName, (this.awsRegionName!= null));
@Test public void testHashCode() throws Exception { AwsParamsDto dto1 = new AwsParamsDto(); dto1.setHttpProxyHost("localhost1"); dto1.setHttpProxyPort(8080); AwsParamsDto dto2 = new AwsParamsDto(); dto2.setHttpProxyHost("localhost2"); dto2.setHttpProxyPort(8080); AwsParamsDto dto3 = new AwsParamsDto(); dto3.setHttpProxyHost("localhost1"); dto3.setHttpProxyPort(8080); assertTrue(dto1.hashCode() != dto2.hashCode()); assertTrue(dto1.hashCode() == dto3.hashCode()); } }
@Test public void testGetEc2Client() throws Exception { // Get the EMR client with proxy configuration. AwsParamsDto awsParamsDto = awsHelper.getAwsParamsDto(); awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); // Set the proxy host as blank to get the EMR client without proxy. awsParamsDto.setHttpProxyHost(BLANK_TEXT); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); // Set the proxy port as null to get the EMR client without proxy. awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(null); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); // Set the proxy host as blank and proxy port as null to get the EMR client without proxy. awsParamsDto.setHttpProxyHost(BLANK_TEXT); awsParamsDto.setHttpProxyPort(null); assertNotNull(ec2Dao.getEc2Client(awsParamsDto)); }
@Test public void testDecrypt() { // Decrypt the test ciphertext. AwsParamsDto testAwsParamsDto = new AwsParamsDto(); testAwsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); testAwsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); // Decrypt the test ciphertext. String resultPlainText = kmsDao.decrypt(testAwsParamsDto, MockKmsOperationsImpl.MOCK_CIPHER_TEXT); // Validate the results. assertEquals(MockKmsOperationsImpl.MOCK_PLAIN_TEXT, resultPlainText); }
/** * Creates a client for accessing Amazon EC2 service. * * @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information * * @return the Amazon EC2 client */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonEC2 getEc2Client(AwsParamsDto awsParamsDto) { // Get client configuration. ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto); // If specified, use the AWS credentials passed in. if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId())) { return AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider( new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken()))) .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } // Otherwise, use the default AWS credentials provider chain. else { return AmazonEC2ClientBuilder.standard().withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } }
/** * This method tests the blank proxy details */ @Test public void testEmrAwsDtoBlankProxy() throws Exception { // Set the proxy as blank too to get the EMR client without proxy AwsParamsDto awsParamsDto = emrHelper.getAwsParamsDto(); awsParamsDto.setHttpProxyHost(""); emrDao.getEmrClient(awsParamsDto); }
/** * Creates a client for accessing Amazon SNS. * * @param awsParamsDto the AWS related parameters DTO that includes optional proxy information * * @return the Amazon SNS client */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonSNS getAmazonSNSClient(AwsParamsDto awsParamsDto) { // Construct and return a new client to invoke service methods on Amazon SNS using default credentials provider chain. return AmazonSNSClientBuilder.standard().withClientConfiguration(awsHelper.getClientConfiguration(awsParamsDto)) .withRegion(awsParamsDto.getAwsRegionName()).build(); }
public boolean equals(Object object) { final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE; return equals(null, null, object, strategy); }
/** * Creates a client configuration object that contains client configuration options such as proxy settings and max retry attempts. * * @param awsParamsDto the AWS related parameters that contain optional proxy information * * @return the client configuration object */ public ClientConfiguration getClientConfiguration(AwsParamsDto awsParamsDto) { ClientConfiguration clientConfiguration = new ClientConfiguration(); // Set a retry policy. clientConfiguration.withRetryPolicy(retryPolicyFactory.getRetryPolicy()); // If the proxy hostname and port both are configured, set the HTTP proxy information. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost()) && awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.withProxyHost(awsParamsDto.getHttpProxyHost()).withProxyPort(awsParamsDto.getHttpProxyPort()); } return clientConfiguration; }
lhsAwsAccessKeyId = this.getAwsAccessKeyId(); String rhsAwsAccessKeyId; rhsAwsAccessKeyId = that.getAwsAccessKeyId(); if (!strategy.equals(LocatorUtils.property(thisLocator, "awsAccessKeyId", lhsAwsAccessKeyId), LocatorUtils.property(thatLocator, "awsAccessKeyId", rhsAwsAccessKeyId), lhsAwsAccessKeyId, rhsAwsAccessKeyId, (this.awsAccessKeyId!= null), (that.awsAccessKeyId!= null))) { return false; lhsAwsSecretKey = this.getAwsSecretKey(); String rhsAwsSecretKey; rhsAwsSecretKey = that.getAwsSecretKey(); if (!strategy.equals(LocatorUtils.property(thisLocator, "awsSecretKey", lhsAwsSecretKey), LocatorUtils.property(thatLocator, "awsSecretKey", rhsAwsSecretKey), lhsAwsSecretKey, rhsAwsSecretKey, (this.awsSecretKey!= null), (that.awsSecretKey!= null))) { return false; lhsSessionToken = this.getSessionToken(); String rhsSessionToken; rhsSessionToken = that.getSessionToken(); if (!strategy.equals(LocatorUtils.property(thisLocator, "sessionToken", lhsSessionToken), LocatorUtils.property(thatLocator, "sessionToken", rhsSessionToken), lhsSessionToken, rhsSessionToken, (this.sessionToken!= null), (that.sessionToken!= null))) { return false; lhsHttpProxyHost = this.getHttpProxyHost(); String rhsHttpProxyHost; rhsHttpProxyHost = that.getHttpProxyHost(); if (!strategy.equals(LocatorUtils.property(thisLocator, "httpProxyHost", lhsHttpProxyHost), LocatorUtils.property(thatLocator, "httpProxyHost", rhsHttpProxyHost), lhsHttpProxyHost, rhsHttpProxyHost, (this.httpProxyHost!= null), (that.httpProxyHost!= null))) { return false; lhsHttpProxyPort = this.getHttpProxyPort(); Integer rhsHttpProxyPort; rhsHttpProxyPort = that.getHttpProxyPort(); if (!strategy.equals(LocatorUtils.property(thisLocator, "httpProxyPort", lhsHttpProxyPort), LocatorUtils.property(thatLocator, "httpProxyPort", rhsHttpProxyPort), lhsHttpProxyPort, rhsHttpProxyPort, (this.httpProxyPort!= null), (that.httpProxyPort!= null))) { return false;
/** * Constructs awsParamsDto with AWS parameters. * * @return the AWS params DTO object. */ public AwsParamsDto getAwsParamsDto() { // Get HTTP proxy configuration settings. String httpProxyHost = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_HOST); Integer httpProxyPort = configurationHelper.getProperty(ConfigurationValue.HTTP_PROXY_PORT, Integer.class); // Get AWS region name. String awsRegionName = configurationHelper.getProperty(ConfigurationValue.AWS_REGION_NAME); // Create an AWS parameters DTO. AwsParamsDto awsParamsDto = new AwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); awsParamsDto.setAwsRegionName(awsRegionName); return awsParamsDto; }
@Test public void getEmrClientAssertClientConfigurationNotSetWhenProxyPortIsNull() throws Exception { String httpProxyHost = "httpProxyHost"; Integer httpProxyPort = null; AwsParamsDto awsParamsDto = getAwsParamsDto(); awsParamsDto.setHttpProxyHost(httpProxyHost); awsParamsDto.setHttpProxyPort(httpProxyPort); AmazonElasticMapReduceClient amazonElasticMapReduceClient = emrDao.getEmrClient(awsParamsDto); ClientConfiguration clientConfiguration = (ClientConfiguration) ReflectionTestUtils.getField(amazonElasticMapReduceClient, "clientConfiguration"); assertNotNull(clientConfiguration); assertNull(clientConfiguration.getProxyHost()); }
AwsParamsDto awsParamsDto = new AwsParamsDto(); awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT);
/** * Creates a client for accessing Amazon EC2 service. * * @param awsParamsDto the AWS related parameters DTO that includes optional AWS credentials and proxy information * * @return the Amazon EC2 client */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonEC2 getEc2Client(AwsParamsDto awsParamsDto) { // Get client configuration. ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsParamsDto); // If specified, use the AWS credentials passed in. if (StringUtils.isNotBlank(awsParamsDto.getAwsAccessKeyId())) { return AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider( new BasicSessionCredentials(awsParamsDto.getAwsAccessKeyId(), awsParamsDto.getAwsSecretKey(), awsParamsDto.getSessionToken()))) .withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } // Otherwise, use the default AWS credentials provider chain. else { return AmazonEC2ClientBuilder.standard().withClientConfiguration(clientConfiguration).withRegion(awsParamsDto.getAwsRegionName()).build(); } }
/** * Creates a client for accessing Amazon SQS. * * @param awsParamsDto the AWS related parameters DTO that includes optional proxy information * * @return the Amazon SQS client */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonSQS getAmazonSQSClient(AwsParamsDto awsParamsDto) { // Construct and return a new client to invoke service methods on Amazon SQS using default credentials provider chain. return AmazonSQSClientBuilder.standard().withClientConfiguration(awsHelper.getClientConfiguration(awsParamsDto)) .withRegion(awsParamsDto.getAwsRegionName()).build(); }