adutra commented on code in PR #12555: URL: https://github.com/apache/iceberg/pull/12555#discussion_r2013729592
########## 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: I tried something in 75acdbc – let me know if that's better. -- 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