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


##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Manager.java:
##########
@@ -64,18 +65,89 @@ public class OAuth2Manager extends RefreshingAuthManager {
   private AuthSessionCache sessionCache;
 
   public OAuth2Manager(String managerName) {
-    super(managerName + "-token-refresh");
+    super(managerName);
     this.name = managerName;
   }
 
   @Override
+  public OAuth2Manager withClient(RESTClient restClient) {
+    Preconditions.checkNotNull(restClient, "invalid restClient: null");
+    refreshClient = restClient.withAuthSession(AuthSession.EMPTY);
+    return this;
+  }
+
+  @Override
+  public OAuth2Util.AuthSession authSession(AuthScope scope) {
+    Preconditions.checkNotNull(scope, "invalid scope: null");
+    Preconditions.checkState(
+        refreshClient != null, "cannot create AuthSession: no RESTClient 
available");
+    if (sessionCache == null) {
+      sessionCache = newSessionCache(name, scope.properties());
+    }
+    AuthConfig config = AuthConfig.fromProperties(scope.properties());
+    keepRefreshed(config.keepRefreshed());
+    if (scope instanceof AuthScopes.Initial) {
+      warnIfDeprecatedTokenEndpointUsed(scope.properties());
+      return initSession(config);
+    } else if (scope instanceof AuthScopes.Catalog) {
+      return catalogSession(config);
+    } else if (scope instanceof AuthScopes.Contextual) {
+      return contextualSession((AuthScopes.Contextual) scope);
+    } else if (scope instanceof AuthScopes.Table) {
+      return tableSession((AuthScopes.Table) scope);
+    } else {
+      return genericSession(scope, config);
+    }
+  }
+
+  /**
+   * @deprecated since 1.9.0, will be removed in 1.10.0; use {@link 
#authSession(AuthScope)}
+   *     instead.
+   */
+  @Override
+  @Deprecated
+  @SuppressWarnings("deprecation")
   public OAuth2Util.AuthSession initSession(RESTClient initClient, Map<String, 
String> properties) {
-    warnIfDeprecatedTokenEndpointUsed(properties);
-    AuthConfig config =
-        ImmutableAuthConfig.builder()
-            .from(AuthConfig.fromProperties(properties))
-            .keepRefreshed(false) // no token refresh during init
-            .build();
+    return 
withClient(initClient).authSession(ImmutableAuthScopes.Initial.of(properties));
+  }
+
+  /**
+   * @deprecated since 1.9.0, will be removed in 1.10.0; use {@link 
#authSession(AuthScope)}
+   *     instead.
+   */
+  @Override
+  @Deprecated
+  @SuppressWarnings("deprecation")
+  public OAuth2Util.AuthSession catalogSession(

Review Comment:
   what I mean is this: the `AuthManager` already deprecated those methods and 
here we're just overriding them for the sake of providing a slightly different 
impl. IMO that impl should go into the `AuthManager` so that we don't need to 
do anything for those deprecated methods here



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to