Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ldetmer committed Sep 17, 2024
1 parent a72e2ce commit 615362d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static ClientContext create(StubSettings settings) throws IOException {
Credentials credentials = settings.getCredentialsProvider().getCredentials();
if (apiKey != null && credentials != null) {
throw new IllegalArgumentException(
"You can not provide both ApiKey and Credentials for a client.");
"You can not provide both ApiKey and Credentials for a client.");
}
if (apiKey != null) {
// if API key exists it becomes the default credential
Expand Down Expand Up @@ -234,7 +234,6 @@ public static ClientContext create(StubSettings settings) throws IOException {

ApiCallContext defaultCallContext =
transportChannel.getEmptyCallContext().withTransportChannel(transportChannel);

if (credentials != null) {
defaultCallContext = defaultCallContext.withCredentials(credentials);
}
Expand Down Expand Up @@ -293,7 +292,11 @@ public static ClientContext create(StubSettings settings) throws IOException {
.build();
}

private static Credentials getGdchCredentials(String settingsGdchApiAudience, String endpoint, Credentials credentials) throws IOException {
/**
* Constructs a new {@link Credentials} object based on credentials provided with a GDC-H audience
*/
private static Credentials getGdchCredentials(
String settingsGdchApiAudience, String endpoint, Credentials credentials) throws IOException {
String audienceString;
if (!Strings.isNullOrEmpty(settingsGdchApiAudience)) {
audienceString = settingsGdchApiAudience;
Expand All @@ -307,8 +310,7 @@ private static Credentials getGdchCredentials(String settingsGdchApiAudience, St
try {
gdchAudienceUri = URI.create(audienceString);
} catch (IllegalArgumentException ex) { // thrown when passing a malformed uri string
throw new IllegalArgumentException(
"The GDC-H API audience string is not a valid URI", ex);
throw new IllegalArgumentException("The GDC-H API audience string is not a valid URI", ex);
}
credentials = ((GdchCredentials) credentials).createWithGdchAudience(gdchAudienceUri);
return credentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public final StubSettings getStubSettings() {
return stubSettings;
}

/**
* @deprecated Please use {@link #getBackgroundExecutorProvider()}
*/
/** @deprecated Please use {@link #getBackgroundExecutorProvider()} */
@Deprecated
public final ExecutorProvider getExecutorProvider() {
return stubSettings.getExecutorProvider();
Expand Down Expand Up @@ -314,6 +312,8 @@ public B setGdchApiAudience(@Nullable String gdchApiAudience) {
/**
* Sets the API key. The API key will get translated to an [ApiKeyCredentials] and stored in
* [CallContext].
*
* Note: you can not set an API key and credentials object in the same Settings. It will fail when creating the client.
*/
public B setApiKey(String apiKey) {
stubSettings.setApiKey(apiKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ private EndpointContext buildEndpointContext(Builder builder) {
}
}

/**
* @deprecated Please use {@link #getBackgroundExecutorProvider()}.
*/
/** @deprecated Please use {@link #getBackgroundExecutorProvider()}. */
@Deprecated
public final ExecutorProvider getExecutorProvider() {
return deprecatedExecutorProviderSet ? backgroundExecutorProvider : null;
Expand Down Expand Up @@ -176,23 +174,17 @@ protected String getServiceName() {
return "";
}

/**
* @return the fully resolved universe domain used by the client
*/
/** @return the fully resolved universe domain used by the client */
public final String getUniverseDomain() {
return endpointContext.resolvedUniverseDomain();
}

/**
* @return the fully resolved endpoint used by the client
*/
/** @return the fully resolved endpoint used by the client */
public String getEndpoint() {
return endpointContext.resolvedEndpoint();
}

/**
* @return the newly created EndpointContext
*/
/** @return the newly created EndpointContext */
@InternalApi
final EndpointContext getEndpointContext() {
return endpointContext;
Expand Down Expand Up @@ -605,9 +597,7 @@ public B setApiKey(String apiKey) {
return self();
}

/**
* @deprecated Please use {@link #getBackgroundExecutorProvider()}.
*/
/** @deprecated Please use {@link #getBackgroundExecutorProvider()}. */
@Deprecated
public ExecutorProvider getExecutorProvider() {
return deprecatedExecutorProviderSet ? backgroundExecutorProvider : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import org.apache.http.impl.client.SystemDefaultCredentialsProvider;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

Expand Down Expand Up @@ -1080,7 +1078,6 @@ public void testSetApiKey_createsApiCredentials() throws IOException {
new FakeTransportProvider(
transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT);
builder.setTransportChannelProvider(transportProvider);

HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of());
builder.setHeaderProvider(headerProvider);
Expand All @@ -1099,22 +1096,21 @@ void testCreateClient_throwsErrorIfApiKeyAndCredentialsAreProvided() throws Exce
InterceptingExecutor executor = new InterceptingExecutor(1);
FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
FakeTransportProvider transportProvider =
new FakeTransportProvider(
transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT);
new FakeTransportProvider(
transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT);
builder.setTransportChannelProvider(transportProvider);

HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of());
builder.setHeaderProvider(headerProvider);
builder.setApiKey(apiKey);
builder.setCredentialsProvider(Mockito.mock(CredentialsProvider.class));

try {
ClientContext context = ClientContext.create(builder.build());
ClientContext.create(builder.build());
fail("No exception raised");
} catch (IllegalArgumentException e) {
assert(
e.getMessage().contains("You can not provide both ApiKey and Credentials for a client."));
assert (e.getMessage()
.contains("You can not provide both ApiKey and Credentials for a client."));
}
}
}

0 comments on commit 615362d

Please sign in to comment.