mansehajsingh commented on code in PR #8:
URL: https://github.com/apache/polaris-tools/pull/8#discussion_r2055301244


##########
polaris-synchronizer/api/src/main/java/org/apache/polaris/tools/sync/polaris/auth/AuthenticationSessionWrapper.java:
##########
@@ -0,0 +1,82 @@
+package org.apache.polaris.tools.sync.polaris.auth;
+
+import org.apache.iceberg.rest.HTTPClient;
+import org.apache.iceberg.rest.RESTClient;
+import org.apache.iceberg.rest.auth.AuthConfig;
+import org.apache.iceberg.rest.auth.OAuth2Properties;
+import org.apache.iceberg.rest.auth.OAuth2Util;
+import org.apache.iceberg.util.ThreadPools;
+
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Wraps {@link OAuth2Util.AuthSession} to provide supported authentication 
flows.
+ */
+public class AuthenticationSessionWrapper {
+
+    private final OAuth2Util.AuthSession authSession;
+
+    public AuthenticationSessionWrapper(Map<String, String> properties) {
+        this.authSession = this.newAuthSession(properties);
+    }
+
+    /**
+     * Initializes a new authentication session. Supports client_credentials 
and bearer token flow.
+     * @param properties properties to initialize the session with
+     * @return an authentication session, with token refresh if applicable
+     */
+    private OAuth2Util.AuthSession newAuthSession(Map<String, String> 
properties) {
+
+        RESTClient restClient = HTTPClient.builder(Map.of())

Review Comment:
   I've gone ahead and made some of the core classes implement `Closeable`. 
I've tried to add explicit and appropriate calls to `close` whenever possible, 
and made it so that the CLI also ensures that in the event of unexpected 
failure, there are runtime hooks to ensure the resources are closed 
appropriately. I've tried to scope the explicit closing to the sections that 
call the methods to create the closeable resources. Now,
   
   * `PolarisSynchronizer` will close any `IcebergCatalogService` it creates, 
in which case `PolarisIcebergCatalogService` will close the underlying 
`PolarisCatalog` which closes its own `AuthenticationSessionWrapper`.
   * `PolarisApiService` is closed explicitly by the CLI on program termination 
as well, closings its `AuthenticationSessionWrapper`.



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

Reply via email to