smaheshwar-pltr commented on code in PR #13966:
URL: https://github.com/apache/iceberg/pull/13966#discussion_r2316241347
##########
azure/src/main/java/org/apache/iceberg/azure/adlsv2/VendedAdlsCredentialProvider.java:
##########
@@ -78,6 +81,29 @@ Mono<String> credentialForAccount(String storageAccount) {
}
private AccessToken sasTokenForAccount(String storageAccount) {
+ return sasTokenFromProperties(storageAccount).orElseGet(() ->
refreshSasToken(storageAccount));
+ }
+
+ private Optional<AccessToken> sasTokenFromProperties(String storageAccount) {
+ String sasToken = properties.get(AzureProperties.ADLS_SAS_TOKEN_PREFIX +
storageAccount);
+ String tokenExpiresAtMillis =
+ properties.get(AzureProperties.ADLS_SAS_TOKEN_EXPIRES_AT_MS_PREFIX +
storageAccount);
+
+ if (Strings.isNullOrEmpty(sasToken) ||
Strings.isNullOrEmpty(tokenExpiresAtMillis)) {
+ return Optional.empty();
+ }
+
+ Instant expiresAt =
Instant.ofEpochMilli(Long.parseLong(tokenExpiresAtMillis));
+ Instant prefetchAt = expiresAt.minus(5, ChronoUnit.MINUTES);
+
+ if (Instant.now().isAfter(prefetchAt)) {
+ return Optional.empty();
+ }
Review Comment:
This is a good point, I agree it's not nice that there are two prefetches
going on (here and in the `SimpleTokenCache`) .
I think the problem with removing the prefetch is that, if the token
configured on the `LoadTableResponse` properties happens to be short-lived or
expired by the time we get here for the first time, we'd just use that.
(Removing this if condition causes the `expiredSasTokenInProperties` to fail.)
I don't think there's logic in the `SimpleTokenCache` that handles when the
supplier-returned token is close to expiration (it just handles when to next
refresh), and that's likely fine when fetching credentials from the endpoint
but feels more questionable when extracting from properties. In other words,
when `credentialForAccount` is called for the first time and gets the token
from properties, the cache wouldn't check that the token is soon-to-expire, but
in this case we should probably just refresh from the endpoint and return that
token instead.
--
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]