/** * Sets the region to be used by the client. This will be used to determine both the * service endpoint (eg: https://sns.us-west-1.amazonaws.com) and signing region (eg: us-west-1) * for requests. If neither region or endpoint configuration {@link #setEndpointConfiguration(EndpointConfiguration)} * are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * @param region Region to use */ public final void setRegion(String region) { withRegion(region); }
/** * Sets the endpoint configuration (service endpoint & signing region) to be used for requests. If neither region {@link #setRegion(String)} * or endpoint configuration are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * <p><b>Only use this if using a non-standard service endpoint - the recommended approach for configuring a client is to use {@link #setRegion(String)}</b> * * @param endpointConfiguration The endpointConfiguration to use */ public final void setEndpointConfiguration(EndpointConfiguration endpointConfiguration) { withEndpointConfiguration(endpointConfiguration); }
private void setRegion(AmazonWebServiceClient client) { if (region != null && endpointConfiguration != null) { throw new IllegalStateException("Only one of Region or EndpointConfiguration may be set."); } if (endpointConfiguration != null) { client.setEndpoint(endpointConfiguration.getServiceEndpoint()); client.setSignerRegionOverride(endpointConfiguration.getSigningRegion()); } else if (region != null) { client.setRegion(region); } else { final String region = determineRegionFromRegionProvider(); if (region != null) { client.setRegion(getRegionObject(region)); } else { throw new SdkClientException( "Unable to find a region via the region provider chain. " + "Must provide an explicit region in the builder or setup environment to supply a region."); } } }
/** * Sets the region to be used by the client. This will be used to determine both the * service endpoint (eg: https://sns.us-west-1.amazonaws.com) and signing region (eg: us-west-1) * for requests. If neither region or endpoint configuration {@link #setEndpointConfiguration(EndpointConfiguration)} * are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * @param region Region to use * @return This object for method chaining. */ public final Subclass withRegion(String region) { return withRegion(getRegionObject(region)); }
<R, T extends AwsClientBuilder<T, R>> R createClient(final T builder, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration clientConfiguration, final String endpointUrl, final String region) { if (credentialsProvider != null) { builder.withCredentials(credentialsProvider); } if (clientConfiguration != null) { builder.withClientConfiguration(clientConfiguration); } if (StringUtils.isNotEmpty(endpointUrl)) { LOG.warn("Received configuration for endpoint as " + endpointUrl + ", and region as " + region + "."); builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpointUrl, region)); } else if (StringUtils.isNotEmpty(region)) { LOG.warn("Received configuration for region as " + region + "."); builder.withRegion(region); } else { LOG.warn("No configuration received for endpoint and region, will default region to us-east-1"); builder.withRegion(Regions.US_EAST_1); } return builder.build(); } }
public <T, B extends AwsClientBuilder<B, T>> T create(final AwsClientBuilder<B, T> builder) { return builder // .withCredentials(credentialsProvider) // .withRegion(region) // .build(); } }
public AwsClientBuilder configure(AwsClientBuilder b) { b = b.withRegion(Regions.fromName(region.getName())).withCredentials(getCredentialsProvider()); if (clientConfiguration != null) { b = b.withClientConfiguration(clientConfiguration); } return b; }
protected void configureClient(AwsClientBuilder clientBuilder) { clientBuilder.withCredentials(credentialsProvider).withRegion(region); }
protected T createClient(Class<T> clazz) { try { String builderClass = clazz.getName() + "Builder"; Class<?> builderClazz = Class.forName(builderClass); Method m = builderClazz.getMethod("standard"); return clazz.cast(builder.configure((AwsSyncClientBuilder<?, ?>) m.invoke(null)).build()); } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new MercatorException(e); } }
private void setRegion(AmazonWebServiceClient client) { if (region != null && endpointConfiguration != null) { throw new IllegalStateException("Only one of Region or EndpointConfiguration may be set."); } if (endpointConfiguration != null) { client.setEndpoint(endpointConfiguration.getServiceEndpoint()); client.setSignerRegionOverride(endpointConfiguration.getSigningRegion()); } else if (region != null) { client.setRegion(region); } else { final String region = determineRegionFromRegionProvider(); if (region != null) { client.setRegion(RegionUtils.getRegion(region)); } else { throw new SdkClientException( "Unable to find a region via the region provider chain. " + "Must provide an explicit region in the builder or setup environment to supply a region."); } } }
@Override public CacheValue load(@Nonnull final Key<?> key) { log.debug("Creating a new AmazonWebServiceClient client for {}", key); final STSAssumeRoleSessionCredentialsProvider tempCredentials = new STSAssumeRoleSessionCredentialsProvider .Builder(buildRoleArn(key.accountId), ROLE_SESSION_NAME).withStsClient(awsSecurityTokenService) .build(); final String builderName = key.type.getName() + "Builder"; final Class<?> className = ClassUtils.resolveClassName(builderName, ClassUtils.getDefaultClassLoader()); final Method method = ClassUtils.getStaticMethod(className, "standard"); Assert.notNull(method, "Could not find standard() method in class:'" + className.getName() + "'"); final AwsClientBuilder<?, ?> builder = (AwsClientBuilder<?, ?>) ReflectionUtils.invokeMethod(method, null); builder.withCredentials(tempCredentials); builder.withRegion(key.region.getName()); builder.withClientConfiguration(new ClientConfiguration().withMaxErrorRetry(MAX_ERROR_RETRY)); final AmazonWebServiceClient client = (AmazonWebServiceClient) builder.build(); return new CacheValue(client, tempCredentials); } };
@SuppressWarnings("unchecked") @Override protected T createInstance() throws Exception { String builderName = this.clientClass.getName() + "Builder"; Class<?> className = ClassUtils.resolveClassName(builderName, ClassUtils.getDefaultClassLoader()); Method method = ClassUtils.getStaticMethod(className, "standard"); Assert.notNull(method, "Could not find standard() method in class:'" + className.getName() + "'"); AwsClientBuilder<?, T> builder = (AwsClientBuilder<?, T>) ReflectionUtils.invokeMethod(method, null); if (this.executor != null) { AwsAsyncClientBuilder<?, T> asyncBuilder = (AwsAsyncClientBuilder<?, T>) builder; asyncBuilder.withExecutorFactory((ExecutorFactory) () -> this.executor); } if (this.credentialsProvider != null) { builder.withCredentials(this.credentialsProvider); } if (this.customRegion != null) { builder.withRegion(this.customRegion.getName()); } else if (this.regionProvider != null) { builder.withRegion(this.regionProvider.getRegion().getName()); } else { builder.withRegion(Regions.DEFAULT_REGION); } return builder.build(); }
@Override protected AmazonKinesisClient createClient() { return (AmazonKinesisClient) builder.configure(AmazonKinesisClientBuilder .standard()).build(); }
/** * Sets the region to be used by the client. This will be used to determine both the * service endpoint (eg: https://sns.us-west-1.amazonaws.com) and signing region (eg: us-west-1) * for requests. If neither region or endpoint configuration {@link #setEndpointConfiguration(EndpointConfiguration)} * are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * @param region Region to use * @return This object for method chaining. */ public final Subclass withRegion(String region) { return withRegion(getRegionObject(region)); }
@Override public Object load(AmazonClientKey<?> key) throws Exception { Method m = key.implClass.getDeclaredMethod("standard"); AwsClientBuilder<?, ?> builder = key.implClass.cast(m.invoke(null)); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setRetryPolicy(getRetryPolicy(key)); clientConfiguration.setUseGzip(useGzip); clientConfiguration.setUserAgentSuffix("spinnaker"); if (proxy != null && proxy.isProxyConfigMode()) { proxy.apply(clientConfiguration); } builder.withCredentials(key.awsCredentialsProvider) .withClientConfiguration(clientConfiguration); getRequestHandlers(key).ifPresent(builder::withRequestHandlers); builder.withRegion(key.getRegion().orElseGet(() -> new SpinnakerAwsRegionProvider().getRegion())); return builder.build(); }
@SuppressWarnings("unchecked") @Override protected T createInstance() throws Exception { String builderName = this.clientClass.getName() + "Builder"; Class<?> className = ClassUtils.resolveClassName(builderName, ClassUtils.getDefaultClassLoader()); Method method = ClassUtils.getStaticMethod(className, "standard"); Assert.notNull(method, "Could not find standard() method in class:'" + className.getName() + "'"); AwsClientBuilder<?, T> builder = (AwsClientBuilder<?, T>) ReflectionUtils.invokeMethod(method, null); if (this.executor != null) { AwsAsyncClientBuilder<?, T> asyncBuilder = (AwsAsyncClientBuilder<?, T>) builder; asyncBuilder.withExecutorFactory((ExecutorFactory) () -> this.executor); } if (this.credentialsProvider != null) { builder.withCredentials(this.credentialsProvider); } if (this.customRegion != null) { builder.withRegion(this.customRegion.getName()); } else if (this.regionProvider != null) { builder.withRegion(this.regionProvider.getRegion().getName()); } else { builder.withRegion(Regions.DEFAULT_REGION); } return builder.build(); }
/** * Sets the region to be used by the client. This will be used to determine both the * service endpoint (eg: https://sns.us-west-1.amazonaws.com) and signing region (eg: us-west-1) * for requests. If neither region or endpoint configuration {@link #setEndpointConfiguration(EndpointConfiguration)} * are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * <p> For regions not explicitly in the {@link Regions} enum use the {@link * #withRegion(String)} overload.</p> * * @param region Region to use * @return This object for method chaining. */ public final Subclass withRegion(Regions region) { return withRegion(region.getName()); }
@Override protected AmazonRDSClient createClient() { return (AmazonRDSClient) builder.configure(AmazonRDSClientBuilder .standard()).build(); }
/** * Sets the endpoint configuration (service endpoint & signing region) to be used for requests. If neither region {@link #setRegion(String)} * or endpoint configuration are explicitly provided in the builder the {@link #DEFAULT_REGION_PROVIDER} is consulted. * * <p><b>Only use this if using a non-standard service endpoint - the recommended approach for configuring a client is to use {@link #setRegion(String)}</b> * * @param endpointConfiguration The endpointConfiguration to use */ public final void setEndpointConfiguration(EndpointConfiguration endpointConfiguration) { withEndpointConfiguration(endpointConfiguration); }
private void setRegion(AmazonWebServiceClient client) { if (region != null && endpointConfiguration != null) { throw new IllegalStateException("Only one of Region or EndpointConfiguration may be set."); } if (endpointConfiguration != null) { client.setEndpoint(endpointConfiguration.getServiceEndpoint()); client.setSignerRegionOverride(endpointConfiguration.getSigningRegion()); } else if (region != null) { client.setRegion(region); } else { final String region = determineRegionFromRegionProvider(); if (region != null) { client.setRegion(getRegionObject(region)); } else { throw new SdkClientException( "Unable to find a region via the region provider chain. " + "Must provide an explicit region in the builder or setup environment to supply a region."); } } }