Skip to content

Commit cf4bab5

Browse files
authored
[Fix][Connector-V2] Fixed incorrectly setting s3 key in some cases (#8885)
1 parent 89d1878 commit cf4bab5

File tree

2 files changed

+49
-1
lines changed
  • seatunnel-connectors-v2/connector-file/connector-file-s3/src

2 files changed

+49
-1
lines changed

seatunnel-connectors-v2/connector-file/connector-file-s3/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/s3/config/S3HadoopConf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected String switchHdfsImpl() {
8282

8383
private void putS3SK(Map<String, String> s3Options, ReadonlyConfig config) {
8484
if (!config.getOptional(S3ConfigOptions.S3_ACCESS_KEY).isPresent()
85-
&& config.getOptional(S3ConfigOptions.S3_SECRET_KEY).isPresent()) {
85+
&& !config.getOptional(S3ConfigOptions.S3_SECRET_KEY).isPresent()) {
8686
return;
8787
}
8888
String accessKey = config.get(S3ConfigOptions.S3_ACCESS_KEY);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.connectors.seatunnel.file.s3.config;
19+
20+
import org.apache.seatunnel.api.configuration.ReadonlyConfig;
21+
import org.apache.seatunnel.connectors.seatunnel.file.config.HadoopConf;
22+
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
25+
26+
import java.util.HashMap;
27+
import java.util.Map;
28+
29+
public class S3HadoopConfTest {
30+
31+
@Test
32+
void testPutS3SK() {
33+
Map<String, Object> config = new HashMap<>();
34+
config.put("bucket", "test");
35+
config.put("access_key", "access_key");
36+
config.put("secret_key", "secret_key");
37+
HadoopConf conf = S3HadoopConf.buildWithReadOnlyConfig(ReadonlyConfig.fromMap(config));
38+
Assertions.assertTrue(conf.getExtraOptions().containsKey("fs.s3n.awsAccessKeyId"));
39+
40+
config.remove("access_key");
41+
conf = S3HadoopConf.buildWithReadOnlyConfig(ReadonlyConfig.fromMap(config));
42+
Assertions.assertTrue(conf.getExtraOptions().containsKey("fs.s3n.awsAccessKeyId"));
43+
44+
config.remove("secret_key");
45+
conf = S3HadoopConf.buildWithReadOnlyConfig(ReadonlyConfig.fromMap(config));
46+
Assertions.assertFalse(conf.getExtraOptions().containsKey("fs.s3n.awsAccessKeyId"));
47+
}
48+
}

0 commit comments

Comments
 (0)