From afc244aa302c3c105be6097a58e26b6c69e1a79c Mon Sep 17 00:00:00 2001 From: Eunbin Son Date: Wed, 23 Sep 2026 09:00:45 +0900 Subject: [PATCH] [cosn] Support alternative COSN authentication options Allow the loader to accept the endpoint suffix alternative and defer credential selection to hadoop-cos. Generated-by: Codex --- .../org/apache/paimon/cosn/COSNLoader.java | 4 +- .../apache/paimon/cosn/COSNLoaderTest.java | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 paimon-filesystems/paimon-cosn/src/test/java/org/apache/paimon/cosn/COSNLoaderTest.java diff --git a/paimon-filesystems/paimon-cosn/src/main/java/org/apache/paimon/cosn/COSNLoader.java b/paimon-filesystems/paimon-cosn/src/main/java/org/apache/paimon/cosn/COSNLoader.java index 887ea479be4e..96235989fd2e 100644 --- a/paimon-filesystems/paimon-cosn/src/main/java/org/apache/paimon/cosn/COSNLoader.java +++ b/paimon-filesystems/paimon-cosn/src/main/java/org/apache/paimon/cosn/COSNLoader.java @@ -54,9 +54,7 @@ public String getScheme() { @Override public List requiredOptions() { List options = new ArrayList<>(); - options.add(new String[] {"fs.cosn.bucket.region"}); - options.add(new String[] {"fs.cosn.userinfo.secretId"}); - options.add(new String[] {"fs.cosn.userinfo.secretKey"}); + options.add(new String[] {"fs.cosn.bucket.region", "fs.cosn.bucket.endpoint_suffix"}); return options; } diff --git a/paimon-filesystems/paimon-cosn/src/test/java/org/apache/paimon/cosn/COSNLoaderTest.java b/paimon-filesystems/paimon-cosn/src/test/java/org/apache/paimon/cosn/COSNLoaderTest.java new file mode 100644 index 000000000000..3d816d390305 --- /dev/null +++ b/paimon-filesystems/paimon-cosn/src/test/java/org/apache/paimon/cosn/COSNLoaderTest.java @@ -0,0 +1,69 @@ +/* + * 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.paimon.cosn; + +import org.apache.paimon.catalog.CatalogContext; +import org.apache.paimon.fs.FileIO; +import org.apache.paimon.fs.Path; +import org.apache.paimon.fs.PluginFileIO; +import org.apache.paimon.options.Options; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for {@link COSNLoader}. */ +public class COSNLoaderTest { + + private static final Path COSN_PATH = new Path("cosn://bucket/path"); + + @Test + public void testEndpointSuffixSelectsPluginWithDefaultCredentialChain() throws IOException { + Options options = new Options(); + options.set("fs.cosn.bucket.endpoint_suffix", "cos.example.com"); + + assertCosnPluginSelected(options); + } + + @Test + public void testEndpointSuffixSelectsPluginWithCustomCredentialProvider() throws IOException { + Options options = new Options(); + options.set("fs.cosn.bucket.endpoint_suffix", "cos.example.com"); + options.set("fs.cosn.credentials.provider", "example.CustomCredentialsProvider"); + + assertCosnPluginSelected(options); + } + + @Test + public void testRegionSelectsPluginWithoutStaticCredentials() throws IOException { + Options options = new Options(); + options.set("fs.cosn.bucket.region", "ap-test"); + + assertCosnPluginSelected(options); + } + + private static void assertCosnPluginSelected(Options options) throws IOException { + FileIO fileIO = FileIO.get(COSN_PATH, CatalogContext.create(options)); + + assertThat(fileIO).isInstanceOf(PluginFileIO.class); + assertThat(fileIO.getClass().getEnclosingClass()).isEqualTo(COSNLoader.class); + } +}