Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support GDC-H Credentials #1642

Merged
merged 54 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
80f7327
chore: initial additions to handle GDC-H API audience
diegomarquezp Apr 14, 2023
110f043
chore: add unit tests for GDC-H
diegomarquezp Apr 20, 2023
7385189
chore: cleanup of logic
diegomarquezp May 3, 2023
032af75
chore: decompose tests into separate methods
diegomarquezp May 3, 2023
6cc7f6b
chore: fix clirr diff check
diegomarquezp May 3, 2023
78df0fd
chore: fmt:format
diegomarquezp May 3, 2023
f5b9d99
chore: add support in `ClientSettings`
diegomarquezp May 17, 2023
5f149db
Merge remote-tracking branch 'origin/main' into gdc-h
diegomarquezp May 18, 2023
bbde736
chore: add showcase IT for GDCH credentials
diegomarquezp May 18, 2023
8fb9ced
chore: comments
diegomarquezp May 18, 2023
ea4a03c
chore: improve tests
diegomarquezp May 18, 2023
ea05922
chore: add partial IT for testing context credential
diegomarquezp May 23, 2023
5cbf2b2
chore: recreate GdchCredentials with audience using convenience method
diegomarquezp May 24, 2023
40f21a5
chore: more readable api audience logic
diegomarquezp May 24, 2023
27cb7c7
chore: no wildcard imports
diegomarquezp May 24, 2023
bd44dd1
chore: javadoc for public methods
diegomarquezp May 24, 2023
c5cac43
chore: gdch test to use default null initialization
diegomarquezp May 24, 2023
f1b5cbf
chore: tear down for gdch IT
diegomarquezp May 24, 2023
5e2af11
chore: `assertThrows` for gdch ITs
diegomarquezp May 24, 2023
a3a0f4b
chore: mvn fmt:format
diegomarquezp May 24, 2023
ef540ad
test: remove context test
diegomarquezp May 25, 2023
d1b7b92
docs: explain that audience will be overriden if set through client/s…
diegomarquezp May 25, 2023
ce57a76
test: test audience setting should modify initial credentials
diegomarquezp May 26, 2023
524712a
Merge branch 'main' into gdc-h
diegomarquezp May 26, 2023
33e95ec
chore: clirr check
diegomarquezp May 26, 2023
44e5369
Merge branch 'gdc-h' of https://github.com/googleapis/gapic-generator…
diegomarquezp May 26, 2023
32e175f
chore: ignore gdch changes
diegomarquezp May 26, 2023
f3c2a0a
chore: format
diegomarquezp May 26, 2023
a297a16
chore: default to endpoint if audience not provided
diegomarquezp Jun 14, 2023
1e5cac4
test: refresh gdch creds to confirm audience works
diegomarquezp Jun 20, 2023
80f1821
Merge branch 'main' into gdc-h
diegomarquezp Jun 21, 2023
1875523
chore: fmt
diegomarquezp Jun 21, 2023
f38a76b
Merge remote-tracking branch 'origin/gdc-h' into gdc-h
diegomarquezp Jun 21, 2023
3360925
chore: fmt
diegomarquezp Jun 21, 2023
1608cc2
chore: better test names in ClientContextTest
diegomarquezp Jun 21, 2023
6f9f4c5
chore: better test names for showcase tests
diegomarquezp Jun 21, 2023
cdfc1ac
chore: simplify refresh verification logic
diegomarquezp Jun 22, 2023
434ee7a
chore: include outcome in gdch it test names
diegomarquezp Jun 22, 2023
f255d09
chore: expand comments in GDCH ITs
diegomarquezp Jun 22, 2023
59b9c26
Merge remote-tracking branch 'origin/main' into gdc-h
diegomarquezp Jun 22, 2023
c42a160
test: intercept mock transport to verify audience
diegomarquezp Jun 23, 2023
0fe4c6b
chore: fmt
diegomarquezp Jun 23, 2023
1c69890
chore: move auth test-jar to shared dependencies
diegomarquezp Jun 23, 2023
a2e6c90
chore: cleanup
diegomarquezp Jun 23, 2023
d6ce65c
chore: use inferred version for auth library
diegomarquezp Jun 27, 2023
60828fe
deps: update google-auth-java-library to 1.19.0
diegomarquezp Jun 28, 2023
e30dabb
choreL fmt ITGdch.java
diegomarquezp Jun 28, 2023
ad0f3ba
chore: import auth test-jar using common version variable
diegomarquezp Jun 28, 2023
4f819b7
chore: remove auth test-jar import from first-party-dependencies
diegomarquezp Jun 28, 2023
95a3568
chore: add license headers to new files
diegomarquezp Jun 28, 2023
5e84582
chore: revert google-auth-version to be obtained from main branch
diegomarquezp Jun 28, 2023
7e7979a
Merge remote-tracking branch 'origin/main' into gdc-h
diegomarquezp Jun 28, 2023
596ff9b
chore: correct showcase parent pom indentation
diegomarquezp Jun 28, 2023
f08dffc
chore: remove resource declaration for native test build
diegomarquezp Jun 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion gapic-generator-java-pom-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
consistent across modules in this repository -->
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<grpc.version>1.55.1</grpc.version>
<google.auth.version>1.18.0</google.auth.version>
<google.auth.version>1.19.0</google.auth.version>
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
<gson.version>2.10.1</gson.version>
<guava.version>32.0.1-jre</guava.version>
<!-- On next protobuf upgrade (to 3.23.3 or higher),
Expand Down
1 change: 1 addition & 0 deletions gax-java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target

# IntelliJ
.idea
.ijwb
*.iml
out

Expand Down
6 changes: 6 additions & 0 deletions gax-java/gax/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<className>com/google/api/gax/paging/Page</className>
<method>* stream*(*)</method>
</difference>
<difference>
<!-- add gdchApiAudience to ClientContext -->
<differenceType>7013</differenceType>
<className>com/google/api/gax/rpc/*</className>
<method>* *Gdch*(*)</method>
</difference>
<difference>
<differenceType>7006</differenceType>
<className>com/google/api/gax/rpc/ServerStreamingCallSettings$Builder</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package com.google.api.gax.rpc;

import com.google.api.client.util.Strings;
import com.google.api.core.ApiClock;
import com.google.api.core.BetaApi;
import com.google.api.core.NanoClock;
Expand All @@ -40,11 +41,13 @@
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.auth.Credentials;
import com.google.auth.oauth2.GdchCredentials;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -109,6 +112,13 @@ public abstract class ClientContext {
@Nonnull
public abstract ApiTracerFactory getTracerFactory();

/**
* Gets the API audience used when creating a Client that uses {@link
* com.google.auth.oauth2.GdchCredentials}
*/
@Nullable
public abstract String getGdchApiAudience();

public static Builder newBuilder() {
return new AutoValue_ClientContext.Builder()
.setBackgroundResources(Collections.<BackgroundResource>emptyList())
Expand All @@ -119,7 +129,8 @@ public static Builder newBuilder() {
.setStreamWatchdog(null)
.setStreamWatchdogCheckInterval(Duration.ZERO)
.setTracerFactory(BaseApiTracerFactory.getInstance())
.setQuotaProjectId(null);
.setQuotaProjectId(null)
.setGdchApiAudience(null);
}

public abstract Builder toBuilder();
Expand Down Expand Up @@ -167,6 +178,30 @@ public static ClientContext create(StubSettings settings) throws IOException {

Credentials credentials = settings.getCredentialsProvider().getCredentials();

String settingsGdchApiAudience = settings.getGdchApiAudience();
if (credentials instanceof GdchCredentials) {
// We recompute the GdchCredentials with the audience
String audienceString;
if (!Strings.isNullOrEmpty(settingsGdchApiAudience)) {
audienceString = settingsGdchApiAudience;
} else if (!Strings.isNullOrEmpty(settings.getEndpoint())) {
audienceString = settings.getEndpoint();
} else {
throw new IllegalArgumentException("Could not infer GDCH api audience from settings");
}

URI gdchAudienceUri;
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);
}
credentials = ((GdchCredentials) credentials).createWithGdchAudience(gdchAudienceUri);
} else if (!Strings.isNullOrEmpty(settingsGdchApiAudience)) {
throw new IllegalArgumentException(
"GDC-H API audience can only be set when using GdchCredentials");
}

if (settings.getQuotaProjectId() != null && credentials != null) {
// If the quotaProjectId is set, wrap original credentials with correct quotaProjectId as
// QuotaProjectIdHidingCredentials.
Expand Down Expand Up @@ -325,6 +360,17 @@ public abstract static class Builder {
@BetaApi("The surface for tracing is not stable yet and may change in the future.")
public abstract Builder setTracerFactory(ApiTracerFactory tracerFactory);

/**
* Sets the API audience used by {@link com.google.auth.oauth2.GdchCredentials} It cannot be
* used if other type of {@link com.google.auth.Credentials} is used
*
* <p>If the provided credentials already contain an api audience, it will be overriden by this
* one
*
* @param gdchApiAudience the audience to be used - must be a valid URI string
*/
public abstract Builder setGdchApiAudience(String gdchApiAudience);

public abstract ClientContext build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public final Duration getWatchdogCheckInterval() {
return stubSettings.getStreamWatchdogCheckInterval();
}

/** Gets the GDCH API audience that was previously set in this Builder */
public final String getGdchApiAudience() {
return stubSettings.getGdchApiAudience();
}

public String toString() {
return MoreObjects.toStringHelper(this)
.add("executorProvider", getExecutorProvider())
Expand All @@ -124,6 +129,7 @@ public String toString() {
.add("quotaProjectId", getQuotaProjectId())
.add("watchdogProvider", getWatchdogProvider())
.add("watchdogCheckInterval", getWatchdogCheckInterval())
.add("gdchApiAudience", getGdchApiAudience())
.toString();
}

Expand Down Expand Up @@ -255,6 +261,18 @@ public B setWatchdogCheckInterval(@Nullable Duration checkInterval) {
return self();
}

/**
* Sets the GDC-H api audience. This is intended only to be used with {@link
* com.google.auth.oauth2.GdchCredentials} If this field is set and other type of {@link
* com.google.auth.Credentials} is used then an {@link IllegalArgumentException} will be thrown.
* If the provided credentials already have an api audience, then it will be overriden by this
* audience
*/
public B setGdchApiAudience(@Nullable String gdchApiAudience) {
stubSettings.setGdchApiAudience(gdchApiAudience);
return self();
}

/**
* Gets the ExecutorProvider that was previously set on this Builder. This ExecutorProvider is
* to use for running asynchronous API call logic (such as retries and long-running operations),
Expand Down Expand Up @@ -322,6 +340,12 @@ public Duration getWatchdogCheckInterval() {
return stubSettings.getStreamWatchdogCheckInterval();
}

/** Gets the GDCH API audience that was previously set in this Builder */
@Nullable
public String getGdchApiAudience() {
return stubSettings.getGdchApiAudience();
}

/** Applies the given settings updater function to the given method settings builders. */
protected static void applyToAllUnaryMethods(
Iterable<UnaryCallSettings.Builder<?, ?>> methodSettingsBuilders,
Expand All @@ -344,6 +368,7 @@ public String toString() {
.add("quotaProjectId", getQuotaProjectId())
.add("watchdogProvider", getWatchdogProvider())
.add("watchdogCheckInterval", getWatchdogCheckInterval())
.add("gdchApiAudience", getGdchApiAudience())
.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public abstract class StubSettings<SettingsT extends StubSettings<SettingsT>> {
private final String endpoint;
private final String mtlsEndpoint;
private final String quotaProjectId;
@Nullable private final String gdchApiAudience;
@Nullable private final WatchdogProvider streamWatchdogProvider;
@Nonnull private final Duration streamWatchdogCheckInterval;
@Nonnull private final ApiTracerFactory tracerFactory;
Expand Down Expand Up @@ -103,6 +104,7 @@ protected StubSettings(Builder builder) {
this.streamWatchdogCheckInterval = builder.streamWatchdogCheckInterval;
this.tracerFactory = builder.tracerFactory;
this.deprecatedExecutorProviderSet = builder.deprecatedExecutorProviderSet;
this.gdchApiAudience = builder.gdchApiAudience;
}

/** @deprecated Please use {@link #getBackgroundExecutorProvider()}. */
Expand Down Expand Up @@ -172,6 +174,12 @@ public ApiTracerFactory getTracerFactory() {
return tracerFactory;
}

/** Gets the GDCH API audience to be used with {@link com.google.auth.oauth2.GdchCredentials} */
@Nullable
public final String getGdchApiAudience() {
return gdchApiAudience;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand All @@ -188,6 +196,7 @@ public String toString() {
.add("streamWatchdogProvider", streamWatchdogProvider)
.add("streamWatchdogCheckInterval", streamWatchdogCheckInterval)
.add("tracerFactory", tracerFactory)
.add("gdchApiAudience", gdchApiAudience)
.toString();
}

Expand All @@ -205,6 +214,7 @@ public abstract static class Builder<
private String endpoint;
private String mtlsEndpoint;
private String quotaProjectId;
@Nullable private String gdchApiAudience;
@Nullable private WatchdogProvider streamWatchdogProvider;
@Nonnull private Duration streamWatchdogCheckInterval;
@Nonnull private ApiTracerFactory tracerFactory;
Expand Down Expand Up @@ -234,6 +244,7 @@ protected Builder(StubSettings settings) {
this.streamWatchdogCheckInterval = settings.streamWatchdogCheckInterval;
this.tracerFactory = settings.tracerFactory;
this.deprecatedExecutorProviderSet = settings.deprecatedExecutorProviderSet;
this.gdchApiAudience = settings.gdchApiAudience;
}

/** Get Quota Project ID from Client Context * */
Expand Down Expand Up @@ -268,6 +279,7 @@ protected Builder(ClientContext clientContext) {
this.streamWatchdogCheckInterval = Duration.ofSeconds(10);
this.tracerFactory = BaseApiTracerFactory.getInstance();
this.deprecatedExecutorProviderSet = false;
this.gdchApiAudience = null;
} else {
ExecutorProvider fixedExecutorProvider =
FixedExecutorProvider.create(clientContext.getExecutor());
Expand All @@ -289,6 +301,7 @@ protected Builder(ClientContext clientContext) {
this.streamWatchdogCheckInterval = clientContext.getStreamWatchdogCheckInterval();
this.tracerFactory = clientContext.getTracerFactory();
this.quotaProjectId = getQuotaProjectIdFromClientContext(clientContext);
this.gdchApiAudience = clientContext.getGdchApiAudience();
blakeli0 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -435,6 +448,18 @@ public B setStreamWatchdogCheckInterval(@Nonnull Duration checkInterval) {
return self();
}

/**
* Sets the API audience used by {@link com.google.auth.oauth2.GdchCredentials} It cannot be
* used if other type of {@link com.google.auth.Credentials} is used. If the provided
* credentials already have an api audience set, then it will be overriden by this audience
*
* @param gdchApiAudience the audience to be used - must be a valid URI string
*/
public B setGdchApiAudience(String gdchApiAudience) {
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
this.gdchApiAudience = gdchApiAudience;
return self();
}

/**
* Configures the {@link ApiTracerFactory} that will be used to generate traces.
*
Expand Down Expand Up @@ -513,6 +538,11 @@ public ApiTracerFactory getTracerFactory() {
return tracerFactory;
}

/** Gets the GDCH API audience that was previously set in this Builder */
public String getGdchApiAudience() {
return gdchApiAudience;
}

/** Applies the given settings updater function to the given method settings builders. */
protected static void applyToAllUnaryMethods(
Iterable<UnaryCallSettings.Builder<?, ?>> methodSettingsBuilders,
Expand Down Expand Up @@ -540,6 +570,7 @@ public String toString() {
.add("streamWatchdogProvider", streamWatchdogProvider)
.add("streamWatchdogCheckInterval", streamWatchdogCheckInterval)
.add("tracerFactory", tracerFactory)
.add("gdchApiAudience", gdchApiAudience)
.toString();
}
}
Expand Down