FANNG1 commented on code in PR #5974:
URL: https://github.com/apache/gravitino/pull/5974#discussion_r1908602750


##########
bundles/gcp/src/main/java/org/apache/gravitino/gcs/fs/GCSFileSystemProvider.java:
##########
@@ -43,9 +50,25 @@ public FileSystem getFileSystem(Path path, Map<String, 
String> config) throws IO
     Configuration configuration = new Configuration();
     FileSystemUtils.toHadoopConfigMap(config, GRAVITINO_KEY_TO_GCS_HADOOP_KEY)
         .forEach(configuration::set);
+
+    if (gravitinoCredentialVendingEnabled(config)) {

Review Comment:
   is this still useful?



##########
bundles/azure/src/main/java/org/apache/gravitino/abs/fs/AzureFileSystemProvider.java:
##########
@@ -67,6 +77,31 @@ public FileSystem getFileSystem(@Nonnull Path path, @Nonnull 
Map<String, String>
     return FileSystem.get(path.toUri(), configuration);
   }
 
+  @Override
+  public Map<String, String> getFileSystemCredentialConf(Credential[] 
credentials) {
+    Credential credential = 
AzureSasCredentialsProvider.getSuitableCredential(credentials);
+    Map<String, String> result = Maps.newHashMap();
+    if (credential instanceof ADLSTokenCredential) {
+      ADLSTokenCredential adlsTokenCredential = (ADLSTokenCredential) 
credential;
+
+      String accountName = adlsTokenCredential.accountName();
+      result.put(FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME + "." + accountName, 
AuthType.SAS.name());
+      result.put(
+          FS_AZURE_SAS_TOKEN_PROVIDER_TYPE + "." + accountName,
+          AzureSasCredentialsProvider.class.getName());
+      result.put(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, "true");
+    } else if (credential instanceof AzureAccountKeyCredential) {
+      AzureAccountKeyCredential azureAccountKeyCredential = 
(AzureAccountKeyCredential) credential;

Review Comment:
   Do you think is it neccesary to pass S3 OSS AKSK to configuration like Azure?



##########
bundles/aliyun/src/main/java/org/apache/gravitino/oss/fs/OSSCredentialsProvider.java:
##########
@@ -0,0 +1,113 @@
+/*
+ *  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.gravitino.oss.fs;
+
+import com.aliyun.oss.common.auth.BasicCredentials;
+import com.aliyun.oss.common.auth.Credentials;
+import com.aliyun.oss.common.auth.CredentialsProvider;
+import com.aliyun.oss.common.auth.DefaultCredentials;
+import java.net.URI;
+import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
+import 
org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.credential.OSSSecretKeyCredential;
+import org.apache.gravitino.credential.OSSTokenCredential;
+import org.apache.hadoop.conf.Configuration;
+
+public class OSSCredentialsProvider implements CredentialsProvider {
+
+  private GravitinoFileSystemCredentialsProvider 
gravitinoFileSystemCredentialsProvider;
+  private Credentials basicCredentials;
+  private long expirationTime = Long.MAX_VALUE;
+  private static final double EXPIRATION_TIME_FACTOR = 0.9D;

Review Comment:
   should we align the factor with python to 0.5?



##########
bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3FileSystemProvider.java:
##########
@@ -61,18 +68,34 @@ public FileSystem getFileSystem(Path path, Map<String, 
String> config) throws IO
     Map<String, String> hadoopConfMap =
         FileSystemUtils.toHadoopConfigMap(config, 
GRAVITINO_KEY_TO_S3_HADOOP_KEY);
 
+    hadoopConfMap.forEach(configuration::set);
     if (!hadoopConfMap.containsKey(S3_CREDENTIAL_KEY)) {
-      hadoopConfMap.put(S3_CREDENTIAL_KEY, S3_SIMPLE_CREDENTIAL);
+      configuration.set(S3_CREDENTIAL_KEY, S3_SIMPLE_CREDENTIAL);
     }
 
-    hadoopConfMap.forEach(configuration::set);
+    if (gravitinoCredentialVendingEnabled(config)) {

Review Comment:
   is this still neccesary?



##########
clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/DefaultGravitinoFileSystemCredentialsProvider.java:
##########
@@ -0,0 +1,84 @@
+/*
+ *  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.gravitino.filesystem.hadoop;
+
+import com.google.common.base.Preconditions;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.NameIdentifier;
+import 
org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.client.GravitinoClient;
+import org.apache.gravitino.credential.Credential;
+import org.apache.gravitino.file.Fileset;
+import org.apache.gravitino.file.FilesetCatalog;
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * Default implementation of {@link GravitinoFileSystemCredentialsProvider} 
which provides
+ * credentials for Gravitino Virtual File System.
+ */
+public class DefaultGravitinoFileSystemCredentialsProvider
+    implements GravitinoFileSystemCredentialsProvider {
+
+  private Configuration configuration;
+
+  private static final Pattern IDENTIFIER_PATTERN =
+      
Pattern.compile("^(?:gvfs://fileset)?/([^/]+)/([^/]+)/([^/]+)(?>/[^/]+)*/?$");
+
+  @Override
+  public void setConf(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  @Override
+  public Configuration getConf() {
+    return configuration;
+  }
+
+  @Override
+  public Credential[] getCredentials() {
+    String virtualPath = configuration.get(GVFS_PATH);

Review Comment:
   @yuqi1129 could you change to `NameIdentifier`? I couldn't see the benefit 
to use path



##########
bundles/azure/src/main/java/org/apache/gravitino/abs/fs/AzureSasCredentialsProvider.java:
##########
@@ -0,0 +1,113 @@
+/*
+ *  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.gravitino.abs.fs;
+
+import java.io.IOException;
+import org.apache.gravitino.catalog.hadoop.fs.FileSystemUtils;
+import 
org.apache.gravitino.catalog.hadoop.fs.GravitinoFileSystemCredentialsProvider;
+import org.apache.gravitino.credential.ADLSTokenCredential;
+import org.apache.gravitino.credential.AzureAccountKeyCredential;
+import org.apache.gravitino.credential.Credential;
+import org.apache.hadoop.conf.Configurable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.azurebfs.extensions.SASTokenProvider;
+
+public class AzureSasCredentialsProvider implements SASTokenProvider, 
Configurable {
+
+  private Configuration configuration;
+  private String sasToken;
+
+  private GravitinoFileSystemCredentialsProvider 
gravitinoFileSystemCredentialsProvider;
+  private long expirationTime = Long.MAX_VALUE;
+  private static final double EXPIRATION_TIME_FACTOR = 0.9D;
+
+  @Override
+  public void setConf(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  @Override
+  public Configuration getConf() {
+    return configuration;
+  }
+
+  @Override
+  public void initialize(Configuration conf, String accountName) throws 
IOException {
+    this.configuration = conf;
+    this.gravitinoFileSystemCredentialsProvider = 
FileSystemUtils.getGvfsCredentialProvider(conf);
+  }
+
+  @Override
+  public String getSASToken(String account, String fileSystem, String path, 
String operation) {
+    // Refresh credentials if they are null or about to expire.
+    if (sasToken == null || System.currentTimeMillis() >= expirationTime) {
+      synchronized (this) {
+        refresh();
+      }
+    }
+    return sasToken;
+  }
+
+  private void refresh() {
+    Credential[] gravitinoCredentials = 
gravitinoFileSystemCredentialsProvider.getCredentials();
+    Credential credential = getSuitableCredential(gravitinoCredentials);
+    if (credential == null) {
+      throw new RuntimeException("No suitable credential for OSS found...");
+    }
+
+    if (credential instanceof ADLSTokenCredential) {
+      ADLSTokenCredential adlsTokenCredential = (ADLSTokenCredential) 
credential;
+      sasToken = adlsTokenCredential.sasToken();
+    }
+
+    if (credential.expireTimeInMs() > 0) {
+      expirationTime =
+          System.currentTimeMillis()
+              + (long)
+                  ((credential.expireTimeInMs() - System.currentTimeMillis())
+                      * EXPIRATION_TIME_FACTOR);
+    }
+  }
+
+  /**
+   * Get the credential from the credential array. Using dynamic credential 
first, if not found,
+   * uses static credential.
+   *
+   * @param credentials The credential array.
+   * @return A credential. Null if not found.
+   */
+  static Credential getSuitableCredential(Credential[] credentials) {
+    // Use dynamic credential if found.
+    for (Credential credential : credentials) {
+      if (credential instanceof ADLSTokenCredential) {
+        return credential;
+      }
+    }
+
+    // If dynamic credential not found, use the static one
+    for (Credential credential : credentials) {

Review Comment:
   no need static credentail here?



##########
catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/CredentialUtils.java:
##########
@@ -0,0 +1,36 @@
+/*
+ *  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.gravitino.catalog.hadoop.fs;
+
+import java.util.Map;
+
+/** Utility class for Gravitino Virtual File System. */
+public class CredentialUtils {
+
+  /**
+   * Check if Gravitino credential vending is enabled.
+   *
+   * @param config The configuration for Gravitino Virtual File System.
+   * @return true if Gravitino credential vending is enabled, false otherwise.
+   */
+  public static boolean gravitinoCredentialVendingEnabled(Map<String, String> 
config) {

Review Comment:
   is this still useful?



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