-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Motivation The goal is to allow consuming dynamodb streams directly into pulsar ### Modifications I created a new source for dynamo, which shares less code than ideal with the kinesis source, since the dynamodb kinesis client adapter supports KCL v1.x only, while, the kinesis source is using KCL v2.x. I also abstracted the aws credential management pieces into their own package. ### Verifying this change Create a dynamodb table with streams enabled. Configure this connector with the stream ARN and appropriate credentials. Create/update an entry in the table and ensure it is written to pulsar by the connector.
- Loading branch information
Showing
23 changed files
with
1,211 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.pulsar</groupId> | ||
<artifactId>pulsar-io</artifactId> | ||
<version>2.6.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pulsar-io-aws</artifactId> | ||
<name>Pulsar IO :: IO AWS</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.pulsar</groupId> | ||
<artifactId>pulsar-io-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
</dependency> | ||
|
||
<!-- aws dependencies --> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-sts</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>sts</artifactId> | ||
<version>2.10.56</version> | ||
</dependency> | ||
<!-- /aws dependencies --> | ||
|
||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
pulsar-io/aws/src/main/java/org/apache/pulsar/io/aws/AwsCredentialProviderPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* 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.pulsar.io.aws; | ||
|
||
import java.io.Closeable; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.amazonaws.auth.AWSSessionCredentials; | ||
import com.amazonaws.auth.BasicSessionCredentials; | ||
|
||
/** | ||
* Kinesis source/sink calls credential-provider while refreshing aws accessKey and secreKey. So, implementation | ||
* AwsCredentialProviderPlugin needs to makes sure to return non-expired keys when it requires. | ||
* | ||
*/ | ||
public interface AwsCredentialProviderPlugin extends Closeable { | ||
|
||
/** | ||
* accepts aws-account related param and initialize credential provider. | ||
* | ||
* @param param | ||
*/ | ||
void init(String param); | ||
|
||
/** | ||
* Returned {@link AWSCredentialsProvider} can give {@link AWSCredentials} in case credential belongs to IAM user or | ||
* it can return {@link BasicSessionCredentials} if user wants to generate temporary credential for a given IAM | ||
* role. | ||
* | ||
* @return | ||
*/ | ||
AWSCredentialsProvider getCredentialProvider(); | ||
|
||
/** | ||
* Returns a V2 credential provider for use with the v2 SDK. | ||
* | ||
* Defaults to an implementation that pulls credentials from a v1 provider | ||
*/ | ||
default software.amazon.awssdk.auth.credentials.AwsCredentialsProvider getV2CredentialsProvider() { | ||
// make a small wrapper to forward requests to v1, this allows | ||
// for this interface to not "break" for implementers | ||
AWSCredentialsProvider v1Provider = getCredentialProvider(); | ||
return () -> { | ||
AWSCredentials creds = v1Provider.getCredentials(); | ||
if (creds instanceof AWSSessionCredentials) { | ||
return software.amazon.awssdk.auth.credentials.AwsSessionCredentials.create( | ||
creds.getAWSAccessKeyId(), | ||
creds.getAWSSecretKey(), | ||
((AWSSessionCredentials) creds).getSessionToken()); | ||
} else { | ||
return software.amazon.awssdk.auth.credentials.AwsBasicCredentials.create( | ||
creds.getAWSAccessKeyId(), | ||
creds.getAWSSecretKey()); | ||
} | ||
}; | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
pulsar-io/aws/src/main/java/org/apache/pulsar/io/aws/AwsDefaultProviderChainPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.pulsar.io.aws; | ||
|
||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
|
||
import java.io.IOException; | ||
|
||
public class AwsDefaultProviderChainPlugin implements AwsCredentialProviderPlugin { | ||
@Override | ||
public void init(String param) { | ||
|
||
} | ||
|
||
@Override | ||
public AWSCredentialsProvider getCredentialProvider() { | ||
return new DefaultAWSCredentialsProviderChain(); | ||
} | ||
|
||
@Override | ||
public software.amazon.awssdk.auth.credentials.AwsCredentialsProvider getV2CredentialsProvider() { | ||
return DefaultCredentialsProvider.create(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
pulsar-io/aws/src/main/java/org/apache/pulsar/io/aws/STSAssumeRoleProviderPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* 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.pulsar.io.aws; | ||
|
||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; | ||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
import software.amazon.awssdk.services.sts.StsClient; | ||
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class STSAssumeRoleProviderPlugin implements AwsCredentialProviderPlugin { | ||
public static final String ASSUME_ROLE_ARN = "roleArn"; | ||
public static final String ASSUME_ROLE_SESSION_NAME = "roleSessionName"; | ||
|
||
private String roleArn; | ||
private String roleSessionName; | ||
|
||
@Override | ||
public void init(String param) { | ||
Map<String, String> credentialMap = new Gson().fromJson(param, | ||
new TypeToken<Map<String, String>>() { | ||
}.getType()); | ||
|
||
roleArn = credentialMap.get(ASSUME_ROLE_ARN); | ||
roleSessionName = credentialMap.get(ASSUME_ROLE_SESSION_NAME); | ||
} | ||
|
||
@Override | ||
public AWSCredentialsProvider getCredentialProvider() { | ||
return new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName).build(); | ||
} | ||
|
||
@Override | ||
public software.amazon.awssdk.auth.credentials.AwsCredentialsProvider getV2CredentialsProvider() { | ||
StsClient client = StsClient.create(); | ||
return StsAssumeRoleCredentialsProvider.builder().stsClient(client).refreshRequest((req) -> { | ||
req.roleArn(roleArn).roleSessionName(roleSessionName).build(); | ||
}).build(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
} | ||
} |
Oops, something went wrong.