/** * 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 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)); }
/** * 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()); }
/** * 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 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)); }
/** * 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()); }
/** * 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 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(RegionUtils.getRegion(region)); }
protected void configureClient(AwsClientBuilder clientBuilder) { clientBuilder.withCredentials(credentialsProvider).withRegion(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. * * <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()); }
public <T, B extends AwsClientBuilder<B, T>> T create(final AwsClientBuilder<B, T> builder) { return builder // .withCredentials(credentialsProvider) // .withRegion(region) // .build(); } }
<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(); } }
@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(); }
@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 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); } };
public AwsClientBuilder configure(AwsClientBuilder b) { b = b.withRegion(Regions.fromName(region.getName())).withCredentials(getCredentialsProvider()); if (clientConfiguration != null) { b = b.withClientConfiguration(clientConfiguration); } return b; }
@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(); }
builder.withRegion(finalRegion);