Skip to content

Commit cac4b08

Browse files
committed
chore: Remove MDS call in the constructor
1 parent e1b04b4 commit cac4b08

File tree

5 files changed

+81
-123
lines changed

5 files changed

+81
-123
lines changed

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

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ public class ComputeEngineCredentials extends GoogleCredentials
111111
static final int MAX_COMPUTE_PING_TRIES = 3;
112112
static final int COMPUTE_PING_CONNECTION_TIMEOUT_MS = 500;
113113

114+
private static final String METADATA_FLAVOR = "Metadata-Flavor";
115+
private static final String GOOGLE = "Google";
116+
private static final String WINDOWS = "windows";
117+
private static final String LINUX = "linux";
118+
119+
private static final String PARSE_ERROR_PREFIX = "Error parsing token refresh response. ";
120+
private static final String PARSE_ERROR_ACCOUNT = "Error parsing service account response. ";
121+
private static final long serialVersionUID = -4113476462526554235L;
122+
123+
private final String transportFactoryClassName;
124+
125+
private final Collection<String> scopes;
126+
127+
private final GoogleAuthTransport transport;
128+
private final BindingEnforcement bindingEnforcement;
129+
130+
private transient HttpTransportFactory transportFactory;
131+
private transient String serviceAccountEmail;
132+
133+
private String universeDomainFromMetadata = null;
134+
114135
/**
115136
* Experimental Feature.
116137
*
@@ -172,29 +193,6 @@ public String getLabel() {
172193
}
173194
}
174195

175-
private static final String METADATA_FLAVOR = "Metadata-Flavor";
176-
private static final String GOOGLE = "Google";
177-
private static final String WINDOWS = "windows";
178-
private static final String LINUX = "linux";
179-
180-
private static final String PARSE_ERROR_PREFIX = "Error parsing token refresh response. ";
181-
private static final String PARSE_ERROR_ACCOUNT = "Error parsing service account response. ";
182-
private static final long serialVersionUID = -4113476462526554235L;
183-
184-
private final String transportFactoryClassName;
185-
186-
private final Collection<String> scopes;
187-
188-
private final GoogleAuthTransport transport;
189-
private final BindingEnforcement bindingEnforcement;
190-
191-
private transient HttpTransportFactory transportFactory;
192-
private transient String serviceAccountEmail;
193-
194-
private final boolean shouldCheckMDSOnInitialization;
195-
196-
private String universeDomainFromMetadata = null;
197-
198196
/**
199197
* An internal constructor
200198
*
@@ -223,18 +221,6 @@ private ComputeEngineCredentials(ComputeEngineCredentials.Builder builder) {
223221
this.transport = builder.getGoogleAuthTransport();
224222
this.bindingEnforcement = builder.getBindingEnforcement();
225223
this.name = GoogleCredentialsInfo.COMPUTE_ENGINE_CREDENTIALS.getCredentialName();
226-
this.shouldCheckMDSOnInitialization = builder.shouldCheckMDSOnInitialization;
227-
try {
228-
if (shouldCheckMDSOnInitialization
229-
&& !Boolean.parseBoolean(System.getenv(DefaultCredentialsProvider.NO_GCE_CHECK_ENV_VAR))
230-
&& checkStaticGceDetection(new DefaultCredentialsProvider())) {
231-
this.serviceAccountEmail = getDefaultServiceAccount();
232-
this.principal = this.serviceAccountEmail;
233-
}
234-
} catch (IOException e) {
235-
// This should never happen since we do a passive check for MDS. However, if this does fail,
236-
// we mo-op as MDS is not available yet and should not fail initialization
237-
}
238224
}
239225

240226
@Override
@@ -701,10 +687,6 @@ public static Builder newBuilder() {
701687
return new Builder();
702688
}
703689

704-
static Builder newTestBuilder() {
705-
return newBuilder().setShouldCheckMDSOnInitialization(false);
706-
}
707-
708690
/**
709691
* Returns the email address associated with the GCE default service account.
710692
*
@@ -797,8 +779,6 @@ public static class Builder extends GoogleCredentials.Builder {
797779
private GoogleAuthTransport transport;
798780
private BindingEnforcement bindingEnforcement;
799781

800-
private boolean shouldCheckMDSOnInitialization = true;
801-
802782
protected Builder() {
803783
setRefreshMargin(COMPUTE_REFRESH_MARGIN);
804784
setExpirationMargin(COMPUTE_EXPIRATION_MARGIN);
@@ -808,7 +788,6 @@ protected Builder(ComputeEngineCredentials credentials) {
808788
super(credentials);
809789
this.transportFactory = credentials.transportFactory;
810790
this.scopes = credentials.scopes;
811-
this.shouldCheckMDSOnInitialization = credentials.shouldCheckMDSOnInitialization;
812791
}
813792

814793
@CanIgnoreReturnValue
@@ -863,11 +842,6 @@ public Builder setBindingEnforcement(BindingEnforcement bindingEnforcement) {
863842
return this;
864843
}
865844

866-
Builder setShouldCheckMDSOnInitialization(boolean shouldCheckMDSOnInitialization) {
867-
this.shouldCheckMDSOnInitialization = shouldCheckMDSOnInitialization;
868-
return this;
869-
}
870-
871845
public HttpTransportFactory getHttpTransportFactory() {
872846
return transportFactory;
873847
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,7 @@ private final GoogleCredentials tryGetComputeCredentials(HttpTransportFactory tr
311311
}
312312
boolean runningOnComputeEngine = ComputeEngineCredentials.isOnGce(transportFactory, this);
313313
checkedComputeEngine = true;
314-
ComputeEngineCredentials.Builder builder =
315-
shouldCheckMDSOnInitialization()
316-
? ComputeEngineCredentials.newBuilder()
317-
: ComputeEngineCredentials.newTestBuilder();
314+
ComputeEngineCredentials.Builder builder = ComputeEngineCredentials.newBuilder();
318315
if (runningOnComputeEngine) {
319316
return builder.setHttpTransportFactory(transportFactory).build();
320317
}
@@ -365,10 +362,6 @@ InputStream readStream(File file) throws FileNotFoundException {
365362
return new FileInputStream(file);
366363
}
367364

368-
boolean shouldCheckMDSOnInitialization() {
369-
return true;
370-
}
371-
372365
/*
373366
* End of methods to allow overriding in the test code to isolate from the environment.
374367
*/

0 commit comments

Comments
 (0)