Skip to content

Commit

Permalink
Remove unnecessary credentials retrieval (#34)
Browse files Browse the repository at this point in the history
Just overriding the signer to a no-op signer in client config still
causes the default credentials provider chain to be invoked and fail in
the absence of credentials obtainable by the default chain. Instead,
build the client with anonymous credentials, which skips both signing
and credentials retrieval.
  • Loading branch information
aapolait authored and haotianw465 committed Oct 13, 2018
1 parent 823620d commit 901f2f9
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package com.amazonaws.xray.strategy.sampling;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.SignerFactory;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.xray.AWSXRayClientBuilder;
import com.amazonaws.services.xray.AWSXRay;
import com.amazonaws.xray.config.DaemonConfiguration;

public final class XRayClient {

private static final String DUMMY_REGION = "us-west-1"; // Ignored because we use a No-op signer
private static final AWSCredentialsProvider ANONYMOUS_CREDENTIALS = new AWSStaticCredentialsProvider(
new AnonymousAWSCredentials());
private static final String DUMMY_REGION = "us-west-1"; // Ignored because we use anonymous credentials
private static final int TIME_OUT = 2000; // Milliseconds
private XRayClient() {}

public static AWSXRay newClient() {
DaemonConfiguration config = new DaemonConfiguration();

ClientConfiguration clientConfig = new ClientConfiguration()
.withSignerOverride(SignerFactory.NO_OP_SIGNER)
.withRequestTimeout(TIME_OUT);

AwsClientBuilder.EndpointConfiguration endpointConfig = new AwsClientBuilder.EndpointConfiguration(
Expand All @@ -28,6 +31,7 @@ public static AWSXRay newClient() {
return AWSXRayClientBuilder.standard()
.withEndpointConfiguration(endpointConfig)
.withClientConfiguration(clientConfig)
.withCredentials(ANONYMOUS_CREDENTIALS) // This will entirely skip signing too
.build();

}
Expand Down

0 comments on commit 901f2f9

Please sign in to comment.