Skip to content

Commit 08f8e33

Browse files
committed
[hotfix] Minor refactor DLFAuthProviderFactory.parseRegionFromUri
1 parent 9a8f63f commit 08f8e33

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

paimon-core/src/main/java/org/apache/paimon/rest/auth/DLFAuthProviderFactory.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.paimon.options.Options;
2222
import org.apache.paimon.rest.RESTCatalogOptions;
2323

24-
import java.util.Optional;
2524
import java.util.regex.Matcher;
2625
import java.util.regex.Pattern;
2726

@@ -40,7 +39,8 @@ public String identifier() {
4039
@Override
4140
public AuthProvider create(Options options) {
4241
String region =
43-
getRegion(options.getOptional(RESTCatalogOptions.DLF_REGION), options.get(URI));
42+
options.getOptional(RESTCatalogOptions.DLF_REGION)
43+
.orElseGet(() -> parseRegionFromUri(options.get(URI)));
4444
if (options.getOptional(RESTCatalogOptions.DLF_TOKEN_PATH).isPresent()) {
4545
String tokenFilePath = options.get(DLF_TOKEN_PATH);
4646
long tokenRefreshInMills = options.get(TOKEN_REFRESH_TIME).toMillis();
@@ -56,10 +56,7 @@ public AuthProvider create(Options options) {
5656
throw new IllegalArgumentException("DLF token path or AK must be set for DLF Auth.");
5757
}
5858

59-
protected static String getRegion(Optional<String> region, String uri) {
60-
if (region.isPresent()) {
61-
return region.get();
62-
}
59+
protected static String parseRegionFromUri(String uri) {
6360
try {
6461
String regex = "dlf-(?:pre-)?([a-z]+-[a-z]+(?:-\\d+)?)(?:-internal)?";
6562

paimon-core/src/test/java/org/apache/paimon/rest/auth/DLFAuthProviderFactoryTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23-
import java.util.Optional;
24-
2523
import static org.junit.jupiter.api.Assertions.assertEquals;
2624
import static org.junit.jupiter.api.Assertions.assertThrows;
2725

@@ -32,20 +30,19 @@ class DLFAuthProviderFactoryTest {
3230
void getRegion() {
3331
String region = "cn-hangzhou";
3432
String ipPortUri = "http://127.0.0.1:8080";
35-
assertEquals(region, DLFAuthProviderFactory.getRegion(Optional.of(region), ipPortUri));
3633
String url = "https://dlf-" + region + "-internal.aliyuncs.com";
37-
assertEquals(region, DLFAuthProviderFactory.getRegion(Optional.empty(), url));
34+
assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
3835
url = "https://dlf-" + region + ".aliyuncs.com";
39-
assertEquals(region, DLFAuthProviderFactory.getRegion(Optional.empty(), url));
36+
assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
4037
url = "https://dlf-pre-" + region + ".aliyuncs.com";
41-
assertEquals(region, DLFAuthProviderFactory.getRegion(Optional.empty(), url));
38+
assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
4239
region = "us-east-1";
4340
url = "https://dlf-" + region + ".aliyuncs.com";
44-
assertEquals(region, DLFAuthProviderFactory.getRegion(Optional.empty(), url));
41+
assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
4542
url = "https://dlf-" + region + "-internal.aliyuncs.com";
46-
assertEquals(region, DLFAuthProviderFactory.getRegion(Optional.empty(), url));
43+
assertEquals(region, DLFAuthProviderFactory.parseRegionFromUri(url));
4744
assertThrows(
4845
IllegalArgumentException.class,
49-
() -> DLFAuthProviderFactory.getRegion(Optional.empty(), ipPortUri));
46+
() -> DLFAuthProviderFactory.parseRegionFromUri(ipPortUri));
5047
}
5148
}

0 commit comments

Comments
 (0)