gaborgsomogyi commented on code in PR #29823:
URL: https://github.com/apache/flink/pull/29823#discussion_r4561444413


##########
flink-filesystems/flink-s3-fs-base/src/main/java/org/apache/flink/fs/s3/common/token/AbstractS3DelegationTokenReceiver.java:
##########
@@ -79,24 +134,25 @@ public void init(Configuration configuration) {
                                 DelegationTokenProvider.CONFIG_PREFIX, 
serviceName()),
                         null);
         if (!StringUtils.isNullOrWhitespaceOnly(region)) {
-            LOG.debug("Region: " + region);
+            LOG.debug("Region: {}", region);
         }
     }
 
     @Override
     public void onNewTokensObtained(byte[] tokens) throws Exception {
         LOG.info("Updating session credentials");
-        credentials =
+        final S3SessionCredentials newCredentials =
                 InstantiationUtil.deserializeObject(
                         tokens, 
AbstractS3DelegationTokenReceiver.class.getClassLoader());
+        credentials = newCredentials;
         LOG.info(
                 "Session credentials updated successfully with access key: {} 
expiration: {}",
-                credentials.getAccessKeyId(),
-                credentials.getExpiration());
+                newCredentials.getAccessKeyId(),
+                
Instant.ofEpochMilli(newCredentials.getExpirationEpochMilli()));

Review Comment:
   Maybe we can use `TimeUtils.formatWithHighestUnit` to have a more meaningful 
representation



##########
flink-filesystems/flink-s3-fs-base/src/main/java/org/apache/flink/fs/s3/common/token/AbstractS3DelegationTokenReceiver.java:
##########
@@ -79,24 +134,25 @@ public void init(Configuration configuration) {
                                 DelegationTokenProvider.CONFIG_PREFIX, 
serviceName()),
                         null);
         if (!StringUtils.isNullOrWhitespaceOnly(region)) {
-            LOG.debug("Region: " + region);
+            LOG.debug("Region: {}", region);
         }
     }
 
     @Override
     public void onNewTokensObtained(byte[] tokens) throws Exception {
         LOG.info("Updating session credentials");
-        credentials =
+        final S3SessionCredentials newCredentials =

Review Comment:
   +1 on this since it's fixing an important race what I've forgot to contrib 
back :)



##########
flink-filesystems/flink-s3-fs-presto/src/main/java/org/apache/flink/fs/s3presto/token/S3PrestoDelegationTokenProvider.java:
##########
@@ -19,13 +19,54 @@
 package org.apache.flink.fs.s3presto.token;
 
 import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
 import org.apache.flink.fs.s3.common.token.AbstractS3DelegationTokenProvider;
+import org.apache.flink.fs.s3.common.token.S3SessionCredentials;
 
-/** Delegation token provider for S3 Presto filesystems. */
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
+import 
com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder;
+import com.amazonaws.services.securitytoken.model.Credentials;
+
+/** Delegation token provider for S3 Presto filesystems, based on AWS SDK v1. 
*/
 @Internal
 public class S3PrestoDelegationTokenProvider extends 
AbstractS3DelegationTokenProvider {
+
     @Override
     public String serviceName() {
         return "s3-presto";
     }
+
+    @Override
+    protected SessionTokenClient createSessionTokenClient(
+            String region, String accessKey, String secretKey) {
+        final AWSSecurityTokenService stsClient = createStsClient(region, 
accessKey, secretKey);
+        return new SessionTokenClient() {
+            @Override
+            public S3SessionCredentials getSessionCredentials() {
+                final Credentials credentials = 
stsClient.getSessionToken().getCredentials();
+                return new S3SessionCredentials(
+                        credentials.getAccessKeyId(),
+                        credentials.getSecretAccessKey(),
+                        credentials.getSessionToken(),
+                        credentials.getExpiration().getTime());
+            }
+
+            @Override
+            public void close() {
+                stsClient.shutdown();

Review Comment:
   Is this best effort or make the obtain cycle fail? It would be good to have 
the first approach



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

Reply via email to