gaborgsomogyi commented on code in PR #27788:
URL: https://github.com/apache/flink/pull/27788#discussion_r3160056680
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystemFactory.java:
##########
@@ -310,9 +316,51 @@ public FileSystem create(URI fsUri) throws IOException {
String region = config.get(REGION);
String endpoint = config.get(ENDPOINT);
boolean pathStyleAccess = config.get(PATH_STYLE_ACCESS);
+ String sseType = config.get(SSE_TYPE);
+ String sseKmsKeyId = config.get(SSE_KMS_KEY_ID);
+ String assumeRoleArn = config.get(ASSUME_ROLE_ARN);
+ String assumeRoleExternalId = config.get(ASSUME_ROLE_EXTERNAL_ID);
+ String assumeRoleSessionName = config.get(ASSUME_ROLE_SESSION_NAME);
+ int assumeRoleSessionDuration =
config.get(ASSUME_ROLE_SESSION_DURATION_SECONDS);
+ String credentialsProviderClasses =
config.get(AWS_CREDENTIALS_PROVIDER);
+
+ // Apply bucket-specific overrides
+ String bucketName = fsUri.getHost();
+ if (bucketName == null || bucketName.isEmpty()) {
Review Comment:
`StringUtils.isNullOrWhitespaceOnly` is a more simple and safe
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/BucketConfigProvider.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.flink.fs.s3native;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+
+/**
+ * Parses bucket-specific S3 configuration using format {@code
s3.bucket.<bucket-name>.<property>}.
+ *
+ * <p>Enables per-bucket overrides for endpoints, credentials, encryption, and
IAM roles. Bucket
+ * names containing dots are supported; properties are matched by longest
suffix first.
+ *
+ * <p>Immutable and thread-safe after construction.
+ */
+@Internal
+final class BucketConfigProvider {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(BucketConfigProvider.class);
+ static final String BUCKET_CONFIG_PREFIX = "s3.bucket.";
+ static final Map<String, BiConsumer<S3BucketConfig.Builder, String>>
PROPERTY_APPLICATORS;
+ static final List<String> KNOWN_PROPERTIES_BY_LENGTH;
+
+ static {
+ final Map<String, BiConsumer<S3BucketConfig.Builder, String>>
applicators =
+ new LinkedHashMap<>();
+ applicators.put("access-key", (b, v) -> b.accessKey(v));
+ applicators.put("assume-role.arn", (b, v) -> b.assumeRoleArn(v));
+ applicators.put("assume-role.external-id", (b, v) ->
b.assumeRoleExternalId(v));
+ applicators.put(
+ "assume-role.session-duration",
+ (b, v) -> {
+ try {
+
b.assumeRoleSessionDurationSeconds(Integer.parseInt(v));
+ } catch (NumberFormatException e) {
+ throw new IllegalConfigurationException(
+ String.format(
+ "Invalid assume-role.session-duration
'%s' for bucket '%s'. "
+ + "Must be a valid integer
(e.g., 3600)",
+ v, b.getBucketName()),
+ e);
+ }
+ });
+ applicators.put("assume-role.session-name", (b, v) ->
b.assumeRoleSessionName(v));
+ applicators.put("credentials.provider", (b, v) ->
b.credentialsProvider(v));
+ applicators.put("endpoint", (b, v) -> b.endpoint(v));
+ applicators.put("path-style-access", (b, v) ->
b.pathStyleAccess(Boolean.parseBoolean(v)));
+ applicators.put("region", (b, v) -> b.region(v));
+ applicators.put("sse.kms-key-id", (b, v) -> b.sseKmsKeyId(v));
+ applicators.put("sse.type", (b, v) -> b.sseType(v));
+ applicators.put("secret-key", (b, v) -> b.secretKey(v));
+ PROPERTY_APPLICATORS = Collections.unmodifiableMap(applicators);
+
+ KNOWN_PROPERTIES_BY_LENGTH =
+ applicators.keySet().stream()
+
.sorted(Comparator.comparingInt(String::length).reversed())
+ .collect(Collectors.toList());
+ }
+
+ private final Map<String, S3BucketConfig> bucketConfigs;
+
+ BucketConfigProvider(Configuration flinkConfig) {
+ this.bucketConfigs =
Collections.unmodifiableMap(parseBucketConfigs(flinkConfig));
+ }
+
+ @Nullable
+ S3BucketConfig getBucketConfig(String bucketName) {
+ return bucketConfigs.get(bucketName);
+ }
+
+ @VisibleForTesting
+ boolean hasBucketConfig(String bucketName) {
+ return bucketConfigs.containsKey(bucketName);
+ }
+
+ @VisibleForTesting
+ int size() {
+ return bucketConfigs.size();
+ }
+
+ private static Map<String, S3BucketConfig>
parseBucketConfigs(Configuration flinkConfig) {
+ final Map<String, Map<String, String>> rawConfigs = new HashMap<>();
+
+ for (final String key : flinkConfig.keySet()) {
+ if (!key.startsWith(BUCKET_CONFIG_PREFIX)) {
+ continue;
+ }
+ final String suffix = key.substring(BUCKET_CONFIG_PREFIX.length());
+ if (suffix.isBlank()) {
Review Comment:
`StringUtils.isNullOrWhitespaceOnly` is a more simple and safe
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystemFactory.java:
##########
@@ -190,15 +195,14 @@ public class NativeS3FileSystemFactory implements
FileSystemFactory {
+ "Example:
'arn:aws:kms:us-east-1:123456789:key/12345678-1234-1234-1234-123456789abc' "
+ "or 'alias/my-s3-key'");
- // IAM Assume Role Configuration
Review Comment:
I think this change is not needed
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystemFactory.java:
##########
@@ -190,15 +195,14 @@ public class NativeS3FileSystemFactory implements
FileSystemFactory {
+ "Example:
'arn:aws:kms:us-east-1:123456789:key/12345678-1234-1234-1234-123456789abc' "
+ "or 'alias/my-s3-key'");
- // IAM Assume Role Configuration
public static final ConfigOption<String> ASSUME_ROLE_ARN =
ConfigOptions.key("s3.assume-role.arn")
.stringType()
.noDefaultValue()
.withDescription(
"ARN of the IAM role to assume for S3 access. "
- + "Enables cross-account access or
temporary elevated permissions. "
- + "Example:
'arn:aws:iam::123456789012:role/S3AccessRole'");
+ + "Examples:
'arn:aws:iam::123456789012:role/S3AccessRole' (aws), "
+ +
"'arn:aws-cn:iam::123456789012:role/S3AccessRole' (aws-cn)");
Review Comment:
I think these changes are not needed
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/BucketConfigProvider.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.flink.fs.s3native;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+
+/**
+ * Parses bucket-specific S3 configuration using format {@code
s3.bucket.<bucket-name>.<property>}.
+ *
+ * <p>Enables per-bucket overrides for endpoints, credentials, encryption, and
IAM roles. Bucket
+ * names containing dots are supported; properties are matched by longest
suffix first.
+ *
+ * <p>Immutable and thread-safe after construction.
+ */
+@Internal
+final class BucketConfigProvider {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(BucketConfigProvider.class);
+ static final String BUCKET_CONFIG_PREFIX = "s3.bucket.";
+ static final Map<String, BiConsumer<S3BucketConfig.Builder, String>>
PROPERTY_APPLICATORS;
+ static final List<String> KNOWN_PROPERTIES_BY_LENGTH;
+
+ static {
+ final Map<String, BiConsumer<S3BucketConfig.Builder, String>>
applicators =
+ new LinkedHashMap<>();
+ applicators.put("access-key", (b, v) -> b.accessKey(v));
+ applicators.put("assume-role.arn", (b, v) -> b.assumeRoleArn(v));
+ applicators.put("assume-role.external-id", (b, v) ->
b.assumeRoleExternalId(v));
+ applicators.put(
+ "assume-role.session-duration",
+ (b, v) -> {
+ try {
+
b.assumeRoleSessionDurationSeconds(Integer.parseInt(v));
+ } catch (NumberFormatException e) {
+ throw new IllegalConfigurationException(
+ String.format(
+ "Invalid assume-role.session-duration
'%s' for bucket '%s'. "
+ + "Must be a valid integer
(e.g., 3600)",
+ v, b.getBucketName()),
+ e);
+ }
+ });
+ applicators.put("assume-role.session-name", (b, v) ->
b.assumeRoleSessionName(v));
+ applicators.put("credentials.provider", (b, v) ->
b.credentialsProvider(v));
+ applicators.put("endpoint", (b, v) -> b.endpoint(v));
+ applicators.put("path-style-access", (b, v) ->
b.pathStyleAccess(Boolean.parseBoolean(v)));
+ applicators.put("region", (b, v) -> b.region(v));
+ applicators.put("sse.kms-key-id", (b, v) -> b.sseKmsKeyId(v));
+ applicators.put("sse.type", (b, v) -> b.sseType(v));
+ applicators.put("secret-key", (b, v) -> b.secretKey(v));
+ PROPERTY_APPLICATORS = Collections.unmodifiableMap(applicators);
+
+ KNOWN_PROPERTIES_BY_LENGTH =
+ applicators.keySet().stream()
+
.sorted(Comparator.comparingInt(String::length).reversed())
+ .collect(Collectors.toList());
+ }
+
+ private final Map<String, S3BucketConfig> bucketConfigs;
+
+ BucketConfigProvider(Configuration flinkConfig) {
+ this.bucketConfigs =
Collections.unmodifiableMap(parseBucketConfigs(flinkConfig));
+ }
+
+ @Nullable
+ S3BucketConfig getBucketConfig(String bucketName) {
+ return bucketConfigs.get(bucketName);
+ }
+
+ @VisibleForTesting
+ boolean hasBucketConfig(String bucketName) {
+ return bucketConfigs.containsKey(bucketName);
+ }
+
+ @VisibleForTesting
+ int size() {
+ return bucketConfigs.size();
+ }
+
+ private static Map<String, S3BucketConfig>
parseBucketConfigs(Configuration flinkConfig) {
+ final Map<String, Map<String, String>> rawConfigs = new HashMap<>();
+
+ for (final String key : flinkConfig.keySet()) {
+ if (!key.startsWith(BUCKET_CONFIG_PREFIX)) {
+ continue;
+ }
+ final String suffix = key.substring(BUCKET_CONFIG_PREFIX.length());
+ if (suffix.isBlank()) {
+ continue;
+ }
+ final String value = flinkConfig.getString(key, null);
+ if (value == null) {
+ continue;
+ }
+
+ for (final String prop : KNOWN_PROPERTIES_BY_LENGTH) {
+ if (suffix.endsWith("." + prop)) {
+ final String bucketName =
+ suffix.substring(0, suffix.length() -
prop.length() - 1);
+ if (bucketName.isEmpty()) {
Review Comment:
`StringUtils.isNullOrWhitespaceOnly` is a more simple and safe (I know null
can't be :)).
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/BucketConfigProvider.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.flink.fs.s3native;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
+
+/**
+ * Parses bucket-specific S3 configuration using format {@code
s3.bucket.<bucket-name>.<property>}.
+ *
+ * <p>Enables per-bucket overrides for endpoints, credentials, encryption, and
IAM roles. Bucket
+ * names containing dots are supported; properties are matched by longest
suffix first.
+ *
+ * <p>Immutable and thread-safe after construction.
+ */
+@Internal
+final class BucketConfigProvider {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(BucketConfigProvider.class);
+ static final String BUCKET_CONFIG_PREFIX = "s3.bucket.";
+ static final Map<String, BiConsumer<S3BucketConfig.Builder, String>>
PROPERTY_APPLICATORS;
+ static final List<String> KNOWN_PROPERTIES_BY_LENGTH;
+
+ static {
+ final Map<String, BiConsumer<S3BucketConfig.Builder, String>>
applicators =
+ new LinkedHashMap<>();
+ applicators.put("access-key", (b, v) -> b.accessKey(v));
+ applicators.put("assume-role.arn", (b, v) -> b.assumeRoleArn(v));
+ applicators.put("assume-role.external-id", (b, v) ->
b.assumeRoleExternalId(v));
+ applicators.put(
+ "assume-role.session-duration",
+ (b, v) -> {
+ try {
+
b.assumeRoleSessionDurationSeconds(Integer.parseInt(v));
+ } catch (NumberFormatException e) {
+ throw new IllegalConfigurationException(
+ String.format(
+ "Invalid assume-role.session-duration
'%s' for bucket '%s'. "
+ + "Must be a valid integer
(e.g., 3600)",
+ v, b.getBucketName()),
+ e);
+ }
+ });
+ applicators.put("assume-role.session-name", (b, v) ->
b.assumeRoleSessionName(v));
+ applicators.put("credentials.provider", (b, v) ->
b.credentialsProvider(v));
+ applicators.put("endpoint", (b, v) -> b.endpoint(v));
+ applicators.put("path-style-access", (b, v) ->
b.pathStyleAccess(Boolean.parseBoolean(v)));
+ applicators.put("region", (b, v) -> b.region(v));
+ applicators.put("sse.kms-key-id", (b, v) -> b.sseKmsKeyId(v));
+ applicators.put("sse.type", (b, v) -> b.sseType(v));
+ applicators.put("secret-key", (b, v) -> b.secretKey(v));
+ PROPERTY_APPLICATORS = Collections.unmodifiableMap(applicators);
+
+ KNOWN_PROPERTIES_BY_LENGTH =
+ applicators.keySet().stream()
+
.sorted(Comparator.comparingInt(String::length).reversed())
+ .collect(Collectors.toList());
+ }
+
+ private final Map<String, S3BucketConfig> bucketConfigs;
+
+ BucketConfigProvider(Configuration flinkConfig) {
+ this.bucketConfigs =
Collections.unmodifiableMap(parseBucketConfigs(flinkConfig));
+ }
+
+ @Nullable
+ S3BucketConfig getBucketConfig(String bucketName) {
+ return bucketConfigs.get(bucketName);
+ }
+
+ @VisibleForTesting
+ boolean hasBucketConfig(String bucketName) {
+ return bucketConfigs.containsKey(bucketName);
+ }
+
+ @VisibleForTesting
+ int size() {
+ return bucketConfigs.size();
+ }
+
+ private static Map<String, S3BucketConfig>
parseBucketConfigs(Configuration flinkConfig) {
+ final Map<String, Map<String, String>> rawConfigs = new HashMap<>();
+
+ for (final String key : flinkConfig.keySet()) {
+ if (!key.startsWith(BUCKET_CONFIG_PREFIX)) {
+ continue;
+ }
+ final String suffix = key.substring(BUCKET_CONFIG_PREFIX.length());
+ if (suffix.isBlank()) {
+ continue;
+ }
+ final String value = flinkConfig.getString(key, null);
+ if (value == null) {
Review Comment:
`StringUtils.isNullOrWhitespaceOnly` is a more simple and safe
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3BucketConfig.java:
##########
@@ -0,0 +1,328 @@
+/*
+ * 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.flink.fs.s3native;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+
+import javax.annotation.Nullable;
+
+import java.util.Objects;
+
+/**
+ * Immutable, bucket-specific S3 configuration overrides.
+ *
+ * <p>Null values indicate inheritance from global configuration. Only
explicitly configured values
+ * are non-null. Configuration format: {@code
s3.bucket.<bucket-name>.<property>}
+ *
+ * <p>Validates that credentials (access-key/secret-key) are either both set
or both absent.
+ */
+@Internal
+final class S3BucketConfig {
+
+ private final String bucketName;
+ @Nullable private final String region;
+ @Nullable private final String endpoint;
+ @Nullable private final Boolean pathStyleAccess;
+ @Nullable private final String accessKey;
+ @Nullable private final String secretKey;
+ @Nullable private final String sseType;
+ @Nullable private final String sseKmsKeyId;
+ @Nullable private final String assumeRoleArn;
+ @Nullable private final String assumeRoleExternalId;
+ @Nullable private final String assumeRoleSessionName;
+ @Nullable private final Integer assumeRoleSessionDurationSeconds;
+ @Nullable private final String credentialsProvider;
+
+ private S3BucketConfig(Builder builder) {
+ this.bucketName = builder.bucketName;
+ this.region = builder.region;
+ this.endpoint = builder.endpoint;
+ this.pathStyleAccess = builder.pathStyleAccess;
+ this.accessKey = builder.accessKey;
+ this.secretKey = builder.secretKey;
+ this.sseType = builder.sseType;
+ this.sseKmsKeyId = builder.sseKmsKeyId;
+ this.assumeRoleArn = builder.assumeRoleArn;
+ this.assumeRoleExternalId = builder.assumeRoleExternalId;
+ this.assumeRoleSessionName = builder.assumeRoleSessionName;
+ this.assumeRoleSessionDurationSeconds =
builder.assumeRoleSessionDurationSeconds;
+ this.credentialsProvider = builder.credentialsProvider;
+ }
+
+ String getBucketName() {
+ return bucketName;
+ }
+
+ @Nullable
+ String getRegion() {
+ return region;
+ }
+
+ @Nullable
+ String getEndpoint() {
+ return endpoint;
+ }
+
+ @Nullable
+ Boolean getPathStyleAccess() {
+ return pathStyleAccess;
+ }
+
+ @Nullable
+ String getAccessKey() {
+ return accessKey;
+ }
+
+ @Nullable
+ String getSecretKey() {
+ return secretKey;
+ }
+
+ @Nullable
+ String getSseType() {
+ return sseType;
+ }
+
+ @Nullable
+ String getSseKmsKeyId() {
+ return sseKmsKeyId;
+ }
+
+ @Nullable
+ String getAssumeRoleArn() {
+ return assumeRoleArn;
+ }
+
+ @Nullable
+ String getAssumeRoleExternalId() {
+ return assumeRoleExternalId;
+ }
+
+ @Nullable
+ String getAssumeRoleSessionName() {
+ return assumeRoleSessionName;
+ }
+
+ @Nullable
+ Integer getAssumeRoleSessionDurationSeconds() {
+ return assumeRoleSessionDurationSeconds;
+ }
+
+ @Nullable
+ String getCredentialsProvider() {
+ return credentialsProvider;
+ }
+
+ boolean hasAnyOverride() {
+ return region != null
+ || endpoint != null
+ || pathStyleAccess != null
+ || accessKey != null
+ || secretKey != null
+ || sseType != null
+ || sseKmsKeyId != null
+ || assumeRoleArn != null
+ || assumeRoleExternalId != null
+ || assumeRoleSessionName != null
+ || assumeRoleSessionDurationSeconds != null
+ || credentialsProvider != null;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ S3BucketConfig that = (S3BucketConfig) o;
+ return Objects.equals(bucketName, that.bucketName)
+ && Objects.equals(region, that.region)
+ && Objects.equals(endpoint, that.endpoint)
+ && Objects.equals(pathStyleAccess, that.pathStyleAccess)
+ && Objects.equals(accessKey, that.accessKey)
+ && Objects.equals(secretKey, that.secretKey)
+ && Objects.equals(sseType, that.sseType)
+ && Objects.equals(sseKmsKeyId, that.sseKmsKeyId)
+ && Objects.equals(assumeRoleArn, that.assumeRoleArn)
+ && Objects.equals(assumeRoleExternalId,
that.assumeRoleExternalId)
+ && Objects.equals(assumeRoleSessionName,
that.assumeRoleSessionName)
+ && Objects.equals(
+ assumeRoleSessionDurationSeconds,
that.assumeRoleSessionDurationSeconds)
+ && Objects.equals(credentialsProvider,
that.credentialsProvider);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ bucketName,
+ region,
+ endpoint,
+ pathStyleAccess,
+ accessKey,
+ secretKey,
+ sseType,
+ sseKmsKeyId,
+ assumeRoleArn,
+ assumeRoleExternalId,
+ assumeRoleSessionName,
+ assumeRoleSessionDurationSeconds,
+ credentialsProvider);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("S3BucketConfig{");
+ sb.append("bucket='").append(bucketName).append("'");
+ if (region != null) {
+ sb.append(", region='").append(region).append("'");
+ }
+ if (endpoint != null) {
+ sb.append(", endpoint='").append(endpoint).append("'");
+ }
+ if (pathStyleAccess != null) {
+ sb.append(", pathStyleAccess=").append(pathStyleAccess);
+ }
+ if (accessKey != null) {
+ sb.append(",
credentials=").append(GlobalConfiguration.HIDDEN_CONTENT);
+ }
+ if (sseType != null) {
+ sb.append(", sseType='").append(sseType).append("'");
+ }
+ if (assumeRoleArn != null) {
+ sb.append(", assumeRoleArn='").append(assumeRoleArn).append("'");
+ }
+ if (credentialsProvider != null) {
+ sb.append(",
credentialsProvider='").append(credentialsProvider).append("'");
+ }
+ sb.append('}');
+ return sb.toString();
+ }
+
+ static Builder builder(String bucketName) {
+ if (bucketName == null || bucketName.isEmpty()) {
+ throw new IllegalArgumentException("Bucket name must not be null
or empty");
+ }
+ return new Builder(bucketName);
+ }
+
+ static final class Builder {
+ private final String bucketName;
+ @Nullable private String region;
+ @Nullable private String endpoint;
+ @Nullable private Boolean pathStyleAccess;
+ @Nullable private String accessKey;
+ @Nullable private String secretKey;
+ @Nullable private String sseType;
+ @Nullable private String sseKmsKeyId;
+ @Nullable private String assumeRoleArn;
+ @Nullable private String assumeRoleExternalId;
+ @Nullable private String assumeRoleSessionName;
+ @Nullable private Integer assumeRoleSessionDurationSeconds;
+ @Nullable private String credentialsProvider;
+
+ private Builder(String bucketName) {
+ this.bucketName = bucketName;
+ }
+
+ String getBucketName() {
+ return bucketName;
+ }
+
+ Builder region(String region) {
+ this.region = region;
+ return this;
+ }
+
+ Builder endpoint(String endpoint) {
+ this.endpoint = endpoint;
+ return this;
+ }
+
+ Builder pathStyleAccess(boolean pathStyleAccess) {
+ this.pathStyleAccess = pathStyleAccess;
+ return this;
+ }
+
+ Builder accessKey(String accessKey) {
+ this.accessKey = accessKey;
+ return this;
+ }
+
+ Builder secretKey(String secretKey) {
+ this.secretKey = secretKey;
+ return this;
+ }
+
+ Builder sseType(String sseType) {
+ this.sseType = sseType;
+ return this;
+ }
+
+ Builder sseKmsKeyId(String sseKmsKeyId) {
+ this.sseKmsKeyId = sseKmsKeyId;
+ return this;
+ }
+
+ Builder assumeRoleArn(String assumeRoleArn) {
+ this.assumeRoleArn = assumeRoleArn;
+ return this;
+ }
+
+ Builder assumeRoleExternalId(String assumeRoleExternalId) {
+ this.assumeRoleExternalId = assumeRoleExternalId;
+ return this;
+ }
+
+ Builder assumeRoleSessionName(String assumeRoleSessionName) {
+ this.assumeRoleSessionName = assumeRoleSessionName;
+ return this;
+ }
+
+ Builder assumeRoleSessionDurationSeconds(int seconds) {
+ this.assumeRoleSessionDurationSeconds = seconds;
+ return this;
+ }
+
+ Builder credentialsProvider(String credentialsProvider) {
+ this.credentialsProvider = credentialsProvider;
+ return this;
+ }
+
+ S3BucketConfig build() {
+ boolean hasAccessKey = accessKey != null && !accessKey.isEmpty();
+ boolean hasSecretKey = secretKey != null && !secretKey.isEmpty();
Review Comment:
Maybe `StringUtils.isNullOrWhitespaceOnly` here too?
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3BucketConfig.java:
##########
@@ -0,0 +1,328 @@
+/*
+ * 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.flink.fs.s3native;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+
+import javax.annotation.Nullable;
+
+import java.util.Objects;
+
+/**
+ * Immutable, bucket-specific S3 configuration overrides.
+ *
+ * <p>Null values indicate inheritance from global configuration. Only
explicitly configured values
+ * are non-null. Configuration format: {@code
s3.bucket.<bucket-name>.<property>}
+ *
+ * <p>Validates that credentials (access-key/secret-key) are either both set
or both absent.
+ */
+@Internal
+final class S3BucketConfig {
+
+ private final String bucketName;
+ @Nullable private final String region;
+ @Nullable private final String endpoint;
+ @Nullable private final Boolean pathStyleAccess;
+ @Nullable private final String accessKey;
+ @Nullable private final String secretKey;
+ @Nullable private final String sseType;
+ @Nullable private final String sseKmsKeyId;
+ @Nullable private final String assumeRoleArn;
+ @Nullable private final String assumeRoleExternalId;
+ @Nullable private final String assumeRoleSessionName;
+ @Nullable private final Integer assumeRoleSessionDurationSeconds;
+ @Nullable private final String credentialsProvider;
+
+ private S3BucketConfig(Builder builder) {
+ this.bucketName = builder.bucketName;
+ this.region = builder.region;
+ this.endpoint = builder.endpoint;
+ this.pathStyleAccess = builder.pathStyleAccess;
+ this.accessKey = builder.accessKey;
+ this.secretKey = builder.secretKey;
+ this.sseType = builder.sseType;
+ this.sseKmsKeyId = builder.sseKmsKeyId;
+ this.assumeRoleArn = builder.assumeRoleArn;
+ this.assumeRoleExternalId = builder.assumeRoleExternalId;
+ this.assumeRoleSessionName = builder.assumeRoleSessionName;
+ this.assumeRoleSessionDurationSeconds =
builder.assumeRoleSessionDurationSeconds;
+ this.credentialsProvider = builder.credentialsProvider;
+ }
+
+ String getBucketName() {
+ return bucketName;
+ }
+
+ @Nullable
+ String getRegion() {
+ return region;
+ }
+
+ @Nullable
+ String getEndpoint() {
+ return endpoint;
+ }
+
+ @Nullable
+ Boolean getPathStyleAccess() {
+ return pathStyleAccess;
+ }
+
+ @Nullable
+ String getAccessKey() {
+ return accessKey;
+ }
+
+ @Nullable
+ String getSecretKey() {
+ return secretKey;
+ }
+
+ @Nullable
+ String getSseType() {
+ return sseType;
+ }
+
+ @Nullable
+ String getSseKmsKeyId() {
+ return sseKmsKeyId;
+ }
+
+ @Nullable
+ String getAssumeRoleArn() {
+ return assumeRoleArn;
+ }
+
+ @Nullable
+ String getAssumeRoleExternalId() {
+ return assumeRoleExternalId;
+ }
+
+ @Nullable
+ String getAssumeRoleSessionName() {
+ return assumeRoleSessionName;
+ }
+
+ @Nullable
+ Integer getAssumeRoleSessionDurationSeconds() {
+ return assumeRoleSessionDurationSeconds;
+ }
+
+ @Nullable
+ String getCredentialsProvider() {
+ return credentialsProvider;
+ }
+
+ boolean hasAnyOverride() {
+ return region != null
+ || endpoint != null
+ || pathStyleAccess != null
+ || accessKey != null
+ || secretKey != null
+ || sseType != null
+ || sseKmsKeyId != null
+ || assumeRoleArn != null
+ || assumeRoleExternalId != null
+ || assumeRoleSessionName != null
+ || assumeRoleSessionDurationSeconds != null
+ || credentialsProvider != null;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ S3BucketConfig that = (S3BucketConfig) o;
+ return Objects.equals(bucketName, that.bucketName)
+ && Objects.equals(region, that.region)
+ && Objects.equals(endpoint, that.endpoint)
+ && Objects.equals(pathStyleAccess, that.pathStyleAccess)
+ && Objects.equals(accessKey, that.accessKey)
+ && Objects.equals(secretKey, that.secretKey)
+ && Objects.equals(sseType, that.sseType)
+ && Objects.equals(sseKmsKeyId, that.sseKmsKeyId)
+ && Objects.equals(assumeRoleArn, that.assumeRoleArn)
+ && Objects.equals(assumeRoleExternalId,
that.assumeRoleExternalId)
+ && Objects.equals(assumeRoleSessionName,
that.assumeRoleSessionName)
+ && Objects.equals(
+ assumeRoleSessionDurationSeconds,
that.assumeRoleSessionDurationSeconds)
+ && Objects.equals(credentialsProvider,
that.credentialsProvider);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ bucketName,
+ region,
+ endpoint,
+ pathStyleAccess,
+ accessKey,
+ secretKey,
+ sseType,
+ sseKmsKeyId,
+ assumeRoleArn,
+ assumeRoleExternalId,
+ assumeRoleSessionName,
+ assumeRoleSessionDurationSeconds,
+ credentialsProvider);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("S3BucketConfig{");
+ sb.append("bucket='").append(bucketName).append("'");
Review Comment:
Nit: we can call the parameter as is it named to have consistency
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystemFactory.java:
##########
@@ -356,8 +403,6 @@ public FileSystem create(URI fsUri) throws IOException {
boolean useAsyncOperations = config.get(USE_ASYNC_OPERATIONS);
- // Validate and clamp read buffer size to sensible range [64KB, 4MB]
- // We clip rather than throw to provide flexibility while preventing
extreme values
Review Comment:
Here too
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystemFactory.java:
##########
@@ -337,7 +385,6 @@ public FileSystem create(URI fsUri) throws IOException {
final long s3minPartSize = config.get(PART_UPLOAD_MIN_SIZE);
final int maxConcurrentUploads = config.get(MAX_CONCURRENT_UPLOADS);
- // Validate part size: S3 requires minimum 5MB and maximum 5GB per part
Review Comment:
Here too
##########
flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/S3BucketConfig.java:
##########
@@ -0,0 +1,328 @@
+/*
+ * 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.flink.fs.s3native;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.configuration.IllegalConfigurationException;
+
+import javax.annotation.Nullable;
+
+import java.util.Objects;
+
+/**
+ * Immutable, bucket-specific S3 configuration overrides.
+ *
+ * <p>Null values indicate inheritance from global configuration. Only
explicitly configured values
+ * are non-null. Configuration format: {@code
s3.bucket.<bucket-name>.<property>}
+ *
+ * <p>Validates that credentials (access-key/secret-key) are either both set
or both absent.
+ */
+@Internal
+final class S3BucketConfig {
+
+ private final String bucketName;
+ @Nullable private final String region;
+ @Nullable private final String endpoint;
+ @Nullable private final Boolean pathStyleAccess;
+ @Nullable private final String accessKey;
+ @Nullable private final String secretKey;
+ @Nullable private final String sseType;
+ @Nullable private final String sseKmsKeyId;
+ @Nullable private final String assumeRoleArn;
+ @Nullable private final String assumeRoleExternalId;
+ @Nullable private final String assumeRoleSessionName;
+ @Nullable private final Integer assumeRoleSessionDurationSeconds;
+ @Nullable private final String credentialsProvider;
+
+ private S3BucketConfig(Builder builder) {
+ this.bucketName = builder.bucketName;
+ this.region = builder.region;
+ this.endpoint = builder.endpoint;
+ this.pathStyleAccess = builder.pathStyleAccess;
+ this.accessKey = builder.accessKey;
+ this.secretKey = builder.secretKey;
+ this.sseType = builder.sseType;
+ this.sseKmsKeyId = builder.sseKmsKeyId;
+ this.assumeRoleArn = builder.assumeRoleArn;
+ this.assumeRoleExternalId = builder.assumeRoleExternalId;
+ this.assumeRoleSessionName = builder.assumeRoleSessionName;
+ this.assumeRoleSessionDurationSeconds =
builder.assumeRoleSessionDurationSeconds;
+ this.credentialsProvider = builder.credentialsProvider;
+ }
+
+ String getBucketName() {
+ return bucketName;
+ }
+
+ @Nullable
+ String getRegion() {
+ return region;
+ }
+
+ @Nullable
+ String getEndpoint() {
+ return endpoint;
+ }
+
+ @Nullable
+ Boolean getPathStyleAccess() {
+ return pathStyleAccess;
+ }
+
+ @Nullable
+ String getAccessKey() {
+ return accessKey;
+ }
+
+ @Nullable
+ String getSecretKey() {
+ return secretKey;
+ }
+
+ @Nullable
+ String getSseType() {
+ return sseType;
+ }
+
+ @Nullable
+ String getSseKmsKeyId() {
+ return sseKmsKeyId;
+ }
+
+ @Nullable
+ String getAssumeRoleArn() {
+ return assumeRoleArn;
+ }
+
+ @Nullable
+ String getAssumeRoleExternalId() {
+ return assumeRoleExternalId;
+ }
+
+ @Nullable
+ String getAssumeRoleSessionName() {
+ return assumeRoleSessionName;
+ }
+
+ @Nullable
+ Integer getAssumeRoleSessionDurationSeconds() {
+ return assumeRoleSessionDurationSeconds;
+ }
+
+ @Nullable
+ String getCredentialsProvider() {
+ return credentialsProvider;
+ }
+
+ boolean hasAnyOverride() {
+ return region != null
+ || endpoint != null
+ || pathStyleAccess != null
+ || accessKey != null
+ || secretKey != null
+ || sseType != null
+ || sseKmsKeyId != null
+ || assumeRoleArn != null
+ || assumeRoleExternalId != null
+ || assumeRoleSessionName != null
+ || assumeRoleSessionDurationSeconds != null
+ || credentialsProvider != null;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ S3BucketConfig that = (S3BucketConfig) o;
+ return Objects.equals(bucketName, that.bucketName)
+ && Objects.equals(region, that.region)
+ && Objects.equals(endpoint, that.endpoint)
+ && Objects.equals(pathStyleAccess, that.pathStyleAccess)
+ && Objects.equals(accessKey, that.accessKey)
+ && Objects.equals(secretKey, that.secretKey)
+ && Objects.equals(sseType, that.sseType)
+ && Objects.equals(sseKmsKeyId, that.sseKmsKeyId)
+ && Objects.equals(assumeRoleArn, that.assumeRoleArn)
+ && Objects.equals(assumeRoleExternalId,
that.assumeRoleExternalId)
+ && Objects.equals(assumeRoleSessionName,
that.assumeRoleSessionName)
+ && Objects.equals(
+ assumeRoleSessionDurationSeconds,
that.assumeRoleSessionDurationSeconds)
+ && Objects.equals(credentialsProvider,
that.credentialsProvider);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(
+ bucketName,
+ region,
+ endpoint,
+ pathStyleAccess,
+ accessKey,
+ secretKey,
+ sseType,
+ sseKmsKeyId,
+ assumeRoleArn,
+ assumeRoleExternalId,
+ assumeRoleSessionName,
+ assumeRoleSessionDurationSeconds,
+ credentialsProvider);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("S3BucketConfig{");
+ sb.append("bucket='").append(bucketName).append("'");
+ if (region != null) {
+ sb.append(", region='").append(region).append("'");
+ }
+ if (endpoint != null) {
+ sb.append(", endpoint='").append(endpoint).append("'");
+ }
+ if (pathStyleAccess != null) {
+ sb.append(", pathStyleAccess=").append(pathStyleAccess);
+ }
+ if (accessKey != null) {
+ sb.append(",
credentials=").append(GlobalConfiguration.HIDDEN_CONTENT);
+ }
+ if (sseType != null) {
+ sb.append(", sseType='").append(sseType).append("'");
+ }
+ if (assumeRoleArn != null) {
+ sb.append(", assumeRoleArn='").append(assumeRoleArn).append("'");
+ }
+ if (credentialsProvider != null) {
+ sb.append(",
credentialsProvider='").append(credentialsProvider).append("'");
+ }
+ sb.append('}');
+ return sb.toString();
+ }
+
+ static Builder builder(String bucketName) {
+ if (bucketName == null || bucketName.isEmpty()) {
Review Comment:
nullorwhitespace
--
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]