Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed from AWS basic authentication to DefaultAWSCredentialsProvide… #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ target
.classpath
.java-version
*.iml
.DS_Store
s3/.DS_Store
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitignore is smart enough to know that if you say you don't want .DS_Store, that you don't want it anywhere, so I don't think you need the last three lines here

s3/src/.DS_Store
s3/src/main/.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ public class AwsStorageConnectorCommonConfig {

public static final String AWS_REGION = "aws.region";

public static final String S3_KEY_PREFIX = "prefix";

public static final String AWS_SECRET_KEY = "aws.secretKey";

public static final String AWS_ACCESS_KEY_ID = "aws.accessKeyId";
public static final String S3_KEY_PREFIX = "prefix";

public static final String DEFAULT_AWS_REGION = Regions.DEFAULT_REGION.getName();

Expand All @@ -36,8 +32,6 @@ public static ConfigDef conf() {
configDef.define(BUCKET, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "Name of the S3 bucket")
.define(S3_KEY_PREFIX, ConfigDef.Type.STRING, "", new RegexStringValidator(Pattern.compile("^$|[-a-zA-Z0-9_./]+$"), "prefix can only contain alphanumerics, underscores(_), hyphens(-), periods(.) and slashes(/) only."),
ConfigDef.Importance.HIGH, "Path prefix for the objects written into S3")
.define(AWS_ACCESS_KEY_ID, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "AWS access key id")
.define(AWS_SECRET_KEY, ConfigDef.Type.PASSWORD, ConfigDef.Importance.HIGH, "AWS access secret key")
.define(AWS_REGION, ConfigDef.Type.STRING, DEFAULT_AWS_REGION, ConfigDef.Importance.MEDIUM, String.format("AWS client region, if not set will use %s", DEFAULT_AWS_REGION));
return configDef;
}
Expand Down Expand Up @@ -69,12 +63,12 @@ public static void verifyS3CredentialsAndBucketInfo(final Map<String, String> se
s3Client.shutdown();
} catch (AmazonS3Exception e) {
switch (e.getErrorCode()) {
case "InvalidAccessKeyId":
addErrorMessageToConfigObject(configObject, AWS_ACCESS_KEY_ID, "The defined aws.accessKeyId is invalid");
break;
case "SignatureDoesNotMatch":
addErrorMessageToConfigObject(configObject, AWS_SECRET_KEY, "The defined aws.secretKey is invalid");
break;
case "InvalidAccessKeyId":
addErrorMessageToConfigObject(configObject, "", "The AWS AccessKeyId is invalid");
break;
case "SignatureDoesNotMatch":
addErrorMessageToConfigObject(configObject, "", "The AWS SecretKey is invalid");
break;
case "InvalidBucketName":
addErrorMessageToConfigObject(configObject, BUCKET, "The defined bucket name is invalid");
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.instaclustr.kafka.connect.s3;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
Expand All @@ -27,12 +28,10 @@ public TransferManagerProvider(final Map<String, String> config) {
}

public static AmazonS3ClientBuilder getS3ClientBuilderWithRegionAndCredentials(final Map<String, String> config) {
String accessKey = getFromConfigOrEnvironment(config, AwsStorageConnectorCommonConfig.AWS_ACCESS_KEY_ID);
String secret = getFromConfigOrEnvironment(config, AwsStorageConnectorCommonConfig.AWS_SECRET_KEY);
String region = getFromConfigOrEnvironment(config, AwsStorageConnectorCommonConfig.AWS_REGION);

AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secret)));
.withCredentials(new DefaultAWSCredentialsProviderChain());

if (region == null) {
region = AwsStorageConnectorCommonConfig.DEFAULT_AWS_REGION;
Expand Down