<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(); } }
@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(); }
LOGGER.error(e.getMessage(), e); builder.withClientConfiguration(cfg);