Skip to content

Commit 933cdd3

Browse files
committed
Formatting changes
1 parent b8d4a85 commit 933cdd3

File tree

12 files changed

+247
-194
lines changed

12 files changed

+247
-194
lines changed

oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,12 @@ protected void refreshTrustBoundaries(AccessToken newAccessToken) throws IOExcep
405405
// Refresh trust boundaries only if the cached value is not NO_OP.
406406
if (this.trustBoundary == null || !this.trustBoundary.isNoOp()) {
407407
try {
408-
this.trustBoundary = TrustBoundary.refresh(
409-
provider.getTransportFactory(),
410-
provider.getTrustBoundaryUrl(),
411-
newAccessToken,
412-
this.trustBoundary);
408+
this.trustBoundary =
409+
TrustBoundary.refresh(
410+
provider.getTransportFactory(),
411+
provider.getTrustBoundaryUrl(),
412+
newAccessToken,
413+
this.trustBoundary);
413414
} catch (IOException e) {
414415
// If refresh fails, check for cached value.
415416
if (this.trustBoundary == null) {
@@ -432,8 +433,7 @@ protected Map<String, List<String>> getAdditionalHeaders() {
432433

433434
if (this.trustBoundary != null) {
434435
String headerValue = trustBoundary.isNoOp() ? "" : trustBoundary.getEncodedLocations();
435-
headers.put(
436-
TrustBoundary.TRUST_BOUNDARY_KEY, Collections.singletonList(headerValue));
436+
headers.put(TrustBoundary.TRUST_BOUNDARY_KEY, Collections.singletonList(headerValue));
437437
}
438438

439439
return Collections.unmodifiableMap(headers);
@@ -544,7 +544,7 @@ public boolean equals(Object obj) {
544544

545545
@Override
546546
public int hashCode() {
547-
return Objects.hash(this.quotaProjectId, this.universeDomain, this.isExplicitUniverseDomain);
547+
return Objects.hash(this.quotaProjectId, this.universeDomain, this.isExplicitUniverseDomain);
548548
}
549549

550550
public static Builder newBuilder() {

oauth2_http/java/com/google/auth/oauth2/ImpersonatedCredentials.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,8 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import java.io.IOException;
35-
import java.io.ObjectInputStream;
36-
import java.text.DateFormat;
37-
import java.text.ParseException;
38-
import java.text.SimpleDateFormat;
39-
import java.util.ArrayList;
40-
import java.util.Arrays;
41-
import java.util.Calendar;
42-
import java.util.Collection;
43-
import java.util.Date;
44-
import java.util.List;
45-
import java.util.Map;
46-
import java.util.Objects;
34+
import static com.google.common.base.MoreObjects.firstNonNull;
35+
import static com.google.common.base.Preconditions.checkNotNull;
4736

4837
import com.google.api.client.http.GenericUrl;
4938
import com.google.api.client.http.HttpContent;
@@ -61,10 +50,21 @@
6150
import com.google.auth.oauth2.MetricsUtils.RequestType;
6251
import com.google.common.annotations.VisibleForTesting;
6352
import com.google.common.base.MoreObjects;
64-
import static com.google.common.base.MoreObjects.firstNonNull;
65-
import static com.google.common.base.Preconditions.checkNotNull;
6653
import com.google.common.collect.ImmutableMap;
6754
import com.google.errorprone.annotations.CanIgnoreReturnValue;
55+
import java.io.IOException;
56+
import java.io.ObjectInputStream;
57+
import java.text.DateFormat;
58+
import java.text.ParseException;
59+
import java.text.SimpleDateFormat;
60+
import java.util.ArrayList;
61+
import java.util.Arrays;
62+
import java.util.Calendar;
63+
import java.util.Collection;
64+
import java.util.Date;
65+
import java.util.List;
66+
import java.util.Map;
67+
import java.util.Objects;
6868

6969
/**
7070
* ImpersonatedCredentials allowing credentials issued to a user or service account to impersonate

oauth2_http/java/com/google/auth/oauth2/OAuth2Credentials.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import java.io.IOException;
35-
import java.io.ObjectInputStream;
36-
import java.io.Serializable;
37-
import java.net.URI;
38-
import java.time.Duration;
39-
import java.util.ArrayList;
40-
import java.util.Date;
41-
import java.util.List;
42-
import java.util.Map;
43-
import java.util.Objects;
44-
import java.util.ServiceLoader;
45-
import java.util.concurrent.ExecutionException;
46-
import java.util.concurrent.Executor;
47-
48-
import javax.annotation.Nullable;
49-
5034
import com.google.api.client.util.Clock;
5135
import com.google.auth.Credentials;
5236
import com.google.auth.RequestMetadataCallback;
@@ -64,6 +48,20 @@
6448
import com.google.common.util.concurrent.ListenableFutureTask;
6549
import com.google.common.util.concurrent.MoreExecutors;
6650
import com.google.errorprone.annotations.CanIgnoreReturnValue;
51+
import java.io.IOException;
52+
import java.io.ObjectInputStream;
53+
import java.io.Serializable;
54+
import java.net.URI;
55+
import java.time.Duration;
56+
import java.util.ArrayList;
57+
import java.util.Date;
58+
import java.util.List;
59+
import java.util.Map;
60+
import java.util.Objects;
61+
import java.util.ServiceLoader;
62+
import java.util.concurrent.ExecutionException;
63+
import java.util.concurrent.Executor;
64+
import javax.annotation.Nullable;
6765

6866
/** Base type for Credentials using OAuth2. */
6967
public class OAuth2Credentials extends Credentials {

oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.google.auth.oauth2.MetricsUtils.RequestType;
6161
import com.google.common.annotations.VisibleForTesting;
6262
import com.google.common.base.MoreObjects.ToStringHelper;
63-
import static com.google.common.base.MoreObjects.firstNonNull;
6463
import com.google.common.collect.ImmutableList;
6564
import com.google.common.collect.ImmutableMap;
6665
import com.google.common.collect.ImmutableSet;

oauth2_http/java/com/google/auth/oauth2/TrustBoundary.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,18 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import java.io.IOException;
35-
import java.util.Collections;
36-
import java.util.Date;
37-
import java.util.List;
38-
39-
import javax.annotation.Nullable;
40-
4134
import com.google.api.client.http.*;
4235
import com.google.api.client.json.GenericJson;
4336
import com.google.api.client.json.JsonParser;
4437
import com.google.api.client.util.ExponentialBackOff;
4538
import com.google.api.client.util.Key;
4639
import com.google.auth.http.HttpTransportFactory;
4740
import com.google.common.base.MoreObjects;
41+
import java.io.IOException;
42+
import java.util.Collections;
43+
import java.util.Date;
44+
import java.util.List;
45+
import javax.annotation.Nullable;
4846

4947
/**
5048
* Represents a trust boundary that can be used to restrict access to resources. This is an
@@ -53,14 +51,18 @@
5351
public final class TrustBoundary {
5452

5553
static final String TRUST_BOUNDARY_KEY = "x-allowed-locations";
56-
static final String GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED_ENV_VAR = "GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT";
54+
static final String GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED_ENV_VAR =
55+
"GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT";
5756
private static final String NO_OP_VALUE = "0x0";
5857
private final String encodedLocations;
5958
private final List<String> locations;
6059

6160
public TrustBoundary(String encodedLocations, List<String> locations) {
6261
this.encodedLocations = encodedLocations;
63-
this.locations = locations == null ? Collections.<String>emptyList() : Collections.unmodifiableList(locations);
62+
this.locations =
63+
locations == null
64+
? Collections.<String>emptyList()
65+
: Collections.unmodifiableList(locations);
6466
}
6567

6668
private static EnvironmentProvider environmentProvider = SystemEnvironmentProvider.getInstance();
@@ -122,8 +124,7 @@ static boolean isTrustBoundaryEnabled() throws IOException {
122124
throw new IOException(
123125
String.format(
124126
"Invalid value for %s environment variable: \"%s\". Supported values are 'true', '1', 'false', or '0'.",
125-
GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED_ENV_VAR,
126-
tbEnabled));
127+
GOOGLE_AUTH_TRUST_BOUNDARY_ENABLED_ENV_VAR, tbEnabled));
127128
}
128129

129130
static TrustBoundary refresh(
@@ -146,16 +147,18 @@ static TrustBoundary refresh(
146147

147148
// Add the cached trust boundary header, if available.
148149
if (cachedTrustBoundary != null) {
149-
String headerValue = cachedTrustBoundary.isNoOp() ? "" : cachedTrustBoundary.getEncodedLocations();
150+
String headerValue =
151+
cachedTrustBoundary.isNoOp() ? "" : cachedTrustBoundary.getEncodedLocations();
150152
// request.getHeaders().set(TRUST_BOUNDARY_KEY, headerValue);
151153
}
152154

153155
// Add retry logic
154-
ExponentialBackOff backoff = new ExponentialBackOff.Builder()
155-
.setInitialIntervalMillis(OAuth2Utils.INITIAL_RETRY_INTERVAL_MILLIS)
156-
.setRandomizationFactor(OAuth2Utils.RETRY_RANDOMIZATION_FACTOR)
157-
.setMultiplier(OAuth2Utils.RETRY_MULTIPLIER)
158-
.build();
156+
ExponentialBackOff backoff =
157+
new ExponentialBackOff.Builder()
158+
.setInitialIntervalMillis(OAuth2Utils.INITIAL_RETRY_INTERVAL_MILLIS)
159+
.setRandomizationFactor(OAuth2Utils.RETRY_RANDOMIZATION_FACTOR)
160+
.setMultiplier(OAuth2Utils.RETRY_MULTIPLIER)
161+
.build();
159162

160163
HttpUnsuccessfulResponseHandler unsuccessfulResponseHandler =
161164
new HttpBackOffUnsuccessfulResponseHandler(backoff);
@@ -179,4 +182,4 @@ static TrustBoundary refresh(
179182
}
180183
return new TrustBoundary(encodedLocations, json.getLocations());
181184
}
182-
}
185+
}

oauth2_http/java/com/google/auth/oauth2/TrustBoundaryProvider.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@
3131

3232
package com.google.auth.oauth2;
3333

34-
import java.io.IOException;
35-
3634
import com.google.auth.http.HttpTransportFactory;
35+
import java.io.IOException;
3736

38-
/**
39-
* An interface for credentials that support trust boundaries. This is an experimental feature.
40-
*/
37+
/** An interface for credentials that support trust boundaries. This is an experimental feature. */
4138
public interface TrustBoundaryProvider {
4239

4340
/** Returns the transport factory. */
4441
HttpTransportFactory getTransportFactory();
4542

4643
/** Returns the trust boundary lookup URL. */
4744
String getTrustBoundaryUrl() throws IOException;
48-
}
45+
}

oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,42 +1152,45 @@ public void idTokenWithAudience_503StatusCode() {
11521152
GoogleAuthException.class, () -> credentials.idTokenWithAudience("Audience", null));
11531153
}
11541154

1155-
@Test
1156-
public void refresh_trustBoundarySuccess() throws IOException {
1157-
TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider();
1158-
TrustBoundary.setEnvironmentProviderForTest(environmentProvider);
1159-
environmentProvider.setEnv("GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT", "1");
1160-
String defaultAccountEmail = "[email protected]";
1161-
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
1162-
TrustBoundary trustBoundary = new TrustBoundary("0x80000", Collections.singletonList("us-central1"));
1163-
transportFactory.transport.setTrustBoundary(trustBoundary);
1164-
transportFactory.transport.setServiceAccountEmail(defaultAccountEmail);
1165-
1166-
ComputeEngineCredentials credentials =
1167-
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
1168-
1169-
Map<String, List<String>> headers = credentials.getRequestMetadata();
1170-
assertEquals(headers.get("x-allowed-locations"), Arrays.asList("0x80000"));
1171-
}
1155+
@Test
1156+
public void refresh_trustBoundarySuccess() throws IOException {
1157+
TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider();
1158+
TrustBoundary.setEnvironmentProviderForTest(environmentProvider);
1159+
environmentProvider.setEnv("GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT", "1");
1160+
String defaultAccountEmail = "[email protected]";
1161+
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
1162+
TrustBoundary trustBoundary =
1163+
new TrustBoundary("0x80000", Collections.singletonList("us-central1"));
1164+
transportFactory.transport.setTrustBoundary(trustBoundary);
1165+
transportFactory.transport.setServiceAccountEmail(defaultAccountEmail);
11721166

1173-
@Test
1174-
public void refresh_trustBoundaryFails_throwsIOException() throws IOException {
1175-
TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider();
1176-
TrustBoundary.setEnvironmentProviderForTest(environmentProvider);
1177-
environmentProvider.setEnv("GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT", "1");
1167+
ComputeEngineCredentials credentials =
1168+
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
11781169

1179-
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
1170+
Map<String, List<String>> headers = credentials.getRequestMetadata();
1171+
assertEquals(headers.get("x-allowed-locations"), Arrays.asList("0x80000"));
1172+
}
11801173

1181-
ComputeEngineCredentials credentials =
1182-
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
1174+
@Test
1175+
public void refresh_trustBoundaryFails_throwsIOException() throws IOException {
1176+
TestEnvironmentProvider environmentProvider = new TestEnvironmentProvider();
1177+
TrustBoundary.setEnvironmentProviderForTest(environmentProvider);
1178+
environmentProvider.setEnv("GOOGLE_AUTH_TRUST_BOUNDARY_ENABLE_EXPERIMENT", "1");
11831179

1184-
try {
1185-
credentials.refresh();
1186-
} catch (IOException e) {
1187-
assertTrue("The exception message should explain why the refresh failed.",
1188-
e.getMessage().contains("Failed to refresh trust boundary and no cached value is available."));
1189-
}
1180+
MockMetadataServerTransportFactory transportFactory = new MockMetadataServerTransportFactory();
1181+
1182+
ComputeEngineCredentials credentials =
1183+
ComputeEngineCredentials.newBuilder().setHttpTransportFactory(transportFactory).build();
1184+
1185+
try {
1186+
credentials.refresh();
1187+
} catch (IOException e) {
1188+
assertTrue(
1189+
"The exception message should explain why the refresh failed.",
1190+
e.getMessage()
1191+
.contains("Failed to refresh trust boundary and no cached value is available."));
11901192
}
1193+
}
11911194

11921195
static class MockMetadataServerTransportFactory implements HttpTransportFactory {
11931196

0 commit comments

Comments
 (0)