This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 08f8e33923 [hotfix] Minor refactor 
DLFAuthProviderFactory.parseRegionFromUri
08f8e33923 is described below

commit 08f8e33923f21bbc22d5a0536e3e51b4e1e758dd
Author: JingsongLi <[email protected]>
AuthorDate: Mon Mar 3 15:29:44 2025 +0800

    [hotfix] Minor refactor DLFAuthProviderFactory.parseRegionFromUri
---
 .../apache/paimon/rest/auth/DLFAuthProviderFactory.java   |  9 +++------
 .../paimon/rest/auth/DLFAuthProviderFactoryTest.java      | 15 ++++++---------
 2 files changed, 9 insertions(+), 15 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/rest/auth/DLFAuthProviderFactory.java
 
b/paimon-core/src/main/java/org/apache/paimon/rest/auth/DLFAuthProviderFactory.java
index c8aff51320..79dd517106 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/rest/auth/DLFAuthProviderFactory.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/rest/auth/DLFAuthProviderFactory.java
@@ -21,7 +21,6 @@ package org.apache.paimon.rest.auth;
 import org.apache.paimon.options.Options;
 import org.apache.paimon.rest.RESTCatalogOptions;
 
-import java.util.Optional;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -40,7 +39,8 @@ public class DLFAuthProviderFactory implements 
AuthProviderFactory {
     @Override
     public AuthProvider create(Options options) {
         String region =
-                getRegion(options.getOptional(RESTCatalogOptions.DLF_REGION), 
options.get(URI));
+                options.getOptional(RESTCatalogOptions.DLF_REGION)
+                        .orElseGet(() -> parseRegionFromUri(options.get(URI)));
         if 
(options.getOptional(RESTCatalogOptions.DLF_TOKEN_PATH).isPresent()) {
             String tokenFilePath = options.get(DLF_TOKEN_PATH);
             long tokenRefreshInMills = 
options.get(TOKEN_REFRESH_TIME).toMillis();
@@ -56,10 +56,7 @@ public class DLFAuthProviderFactory implements 
AuthProviderFactory {
         throw new IllegalArgumentException("DLF token path or AK must be set 
for DLF Auth.");
     }
 
-    protected static String getRegion(Optional<String> region, String uri) {
-        if (region.isPresent()) {
-            return region.get();
-        }
+    protected static String parseRegionFromUri(String uri) {
         try {
             String regex = 
"dlf-(?:pre-)?([a-z]+-[a-z]+(?:-\\d+)?)(?:-internal)?";
 
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/rest/auth/DLFAuthProviderFactoryTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/rest/auth/DLFAuthProviderFactoryTest.java
index c0b6eccd4d..723cf01d08 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/rest/auth/DLFAuthProviderFactoryTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/rest/auth/DLFAuthProviderFactoryTest.java
@@ -20,8 +20,6 @@ package org.apache.paimon.rest.auth;
 
 import org.junit.jupiter.api.Test;
 
-import java.util.Optional;
-
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
@@ -32,20 +30,19 @@ class DLFAuthProviderFactoryTest {
     void getRegion() {
         String region = "cn-hangzhou";
         String ipPortUri = "http://127.0.0.1:8080";;
-        assertEquals(region, 
DLFAuthProviderFactory.getRegion(Optional.of(region), ipPortUri));
         String url = "https://dlf-"; + region + "-internal.aliyuncs.com";
-        assertEquals(region, 
DLFAuthProviderFactory.getRegion(Optional.empty(), url));
+        assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
         url = "https://dlf-"; + region + ".aliyuncs.com";
-        assertEquals(region, 
DLFAuthProviderFactory.getRegion(Optional.empty(), url));
+        assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
         url = "https://dlf-pre-"; + region + ".aliyuncs.com";
-        assertEquals(region, 
DLFAuthProviderFactory.getRegion(Optional.empty(), url));
+        assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
         region = "us-east-1";
         url = "https://dlf-"; + region + ".aliyuncs.com";
-        assertEquals(region, 
DLFAuthProviderFactory.getRegion(Optional.empty(), url));
+        assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
         url = "https://dlf-"; + region + "-internal.aliyuncs.com";
-        assertEquals(region, 
DLFAuthProviderFactory.getRegion(Optional.empty(), url));
+        assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
         assertThrows(
                 IllegalArgumentException.class,
-                () -> DLFAuthProviderFactory.getRegion(Optional.empty(), 
ipPortUri));
+                () -> DLFAuthProviderFactory.parseRegionFromUri(ipPortUri));
     }
 }

Reply via email to