|
23 | 23 | import org.apache.kafka.common.config.AbstractConfig; |
24 | 24 | import org.apache.kafka.common.config.ConfigDef; |
25 | 25 | import org.apache.kafka.common.config.ConfigException; |
| 26 | +import org.apache.kafka.common.utils.Utils; |
26 | 27 |
|
27 | 28 | import io.aiven.kafka.connect.common.config.ConfigFragment; |
28 | 29 | import io.aiven.kafka.connect.common.config.validators.FileCompressionTypeValidator; |
|
43 | 44 | import org.slf4j.LoggerFactory; |
44 | 45 | import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
45 | 46 | import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; |
| 47 | +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; |
46 | 48 |
|
47 | 49 | /** |
48 | 50 | * The configuration fragment that defines the S3 specific characteristics. |
@@ -94,6 +96,12 @@ public final class S3ConfigFragment extends ConfigFragment { |
94 | 96 | public static final String AWS_ACCESS_KEY_ID_CONFIG = "aws.access.key.id"; |
95 | 97 | public static final String AWS_SECRET_ACCESS_KEY_CONFIG = "aws.secret.access.key"; |
96 | 98 | public static final String AWS_CREDENTIALS_PROVIDER_CONFIG = "aws.credentials.provider"; |
| 99 | + /** |
| 100 | + * not used in codebase |
| 101 | + * |
| 102 | + * @deprecated to be removed |
| 103 | + */ |
| 104 | + @Deprecated |
97 | 105 | public static final String AWS_CREDENTIAL_PROVIDER_DEFAULT = "com.amazonaws.auth.DefaultAWSCredentialsProviderChain"; |
98 | 106 | public static final String AWS_S3_BUCKET_NAME_CONFIG = "aws.s3.bucket.name"; |
99 | 107 | public static final String AWS_S3_SSE_ALGORITHM_CONFIG = "aws.s3.sse.algorithm"; |
@@ -189,13 +197,10 @@ static void addAwsConfigGroup(final ConfigDef configDef) { |
189 | 197 | ConfigDef.Importance.MEDIUM, "AWS Secret Access Key", GROUP_AWS, awsGroupCounter++, |
190 | 198 | ConfigDef.Width.NONE, AWS_SECRET_ACCESS_KEY_CONFIG); |
191 | 199 |
|
192 | | - configDef.define(AWS_CREDENTIALS_PROVIDER_CONFIG, ConfigDef.Type.CLASS, AWS_CREDENTIAL_PROVIDER_DEFAULT, |
193 | | - ConfigDef.Importance.MEDIUM, |
194 | | - "When you initialize a new " + "service client without supplying any arguments, " |
195 | | - + "the AWS SDK for Java attempts to find temporary " |
196 | | - + "credentials by using the default credential " + "provider chain implemented by the " |
197 | | - + "DefaultAWSCredentialsProviderChain class.", |
198 | | - |
| 200 | + configDef.define(AWS_CREDENTIALS_PROVIDER_CONFIG, ConfigDef.Type.CLASS, null, ConfigDef.Importance.MEDIUM, |
| 201 | + "When you initialize a new service client without supplying any arguments " |
| 202 | + + "the AWS SDK for Java attempts to find temporary credentials by using the default credential " |
| 203 | + + "provider chain.", |
199 | 204 | GROUP_AWS, awsGroupCounter++, ConfigDef.Width.NONE, AWS_CREDENTIALS_PROVIDER_CONFIG); |
200 | 205 |
|
201 | 206 | configDef.define(AWS_S3_BUCKET_NAME_CONFIG, ConfigDef.Type.STRING, null, new BucketNameValidator(), |
@@ -355,7 +360,7 @@ public void validateCredentials() { |
355 | 360 | final AwsBasicCredentials awsCredentialsV2 = getAwsCredentialsV2(); |
356 | 361 | if (awsCredentials == null && awsCredentialsV2 == null) { |
357 | 362 | LOGGER.info( |
358 | | - "Connector use {} as credential Provider, " |
| 363 | + "Connector uses {} as credential Provider, " |
359 | 364 | + "when configuration for {{}, {}} OR {{}, {}} are absent", |
360 | 365 | AWS_CREDENTIALS_PROVIDER_CONFIG, AWS_ACCESS_KEY_ID_CONFIG, AWS_SECRET_ACCESS_KEY_CONFIG, |
361 | 366 | AWS_STS_ROLE_ARN, AWS_STS_ROLE_SESSION_NAME); |
@@ -541,12 +546,26 @@ public int getS3RetryBackoffMaxRetries() { |
541 | 546 | return cfg.getInt(AWS_S3_RETRY_BACKOFF_MAX_RETRIES_CONFIG); |
542 | 547 | } |
543 | 548 |
|
| 549 | + /** |
| 550 | + * @return a V1 credentials provider |
| 551 | + * @deprecated use {@link #getAwsCredentialsV2()} |
| 552 | + */ |
| 553 | + @Deprecated |
544 | 554 | public AWSCredentialsProvider getCustomCredentialsProvider() { |
545 | | - return cfg.getConfiguredInstance(AWS_CREDENTIALS_PROVIDER_CONFIG, AWSCredentialsProvider.class); |
| 555 | + final AWSCredentialsProvider result = cfg.getConfiguredInstance(AWS_CREDENTIALS_PROVIDER_CONFIG, |
| 556 | + AWSCredentialsProvider.class); |
| 557 | + return result != null ? result : Utils.newInstance(com.amazonaws.auth.DefaultAWSCredentialsProviderChain.class); |
546 | 558 | } |
547 | 559 |
|
| 560 | + /** |
| 561 | + * Gets the Aws Credentials provider. |
| 562 | + * |
| 563 | + * @return the Aws Credentials provider. |
| 564 | + */ |
548 | 565 | public AwsCredentialsProvider getCustomCredentialsProviderV2() { |
549 | | - return cfg.getConfiguredInstance(AWS_CREDENTIALS_PROVIDER_CONFIG, AwsCredentialsProvider.class); |
| 566 | + final AwsCredentialsProvider result = cfg.getConfiguredInstance(AWS_CREDENTIALS_PROVIDER_CONFIG, |
| 567 | + AwsCredentialsProvider.class); |
| 568 | + return result != null ? result : DefaultCredentialsProvider.builder().build(); |
550 | 569 | } |
551 | 570 |
|
552 | 571 | public int getFetchPageSize() { |
|
0 commit comments