dannycranmer commented on a change in pull request #18553: URL: https://github.com/apache/flink/pull/18553#discussion_r812689269
########## File path: flink-connectors/flink-connector-aws-base/src/main/java/org/apache/flink/connector/aws/util/AWSCredentialRetryableExceptionClassifiers.java ########## @@ -0,0 +1,47 @@ +/* + * 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.connector.aws.util; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.connector.base.sink.util.RetryableExceptionClassifier; + +import software.amazon.awssdk.core.exception.SdkClientException; +import software.amazon.awssdk.services.sts.model.StsException; + +/** Class containing set of {@link RetryableExceptionClassifier} for AWS credenetial failures. */ +@Internal +public class AWSCredentialRetryableExceptionClassifiers { + public static RetryableExceptionClassifier getInvalidCredentialsExceptionClassifier() { + return RetryableExceptionClassifier.withRootCauseOfType( + StsException.class, + err -> + new AWSAuthenticationException( + "Encountered non-recoverable exception relating to the provided credentials.", + err)); + } + + public static RetryableExceptionClassifier getSdkClientMisconfiguredExceptionClassifier() { + return RetryableExceptionClassifier.withRootCauseOfType( + SdkClientException.class, + err -> + new AWSAuthenticationException( + "Encountered non-recoverable exception relating to mis-configured client", + err)); + } +} Review comment: It seems wrong to bucket all `SdkClientException` as `AWSAuthenticationException`. Why not just bubble the RC up here? I would rather not introduce incorrect exception wrappers ########## File path: flink-connectors/flink-connector-aws-base/src/main/java/org/apache/flink/connector/aws/util/AWSAuthenticationException.java ########## @@ -0,0 +1,36 @@ +/* + * 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.connector.aws.util; + +import org.apache.flink.annotation.Internal; + +/** + * A {@link IllegalStateException} wrapper indicating the exception was thrown from AWS credentials. + */ +@Internal +public class AWSAuthenticationException extends IllegalStateException { Review comment: I do not think `IllegalStateException` semantically fits here: > Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation. https://docs.oracle.com/javase/7/docs/api/java/lang/IllegalStateException.html We are throwing this when bad creds are provided right? So a better fit might be `IllegalArgumentException`? In any case, the purpose of this class is not really clear. If we are just wrapping any and all exceptions that arise from authentication then we should extend `RuntimeException` ########## File path: flink-connectors/flink-connector-aws-base/src/main/java/org/apache/flink/connector/aws/util/AWSAuthenticationException.java ########## @@ -0,0 +1,36 @@ +/* + * 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.connector.aws.util; + +import org.apache.flink.annotation.Internal; + +/** + * A {@link IllegalStateException} wrapper indicating the exception was thrown from AWS credentials. Review comment: This comment does not make sense "thrown from AWS credentials" ########## File path: flink-connectors/flink-connector-aws-base/src/main/java/org/apache/flink/connector/aws/util/AWSGeneralUtil.java ########## @@ -374,4 +371,34 @@ public static void closeResources(SdkAutoCloseable... resources) { throw exception; } } + + public static void validateAwsCredentials(Properties config) { + try { + validateAwsConfiguration(config); + getCredentialsProvider(config).resolveCredentials(); + } catch (IllegalStateException | IllegalArgumentException | SdkClientException e) { + throw new AWSAuthenticationException( + String.format( + "Failed to create client using %s provider", + getCredentialProviderType( + config, AWSConfigConstants.AWS_CREDENTIALS_PROVIDER)), + e); + } + } Review comment: Again, how about if there are other issues thrown here that are not related to authentication? `SdkClientException` >Direct Known Subclasses: AbortedException, ApiCallAttemptTimeoutException, ApiCallTimeoutException, Crc32MismatchException, EndpointDiscoveryFailedException, ExpiredTokenException, NonRetryableException, RetryableException, SdkJsonGenerator.JsonGenerationException Consider letting these bubble up, or wrapping more specific exceptions ########## File path: flink-connectors/flink-connector-aws-base/src/main/java/org/apache/flink/connector/aws/util/AWSGeneralUtil.java ########## @@ -374,4 +371,34 @@ public static void closeResources(SdkAutoCloseable... resources) { throw exception; } } + + public static void validateAwsCredentials(Properties config) { + try { + validateAwsConfiguration(config); + getCredentialsProvider(config).resolveCredentials(); + } catch (IllegalStateException | IllegalArgumentException | SdkClientException e) { + throw new AWSAuthenticationException( + String.format( + "Failed to create client using %s provider", + getCredentialProviderType( + config, AWSConfigConstants.AWS_CREDENTIALS_PROVIDER)), + e); + } + } + + private static void validateCredentialProvider(Properties config) { + // value specified for AWSConfigConstants.AWS_CREDENTIALS_PROVIDER needs to be + // recognizable + try { + getCredentialsProvider(config); + } catch (IllegalArgumentException e) { + StringBuilder sb = new StringBuilder(); + for (CredentialProvider type : CredentialProvider.values()) { + sb.append(type.toString()).append(", "); + } + throw new IllegalArgumentException( + "Invalid AWS Credential Provider Type set in config. Valid values are: " + + sb.toString()); + } + } Review comment: There are no unit tests in this module for the changes in this PR ########## File path: flink-connectors/flink-connector-aws-base/src/main/java/org/apache/flink/connector/aws/util/AWSCredentialRetryableExceptionClassifiers.java ########## @@ -0,0 +1,47 @@ +/* + * 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.connector.aws.util; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.connector.base.sink.util.RetryableExceptionClassifier; + +import software.amazon.awssdk.core.exception.SdkClientException; +import software.amazon.awssdk.services.sts.model.StsException; + +/** Class containing set of {@link RetryableExceptionClassifier} for AWS credenetial failures. */ +@Internal +public class AWSCredentialRetryableExceptionClassifiers { + public static RetryableExceptionClassifier getInvalidCredentialsExceptionClassifier() { + return RetryableExceptionClassifier.withRootCauseOfType( + StsException.class, + err -> + new AWSAuthenticationException( + "Encountered non-recoverable exception relating to the provided credentials.", + err)); + } + + public static RetryableExceptionClassifier getSdkClientMisconfiguredExceptionClassifier() { Review comment: Why does a misconfigured SDK client result in `AWSAuthenticationException` ? -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org