Java Code Examples for com.amazonaws.ClientConfiguration#setProxyPort()
The following examples show how to use
com.amazonaws.ClientConfiguration#setProxyPort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwsModuleTest.java From beam with Apache License 2.0 | 6 votes |
@Test public void testClientConfigurationSerializationDeserialization() throws Exception { ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost("localhost"); clientConfiguration.setProxyPort(1234); clientConfiguration.setProxyUsername("username"); clientConfiguration.setProxyPassword("password"); final String valueAsJson = objectMapper.writeValueAsString(clientConfiguration); final ClientConfiguration valueDes = objectMapper.readValue(valueAsJson, ClientConfiguration.class); assertEquals("localhost", valueDes.getProxyHost()); assertEquals(1234, valueDes.getProxyPort()); assertEquals("username", valueDes.getProxyUsername()); assertEquals("password", valueDes.getProxyPassword()); }
Example 2
Source File: S3Accessor.java From datacollector with Apache License 2.0 | 6 votes |
ClientConfiguration createClientConfiguration() throws StageException { ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setConnectionTimeout(connectionConfigs.getConnectionTimeoutMillis()); clientConfig.setSocketTimeout(connectionConfigs.getSocketTimeoutMillis()); clientConfig.withMaxErrorRetry(connectionConfigs.getMaxErrorRetry()); if (connectionConfigs.isProxyEnabled()) { clientConfig.setProxyHost(connectionConfigs.getProxyHost()); clientConfig.setProxyPort(connectionConfigs.getProxyPort()); if (connectionConfigs.isProxyAuthenticationEnabled()) { clientConfig.setProxyUsername(connectionConfigs.getProxyUser().get()); clientConfig.setProxyPassword(connectionConfigs.getProxyPassword().get()); } } return clientConfig; }
Example 3
Source File: AWSUtil.java From datacollector with Apache License 2.0 | 6 votes |
public static ClientConfiguration getClientConfiguration(ProxyConfig config) throws StageException { ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.setConnectionTimeout(config.connectionTimeout * MILLIS); clientConfig.setSocketTimeout(config.socketTimeout * MILLIS); clientConfig.withMaxErrorRetry(config.retryCount); // Optional proxy settings if (config.useProxy) { if (config.proxyHost != null && !config.proxyHost.isEmpty()) { clientConfig.setProxyHost(config.proxyHost); clientConfig.setProxyPort(config.proxyPort); if (config.proxyUser != null && !config.proxyUser.get().isEmpty()) { clientConfig.setProxyUsername(config.proxyUser.get()); } if (config.proxyPassword != null) { clientConfig.setProxyPassword(config.proxyPassword.get()); } } } return clientConfig; }
Example 4
Source File: StsDaoImpl.java From herd with Apache License 2.0 | 6 votes |
/** * Returns a set of temporary security credentials (consisting of an access key ID, a secret access key, and a security token) that can be used to access * the specified AWS resource. * * @param sessionName the session name that will be associated with the temporary credentials. The session name must be the same for an initial set of * credentials and an extended set of credentials if credentials are to be refreshed. The session name also is used to identify the user in AWS logs so it * should be something unique and useful to identify the caller/use. * @param awsRoleArn the AWS ARN for the role required to provide access to the specified AWS resource * @param awsRoleDurationSeconds the duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) to 3600 seconds (1 hour). * @param policy the temporary policy to apply to this request * * @return the assumed session credentials */ @Override public Credentials getTemporarySecurityCredentials(AwsParamsDto awsParamsDto, String sessionName, String awsRoleArn, int awsRoleDurationSeconds, Policy policy) { // Construct a new AWS security token service client using the specified client configuration to access Amazon S3. // A credentials provider chain will be used that searches for credentials in this order: // - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY // - Java System Properties - aws.accessKeyId and aws.secretKey // - Instance Profile Credentials - delivered through the Amazon EC2 metadata service ClientConfiguration clientConfiguration = new ClientConfiguration().withRetryPolicy(retryPolicyFactory.getRetryPolicy()); // Only set the proxy hostname and/or port if they're configured. if (StringUtils.isNotBlank(awsParamsDto.getHttpProxyHost())) { clientConfiguration.setProxyHost(awsParamsDto.getHttpProxyHost()); } if (awsParamsDto.getHttpProxyPort() != null) { clientConfiguration.setProxyPort(awsParamsDto.getHttpProxyPort()); } AWSSecurityTokenServiceClient awsSecurityTokenServiceClient = new AWSSecurityTokenServiceClient(clientConfiguration); // Create the request. AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest(); assumeRoleRequest.setRoleSessionName(sessionName); assumeRoleRequest.setRoleArn(awsRoleArn); assumeRoleRequest.setDurationSeconds(awsRoleDurationSeconds); if (policy != null) { assumeRoleRequest.setPolicy(policy.toJson()); } // Get the temporary security credentials. AssumeRoleResult assumeRoleResult = stsOperations.assumeRole(awsSecurityTokenServiceClient, assumeRoleRequest); return assumeRoleResult.getCredentials(); }
Example 5
Source File: AmazonAwsClientFactory.java From primecloud-controller with GNU General Public License v2.0 | 6 votes |
protected ClientConfiguration createConfiguration() { ClientConfiguration configuration = new ClientConfiguration(); // Proxy設定 if (proxyHost != null && proxyPort != null) { configuration.setProxyHost(proxyHost); configuration.setProxyPort(proxyPort); if (proxyUser != null && proxyPassword != null) { configuration.setProxyUsername(proxyUser); configuration.setProxyPassword(proxyPassword); } } // リトライしない configuration.setMaxErrorRetry(0); return configuration; }
Example 6
Source File: S3Service.java From crate with Apache License 2.0 | 6 votes |
static ClientConfiguration buildConfiguration(S3ClientSettings clientSettings) { final ClientConfiguration clientConfiguration = new ClientConfiguration(); // the response metadata cache is only there for diagnostics purposes, // but can force objects from every response to the old generation. clientConfiguration.setResponseMetadataCacheSize(0); clientConfiguration.setProtocol(clientSettings.protocol); if (Strings.hasText(clientSettings.proxyHost)) { // TODO: remove this leniency, these settings should exist together and be validated clientConfiguration.setProxyHost(clientSettings.proxyHost); clientConfiguration.setProxyPort(clientSettings.proxyPort); clientConfiguration.setProxyUsername(clientSettings.proxyUsername); clientConfiguration.setProxyPassword(clientSettings.proxyPassword); } clientConfiguration.setMaxErrorRetry(clientSettings.maxRetries); clientConfiguration.setUseThrottleRetries(clientSettings.throttleRetries); clientConfiguration.setSocketTimeout(clientSettings.readTimeoutMillis); return clientConfiguration; }
Example 7
Source File: PropertyBasedS3ClientConfig.java From exhibitor with Apache License 2.0 | 6 votes |
@Override public ClientConfiguration getAWSClientConfig() { ClientConfiguration awsClientConfig = new ClientConfiguration(); awsClientConfig.setProxyHost(proxyHost); awsClientConfig.setProxyPort(proxyPort); if ( proxyUsername != null ) { awsClientConfig.setProxyUsername(proxyUsername); } if ( proxyPassword != null ) { awsClientConfig.setProxyPassword(proxyPassword); } return awsClientConfig; }
Example 8
Source File: AWSClientFactory.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 6 votes |
private ClientConfiguration getClientConfiguration() { String projectVersion = ""; try(InputStream stream = this.getClass().getResourceAsStream(POM_PROPERTIES)) { properties.load(stream); projectVersion = "/" + properties.getProperty("version"); } catch (IOException e) {} ClientConfiguration clientConfig = new ClientConfiguration() .withUserAgentPrefix("CodeBuild-Jenkins-Plugin" + projectVersion) .withProxyHost(proxyHost) .withRetryPolicy(new RetryPolicy(new CodeBuildClientRetryCondition(), new PredefinedBackoffStrategies.ExponentialBackoffStrategy(10000, 30000), 10, true)); if(proxyPort != null) { clientConfig.setProxyPort(proxyPort); } return clientConfig; }
Example 9
Source File: AwsS3Test.java From ecs-sync with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { Properties syncProperties = TestConfig.getProperties(); endpoint = syncProperties.getProperty(TestConfig.PROP_S3_ENDPOINT); accessKey = syncProperties.getProperty(TestConfig.PROP_S3_ACCESS_KEY_ID); secretKey = syncProperties.getProperty(TestConfig.PROP_S3_SECRET_KEY); region = syncProperties.getProperty(TestConfig.PROP_S3_REGION); String proxyUri = syncProperties.getProperty(TestConfig.PROP_HTTP_PROXY_URI); Assume.assumeNotNull(endpoint, accessKey, secretKey); endpointUri = new URI(endpoint); ClientConfiguration config = new ClientConfiguration().withSignerOverride("S3SignerType"); if (proxyUri != null) { URI uri = new URI(proxyUri); config.setProxyHost(uri.getHost()); config.setProxyPort(uri.getPort()); } AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))) .withClientConfiguration(config) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region)); s3 = builder.build(); }
Example 10
Source File: AmazonWebServiceClientUtil.java From cs-actions with Apache License 2.0 | 6 votes |
public static ClientConfiguration getClientConfiguration(String proxyHost, String proxyPort, String proxyUsername, String proxyPassword, String connectTimeoutMs, String executionTimeoutMs) { ClientConfiguration clientConf = new ClientConfiguration() .withConnectionTimeout(Integer.parseInt(connectTimeoutMs)) .withClientExecutionTimeout(Integer.parseInt(executionTimeoutMs)); if (!StringUtils.isEmpty(proxyHost)) { clientConf.setProxyHost(proxyHost); } if (!StringUtils.isEmpty(proxyPort)) { clientConf.setProxyPort(Integer.parseInt(proxyPort)); } if (!StringUtils.isEmpty(proxyUsername)) { clientConf.setProxyUsername(proxyUsername); } if (!StringUtils.isEmpty(proxyPassword)) { clientConf.setProxyPassword(proxyPassword); } return clientConf; }
Example 11
Source File: AWSClientFactory.java From awseb-deployment-plugin with Apache License 2.0 | 6 votes |
private static AWSClientFactory getClientFactory(AWSCredentialsProvider provider, String awsRegion) { ClientConfiguration clientConfig = new ClientConfiguration(); Jenkins jenkins = Jenkins.get(); if (jenkins.proxy != null) { ProxyConfiguration proxyConfig = jenkins.proxy; clientConfig.setProxyHost(proxyConfig.name); clientConfig.setProxyPort(proxyConfig.port); if (proxyConfig.getUserName() != null) { clientConfig.setProxyUsername(proxyConfig.getUserName()); clientConfig.setProxyPassword(proxyConfig.getPassword()); } } clientConfig.setUserAgentPrefix("ingenieux CloudButler/" + Utils.getVersion()); return new AWSClientFactory(provider, clientConfig, awsRegion); }
Example 12
Source File: HttpUtil.java From snowflake-jdbc with Apache License 2.0 | 5 votes |
public static void setProxyForS3(ClientConfiguration clientConfig) { if (useProxy) { clientConfig.setProxyHost(proxyHost); clientConfig.setProxyPort(proxyPort); clientConfig.setNonProxyHosts(nonProxyHosts); if (!Strings.isNullOrEmpty(proxyUser) && !Strings.isNullOrEmpty(proxyPassword)) { clientConfig.setProxyUsername(proxyUser); clientConfig.setProxyPassword(proxyPassword); } } }
Example 13
Source File: DynamoDBClient.java From emr-dynamodb-connector with Apache License 2.0 | 5 votes |
@VisibleForTesting void applyProxyConfiguration(ClientConfiguration clientConfig, Configuration conf) { final String proxyHost = conf.get(DynamoDBConstants.PROXY_HOST); final int proxyPort = conf.getInt(DynamoDBConstants.PROXY_PORT, 0); final String proxyUsername = conf.get(DynamoDBConstants.PROXY_USERNAME); final String proxyPassword = conf.get(DynamoDBConstants.PROXY_PASSWORD); boolean proxyHostAndPortPresent = false; if (!Strings.isNullOrEmpty(proxyHost) && proxyPort > 0) { clientConfig.setProxyHost(proxyHost); clientConfig.setProxyPort(proxyPort); proxyHostAndPortPresent = true; } else if (Strings.isNullOrEmpty(proxyHost) ^ proxyPort <= 0) { throw new RuntimeException("Only one of proxy host and port are set, when both are required"); } if (!Strings.isNullOrEmpty(proxyUsername) && !Strings.isNullOrEmpty(proxyPassword)) { if (!proxyHostAndPortPresent) { throw new RuntimeException("Proxy host and port must be supplied if proxy username and " + "password are present"); } else { clientConfig.setProxyUsername(proxyUsername); clientConfig.setProxyPassword(proxyPassword); } } else if (Strings.isNullOrEmpty(proxyUsername) ^ Strings.isNullOrEmpty(proxyPassword)) { throw new RuntimeException("Only one of proxy username and password are set, when both are " + "required"); } }
Example 14
Source File: AwsEc2ServiceImpl.java From crate with Apache License 2.0 | 5 votes |
static ClientConfiguration buildConfiguration(Logger logger, Ec2ClientSettings clientSettings) { final ClientConfiguration clientConfiguration = new ClientConfiguration(); // the response metadata cache is only there for diagnostics purposes, // but can force objects from every response to the old generation. clientConfiguration.setResponseMetadataCacheSize(0); clientConfiguration.setProtocol(clientSettings.protocol); if (Strings.hasText(clientSettings.proxyHost)) { // TODO: remove this leniency, these settings should exist together and be validated clientConfiguration.setProxyHost(clientSettings.proxyHost); clientConfiguration.setProxyPort(clientSettings.proxyPort); clientConfiguration.setProxyUsername(clientSettings.proxyUsername); clientConfiguration.setProxyPassword(clientSettings.proxyPassword); } // Increase the number of retries in case of 5xx API responses final Random rand = Randomness.get(); final RetryPolicy retryPolicy = new RetryPolicy( RetryPolicy.RetryCondition.NO_RETRY_CONDITION, (originalRequest, exception, retriesAttempted) -> { // with 10 retries the max delay time is 320s/320000ms (10 * 2^5 * 1 * 1000) logger.warn("EC2 API request failed, retry again. Reason was:", exception); return 1000L * (long) (10d * Math.pow(2, retriesAttempted / 2.0d) * (1.0d + rand.nextDouble())); }, 10, false); clientConfiguration.setRetryPolicy(retryPolicy); clientConfiguration.setSocketTimeout(clientSettings.readTimeoutMillis); return clientConfiguration; }
Example 15
Source File: InvocationClientConfig.java From kafka-connect-lambda with Apache License 2.0 | 5 votes |
ClientConfiguration loadAwsClientConfiguration() { ClientConfiguration clientConfiguration = new ClientConfiguration(); String httpProxyHost = this.getString(HTTP_PROXY_HOST_KEY); if (httpProxyHost != null && !httpProxyHost.isEmpty()) { clientConfiguration.setProxyHost(httpProxyHost); Integer httpProxyPort = this.getInt(HTTP_PROXY_PORT_KEY); if (httpProxyPort > 0) clientConfiguration.setProxyPort(httpProxyPort); } return clientConfiguration; }
Example 16
Source File: CodeBuildBaseCredentials.java From aws-codebuild-jenkins-plugin with Apache License 2.0 | 5 votes |
private ClientConfiguration getClientConfiguration(String proxyHost, String proxyPort) { ClientConfiguration clientConfig = new ClientConfiguration(); if (!proxyHost.isEmpty()) { clientConfig.withProxyHost(proxyHost); } if (!proxyPort.isEmpty()) { clientConfig.setProxyPort(Validation.parseInt(proxyPort)); } return clientConfig; }
Example 17
Source File: AwsClientConfiguration.java From s3-cf-service-broker with Apache License 2.0 | 5 votes |
public ClientConfiguration toClientConfiguration(){ ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProxyHost(proxyHost); if(proxyPort != null) { clientConfiguration.setProxyPort(Integer.parseInt(proxyPort)); } clientConfiguration.setProxyUsername(proxyUsername); clientConfiguration.setProxyPassword(proxyPassword); if(preemptiveBasicProxyAuth != null) { clientConfiguration.setPreemptiveBasicProxyAuth(preemptiveBasicProxyAuth); } return clientConfiguration; }
Example 18
Source File: Aws.java From digdag with Apache License 2.0 | 5 votes |
static void configureProxy(ClientConfiguration configuration, ProxyConfig proxyConfig) { configuration.setProxyHost(proxyConfig.getHost()); configuration.setProxyPort(proxyConfig.getPort()); Optional<String> user = proxyConfig.getUser(); if (user.isPresent()) { configuration.setProxyUsername(user.get()); } Optional<String> password = proxyConfig.getPassword(); if (password.isPresent()) { configuration.setProxyPassword(password.get()); } }
Example 19
Source File: AWSClients.java From aws-codedeploy-plugin with Apache License 2.0 | 5 votes |
/** * Via the default provider chain (i.e., global keys for this Jenkins instance), return the account ID for the * currently authenticated user. * @param proxyHost hostname of the proxy to use (if any) * @param proxyPort port of the proxy to use (if any) * @return 12-digit account id */ public static String getAccountId(String proxyHost, int proxyPort) { String arn = ""; try { ClientConfiguration clientCfg = new ClientConfiguration(); if (proxyHost != null && proxyPort > 0 ) { clientCfg.setProxyHost(proxyHost); clientCfg.setProxyPort(proxyPort); } AmazonIdentityManagementClient iam = new AmazonIdentityManagementClient(clientCfg); GetUserResult user = iam.getUser(); arn = user.getUser().getArn(); } catch (AmazonServiceException e) { if (e.getErrorCode().compareTo("AccessDenied") == 0) { String msg = e.getMessage(); int arnIdx = msg.indexOf("arn:aws"); if (arnIdx != -1) { int arnSpace = msg.indexOf(" ", arnIdx); arn = msg.substring(arnIdx, arnSpace); } } } String accountId = arn.split(":")[ARN_ACCOUNT_ID_INDEX]; return accountId; }
Example 20
Source File: ECSService.java From amazon-ecs-plugin with MIT License | 5 votes |
public ECSService(String credentialsId, String regionName) { this.clientSupplier = () -> { ProxyConfiguration proxy = Jenkins.get().proxy; ClientConfiguration clientConfiguration = new ClientConfiguration(); if (proxy != null) { clientConfiguration.setProxyHost(proxy.name); clientConfiguration.setProxyPort(proxy.port); clientConfiguration.setProxyUsername(proxy.getUserName()); clientConfiguration.setProxyPassword(proxy.getPassword()); } // Default is 3. 10 helps us actually utilize the SDK's backoff strategy // The strategy will wait up to 20 seconds per request (after multiple failures) clientConfiguration.setMaxErrorRetry(10); AmazonECSClientBuilder builder = AmazonECSClientBuilder .standard() .withClientConfiguration(clientConfiguration) .withRegion(regionName); AmazonWebServicesCredentials credentials = getCredentials(credentialsId); if (credentials != null) { if (LOGGER.isLoggable(Level.FINE)) { String awsAccessKeyId = credentials.getCredentials().getAWSAccessKeyId(); String obfuscatedAccessKeyId = StringUtils.left(awsAccessKeyId, 4) + StringUtils.repeat("*", awsAccessKeyId.length() - (2 * 4)) + StringUtils.right(awsAccessKeyId, 4); LOGGER.log(Level.FINE, "Connect to Amazon ECS with IAM Access Key {1}", new Object[]{obfuscatedAccessKeyId}); } builder .withCredentials(credentials); } LOGGER.log(Level.FINE, "Selected Region: {0}", regionName); return builder.build(); }; }