ebyhr commented on code in PR #18910:
URL: https://github.com/apache/iceberg/pull/18910#discussion_r4607777864
##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
@@ -693,6 +708,7 @@ private static AuthSession fromTokenResponse(
if (issuedTokenType == null) {
issuedTokenType = OAuth2Properties.ACCESS_TOKEN_TYPE;
}
+ Long expiresAtMillis = expiresAtMillis(response, startTimeMillis);
Review Comment:
https://iceberg.apache.org/contribute/#block-spacing
> To improve readability and maintain consistency, always place a newline
after control blocks (if, for, while, switch, etc.).
(I know it's pre-existing though)
##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
@@ -542,30 +545,47 @@ public Pair<Integer, TimeUnit> refresh(RESTClient client)
{
return null;
}
- private OAuthTokenResponse refreshCurrentToken(RESTClient client) {
+ private record TimedTokenResponse(long requestStartMillis,
OAuthTokenResponse response) {
+ static TimedTokenResponse of(long requestStartMillis, OAuthTokenResponse
response) {
+ if (response == null) {
+ return null;
+ }
+
+ return new TimedTokenResponse(requestStartMillis, response);
+ }
+ }
+
+ private TimedTokenResponse refreshCurrentToken(RESTClient client) {
if (null != expiresAtMillis() && expiresAtMillis() <=
System.currentTimeMillis()) {
// the token has already expired, attempt to refresh using the
credential
return refreshExpiredToken(client);
} else {
// attempt a normal refresh
- return refreshToken(client, config, headers(), token(), tokenType(),
optionalOAuthParams());
+ long requestStartMillis = System.currentTimeMillis();
+ OAuthTokenResponse response =
+ refreshToken(client, config, headers(), token(), tokenType(),
optionalOAuthParams());
+ return TimedTokenResponse.of(requestStartMillis, response);
}
}
- private OAuthTokenResponse refreshExpiredToken(RESTClient client) {
+ private TimedTokenResponse refreshExpiredToken(RESTClient client) {
if (credential() == null) {
return null;
}
+ long requestStartMillis = System.currentTimeMillis();
+ OAuthTokenResponse response;
if (config.exchangeEnabled()) {
Map<String, String> basicHeaders =
RESTUtil.merge(headers(), basicAuthHeaders(credential()));
- return refreshToken(
- client, config, basicHeaders, token(), tokenType(),
optionalOAuthParams());
+ response =
+ refreshToken(client, config, basicHeaders, token(), tokenType(),
optionalOAuthParams());
} else {
- return fetchToken(
- client, Map.of(), credential(), scope(), oauth2ServerUri(),
optionalOAuthParams());
+ response =
+ fetchToken(
+ client, Map.of(), credential(), scope(), oauth2ServerUri(),
optionalOAuthParams());
}
+ return TimedTokenResponse.of(requestStartMillis, response);
Review Comment:
https://iceberg.apache.org/contribute/#block-spacing
> To improve readability and maintain consistency, always place a newline
after control blocks (if, for, while, switch, etc.).
--
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]