yuqi1129 commented on code in PR #11354:
URL: https://github.com/apache/gravitino/pull/11354#discussion_r3396030216


##########
common/src/main/java/org/apache/gravitino/utils/FetchFileUtils.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+
+/**
+ * Fetches a file referenced by a URI to a local destination. Supports {@code 
file}, {@code http},
+ * {@code https}, {@code ftp} and {@code hdfs} schemes. This is the single 
shared implementation
+ * used by the job manager and the Kerberos clients of the Hive, Iceberg, 
Hadoop and Paimon
+ * catalogs.
+ *
+ * <p>The {@code hdfs} scheme is resolved reflectively against {@code
+ * org.apache.hadoop.fs.FileSystem} so that this class can live in the {@code 
common} module, which
+ * does not declare a compile-time dependency on Hadoop. Callers that never 
use {@code hdfs} URIs
+ * (for example the job manager and the Paimon catalog) simply pass {@code 
null} for the Hadoop
+ * configuration.
+ */
+public final class FetchFileUtils {
+
+  /** The server configuration that controls unsafe remote URI blocking. */
+  public static final String BLOCK_UNSAFE_REMOTE_URI_CONFIG =
+      "gravitino.fetchFile.blockUnsafeRemoteUri";
+
+  private static volatile boolean blockUnsafeRemoteUri = true;
+
+  private FetchFileUtils() {}
+
+  /**
+   * Sets whether remote URIs that resolve to unsafe addresses should be 
blocked.
+   *
+   * @param blockUnsafeRemoteUri whether to block unsafe remote URIs
+   */
+  public static void setBlockUnsafeRemoteUri(boolean blockUnsafeRemoteUri) {
+    FetchFileUtils.blockUnsafeRemoteUri = blockUnsafeRemoteUri;
+  }
+
+  /**
+   * Fetches the file referenced by {@code fileUri} into {@code destFile}.
+   *
+   * @param fileUri the source URI; a missing scheme is treated as {@code file}
+   * @param destFile the local destination file
+   * @param timeoutMs the connect/read timeout in milliseconds, applied to 
remote (http/https/ftp)
+   *     downloads
+   * @param hadoopConf an {@code org.apache.hadoop.conf.Configuration} 
instance, required only for
+   *     the {@code hdfs} scheme; may be {@code null} when no {@code hdfs} URI 
is fetched
+   * @return the absolute path of {@code destFile}
+   * @throws IOException if the file cannot be fetched
+   */
+  public static String fetchFileFromUri(

Review Comment:
   done



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