Izeren commented on code in PR #27187: URL: https://github.com/apache/flink/pull/27187#discussion_r2764610166
########## flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/token/NativeS3DelegationTokenProvider.java: ########## @@ -0,0 +1,117 @@ +/* + * 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.token; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.GlobalConfiguration; +import org.apache.flink.core.security.token.DelegationTokenProvider; +import org.apache.flink.util.InstantiationUtil; +import org.apache.flink.util.StringUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.sts.StsClient; +import software.amazon.awssdk.services.sts.model.Credentials; +import software.amazon.awssdk.services.sts.model.GetSessionTokenRequest; +import software.amazon.awssdk.services.sts.model.GetSessionTokenResponse; + +import java.util.Optional; + +@Internal +public class NativeS3DelegationTokenProvider implements DelegationTokenProvider { + + private static final Logger LOG = + LoggerFactory.getLogger(NativeS3DelegationTokenProvider.class); + + private String region; + private String accessKey; + private String secretKey; + + /** + * Using unique service name. Avoids conflict with s3-fs-hadoop plugin. Both plugins can coexist + * with different service names + * + * @return ServiceName + */ + @Override + public String serviceName() { + return "s3-native"; + } + + @Override + public void init(Configuration configuration) { + String configPrefix = String.format("%s.%s", CONFIG_PREFIX, serviceName()); + + region = configuration.getString(configPrefix + ".region", null); + if (!StringUtils.isNullOrWhitespaceOnly(region)) { Review Comment: They are more complicated than that, there are different partitions (like `aws-cn`, `aws-us-gov`) + there are some special regions. I would probably keep it very generic (like alphanumeric + `-`) to prevent some bad values, but not validating the region regexp -- 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]
