|
47 | 47 | @InternalApi
|
48 | 48 | @AutoValue
|
49 | 49 | public abstract class EndpointContext {
|
| 50 | + private static final String GOOGLE_CLOUD_UNIVERSE_DOMAIN = "GOOGLE_CLOUD_UNIVERSE_DOMAIN"; |
50 | 51 | private static final String INVALID_UNIVERSE_DOMAIN_ERROR_TEMPLATE =
|
51 | 52 | "The configured universe domain (%s) does not match the universe domain found in the credentials (%s). If you haven't configured the universe domain explicitly, `googleapis.com` is the default.";
|
52 | 53 | public static final String UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE =
|
@@ -213,7 +214,9 @@ private String determineUniverseDomain() {
|
213 | 214 | if (universeDomain() != null && universeDomain().isEmpty()) {
|
214 | 215 | throw new IllegalArgumentException("The universe domain value cannot be empty.");
|
215 | 216 | }
|
216 |
| - // Override with user set universe domain if provided |
| 217 | + // Override with configured universe domain if provided. If the universe domain is configured |
| 218 | + // by the user, the universe domain will either be the settings or from the env var. The |
| 219 | + // value from ClientSettings has priority. |
217 | 220 | return universeDomain() != null ? universeDomain() : Credentials.GOOGLE_DEFAULT_UNIVERSE;
|
218 | 221 | }
|
219 | 222 |
|
@@ -283,6 +286,11 @@ String mtlsEndpointResolver(
|
283 | 286 | }
|
284 | 287 |
|
285 | 288 | public EndpointContext build() throws IOException {
|
| 289 | + // If the universe domain wasn't configured explicitly in the settings, check the |
| 290 | + // environment variable for the value |
| 291 | + if (universeDomain() == null) { |
| 292 | + setUniverseDomain(System.getenv(GOOGLE_CLOUD_UNIVERSE_DOMAIN)); |
| 293 | + } |
286 | 294 | // The Universe Domain is used to resolve the Endpoint. It should be resolved first
|
287 | 295 | setResolvedUniverseDomain(determineUniverseDomain());
|
288 | 296 | setResolvedEndpoint(determineEndpoint());
|
|
0 commit comments