danielcweeks commented on code in PR #16848:
URL: https://github.com/apache/iceberg/pull/16848#discussion_r4272300175
##########
gcp/src/main/java/org/apache/iceberg/gcp/auth/GoogleAuthManager.java:
##########
@@ -77,12 +77,31 @@ public String name() {
}
private void initialize(Map<String, String> properties) {
- if (initialized) {
+ if (credentials != null) {
return;
}
- String credentialsPath = properties.get(GCP_CREDENTIALS_PATH_PROPERTY);
- String credentialsJson = properties.get(GCP_CREDENTIALS_JSON_PROPERTY);
+ synchronized (this) {
+ if (credentials != null) {
+ return;
+ }
+
+ String credentialsPath = properties.get(GCP_CREDENTIALS_PATH_PROPERTY);
+ String credentialsJson = properties.get(GCP_CREDENTIALS_JSON_PROPERTY);
+ String scopesString = properties.getOrDefault(GCP_SCOPES_PROPERTY,
DEFAULT_SCOPES);
+
+ try {
+ this.credentials = loadCredentials(credentialsPath, credentialsJson,
scopesString);
+ } catch (IOException e) {
+ // credentials remains null here and treated as not-initialized.
Retries are expected
+ throw new UncheckedIOException("Failed to load Google credentials", e);
+ }
+ }
+ }
+
+ @VisibleForTesting
+ GoogleCredentials loadCredentials(
Review Comment:
This method doesn't mutate state, so it should be static. It seems the only
reason it's not is to facilitate the test, which isn't good practice. This
should either be left in-line or made private static.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]