vladislav-sidorovich commented on code in PR #16848:
URL: https://github.com/apache/iceberg/pull/16848#discussion_r4237880979
##########
gcp/src/main/java/org/apache/iceberg/gcp/auth/GoogleAuthManager.java:
##########
@@ -81,44 +82,68 @@ private void initialize(Map<String, String> properties) {
return;
}
- String credentialsPath = properties.get(GCP_CREDENTIALS_PATH_PROPERTY);
- String credentialsJson = properties.get(GCP_CREDENTIALS_JSON_PROPERTY);
- boolean useCredentialsPath = credentialsPath != null &&
!credentialsPath.isEmpty();
- boolean useCredentialsJson = credentialsJson != null &&
!credentialsJson.isEmpty();
- if (useCredentialsPath && useCredentialsJson) {
- throw new IllegalArgumentException(
- String.format(
- "Cannot specify both %s and %s",
- GCP_CREDENTIALS_PATH_PROPERTY, GCP_CREDENTIALS_JSON_PROPERTY));
+ synchronized (this) {
+ if (initialized) {
+ return;
+ }
+
+ String credentialsPath = properties.get(GCP_CREDENTIALS_PATH_PROPERTY);
+ String credentialsJson = properties.get(GCP_CREDENTIALS_JSON_PROPERTY);
+ boolean useCredentialsPath = credentialsPath != null &&
!credentialsPath.isEmpty();
+ boolean useCredentialsJson = credentialsJson != null &&
!credentialsJson.isEmpty();
+ if (useCredentialsPath && useCredentialsJson) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Cannot specify both %s and %s",
+ GCP_CREDENTIALS_PATH_PROPERTY, GCP_CREDENTIALS_JSON_PROPERTY));
+ }
+
+ String scopesString = properties.getOrDefault(GCP_SCOPES_PROPERTY,
DEFAULT_SCOPES);
+
+ try {
+ this.credentials =
+ loadCredentials(
+ useCredentialsPath,
+ credentialsPath,
+ useCredentialsJson,
+ credentialsJson,
+ scopesString);
+ } catch (IOException e) {
Review Comment:
Done
##########
gcp/src/main/java/org/apache/iceberg/gcp/auth/GoogleAuthManager.java:
##########
@@ -81,44 +82,68 @@ private void initialize(Map<String, String> properties) {
return;
}
- String credentialsPath = properties.get(GCP_CREDENTIALS_PATH_PROPERTY);
- String credentialsJson = properties.get(GCP_CREDENTIALS_JSON_PROPERTY);
- boolean useCredentialsPath = credentialsPath != null &&
!credentialsPath.isEmpty();
- boolean useCredentialsJson = credentialsJson != null &&
!credentialsJson.isEmpty();
- if (useCredentialsPath && useCredentialsJson) {
- throw new IllegalArgumentException(
- String.format(
- "Cannot specify both %s and %s",
- GCP_CREDENTIALS_PATH_PROPERTY, GCP_CREDENTIALS_JSON_PROPERTY));
+ synchronized (this) {
+ if (initialized) {
+ return;
+ }
+
+ String credentialsPath = properties.get(GCP_CREDENTIALS_PATH_PROPERTY);
+ String credentialsJson = properties.get(GCP_CREDENTIALS_JSON_PROPERTY);
+ boolean useCredentialsPath = credentialsPath != null &&
!credentialsPath.isEmpty();
+ boolean useCredentialsJson = credentialsJson != null &&
!credentialsJson.isEmpty();
+ if (useCredentialsPath && useCredentialsJson) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Cannot specify both %s and %s",
+ GCP_CREDENTIALS_PATH_PROPERTY, GCP_CREDENTIALS_JSON_PROPERTY));
+ }
+
+ String scopesString = properties.getOrDefault(GCP_SCOPES_PROPERTY,
DEFAULT_SCOPES);
+
+ try {
+ this.credentials =
+ loadCredentials(
+ useCredentialsPath,
+ credentialsPath,
+ useCredentialsJson,
+ credentialsJson,
+ scopesString);
+ } catch (IOException e) {
+ throw new UncheckedIOException("Failed to load Google credentials", e);
+ }
+
+ this.initialized = true;
}
+ }
- String scopesString = properties.getOrDefault(GCP_SCOPES_PROPERTY,
DEFAULT_SCOPES);
+ @VisibleForTesting
+ GoogleCredentials loadCredentials(
Review Comment:
Done
--
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]