nastra commented on code in PR #14333:
URL: https://github.com/apache/iceberg/pull/14333#discussion_r2567633495


##########
gcp/src/main/java/org/apache/iceberg/gcp/gcs/PrefixedStorage.java:
##########
@@ -117,5 +126,54 @@ public void close() {
       // GCS Storage does not appear to be closable, so release the reference
       storage = null;
     }
+
+    if (null != gcsFileSystem) {
+      gcsFileSystem.close();
+      gcsFileSystem = null;
+    }
+  }
+
+  static Credentials getCredentials(Map<String, String> properties, 
CloseableGroup closeableGroup) {
+    GCPProperties gcpProperties = new GCPProperties(properties);
+    if (gcpProperties.oauth2Token().isPresent()) {
+      return GCPAuthUtils.oauth2CredentialsFromGcpProperties(
+          new GCPProperties(properties), closeableGroup);
+    } else if (gcpProperties.noAuth()) {
+      return NoCredentials.getInstance();
+    } else {
+      return null;
+    }
+  }
+
+  public GcsFileSystem gcsFileSystem() {
+    if (gcsFileSystem == null) {
+      synchronized (this) {
+        if (gcsFileSystem == null) {
+          this.gcsFileSystem = gcsFileSystemSupplier.get();
+        }
+      }
+    }
+    return this.gcsFileSystem;
+  }
+
+  private SerializableSupplier<GcsFileSystem> getGcsFileSystemSupplier(
+      Map<String, String> properties) {
+    ImmutableMap.Builder<String, String> propertiesWithUserAgent =
+        new ImmutableMap.Builder<String, String>()
+            .putAll(properties)
+            .put("user-agent", GCS_FILE_IO_USER_AGENT);
+    GcsAnalyticsCoreOptions gcsAnalyticsCoreOptions =
+        new GcsAnalyticsCoreOptions("", propertiesWithUserAgent.build());
+    GcsFileSystemOptions fileSystemOptions = 
gcsAnalyticsCoreOptions.getGcsFileSystemOptions();
+    if (this.closeableGroup == null) {
+      this.closeableGroup = new CloseableGroup();

Review Comment:
   we should probably just init this always in the constructor. Also you 
probably want to add `gcsFileSystem` to the closeable group after 
`gcsFileSystem` was initialized (then you wouldn't need to call close on it 
explicitly



-- 
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]

Reply via email to