adutra commented on code in PR #15703:
URL: https://github.com/apache/iceberg/pull/15703#discussion_r3269851412


##########
core/src/main/java/org/apache/iceberg/rest/auth/oauth2/config/TokenRefreshConfig.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.rest.auth.oauth2.config;
+
+import com.nimbusds.oauth2.sdk.GrantType;
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.iceberg.rest.auth.oauth2.OAuth2Config;
+import org.immutables.value.Value;
+
+/** Configuration properties for the token refresh feature. */
[email protected]
+public interface TokenRefreshConfig {
+
+  String PREFIX = OAuth2Config.PREFIX + "token-refresh.";
+
+  String ENABLED = PREFIX + "enabled";
+  String TOKEN_EXCHANGE_ENABLED = PREFIX + "token-exchange-enabled";
+  String ACCESS_TOKEN_LIFESPAN = PREFIX + "access-token-lifespan";
+  String SAFETY_MARGIN = PREFIX + "safety-margin";
+
+  Duration DEFAULT_ACCESS_TOKEN_LIFESPAN = Duration.parse("PT1H");
+  Duration DEFAULT_SAFETY_MARGIN = Duration.parse("PT10S");
+
+  Duration MIN_ACCESS_TOKEN_LIFESPAN = Duration.parse("PT15S");
+  Duration MIN_SAFETY_MARGIN = Duration.parse("PT10S");
+
+  /**
+   * Whether to enable token refresh. If enabled, the OAuth2 client will 
automatically refresh its
+   * access token when it expires. If disabled, the OAuth2 client will only 
fetch the initial access
+   * token, but won't refresh it. Defaults to {@code true}.
+   */
+  @Value.Default
+  default boolean enabled() {
+    return true;
+  }
+
+  /**
+   * Whether to use the token exchange grant to refresh tokens.
+   *
+   * <p>When enabled, the token exchange grant will be used to refresh the 
access token, if no
+   * refresh token is available.
+   *
+   * <p>Optional, defaults to {@code true} if the initial grant is {@link
+   * GrantType#CLIENT_CREDENTIALS}.
+   */
+  Optional<Boolean> tokenExchangeEnabled();
+
+  /**
+   * Default access token lifespan; if the OAuth2 server returns an access 
token without specifying
+   * its expiration time, this value will be used.
+   *
+   * <p>Optional, defaults to {@link #DEFAULT_ACCESS_TOKEN_LIFESPAN}. Must be 
a valid <a
+   * href="https://en.wikipedia.org/wiki/ISO_8601#Durations";>ISO-8601 
duration</a>.
+   */
+  @Value.Default
+  default Duration accessTokenLifespan() {
+    return DEFAULT_ACCESS_TOKEN_LIFESPAN;
+  }
+
+  /**
+   * Refresh safety margin to use; a new token will be fetched when the 
current token's remaining
+   * lifespan is less than this value. Optional, defaults to {@link 
#DEFAULT_SAFETY_MARGIN}. Must be
+   * a valid <a 
href="https://en.wikipedia.org/wiki/ISO_8601#Durations";>ISO-8601 duration</a>.
+   */
+  @Value.Default
+  default Duration safetyMargin() {

Review Comment:
   Renamed to `prefetch()` and added `jitter()`. PTAL.



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