-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…al-provider support custom AWS credential provider
- Loading branch information
Showing
9 changed files
with
257 additions
and
23 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
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
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
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
16 changes: 16 additions & 0 deletions
16
src/test/java/software/amazon/event/kafkaconnector/AwsCredentialProviderImpl.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,16 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package software.amazon.event.kafkaconnector; | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
|
||
public class AwsCredentialProviderImpl implements AwsCredentialsProvider { | ||
|
||
@Override | ||
public AwsCredentials resolveCredentials() { | ||
return null; | ||
} | ||
} |
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
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
67 changes: 67 additions & 0 deletions
67
.../software/amazon/event/kafkaconnector/auth/EventBridgeCredentialsProviderFactoryTest.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,67 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package software.amazon.event.kafkaconnector.auth; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider; | ||
import software.amazon.event.kafkaconnector.AwsCredentialProviderImpl; | ||
import software.amazon.event.kafkaconnector.EventBridgeSinkConfig; | ||
|
||
public class EventBridgeCredentialsProviderFactoryTest { | ||
|
||
private static final Map<String, String> commonProps = | ||
Map.of( | ||
"aws.eventbridge.connector.id", "testConnectorId", | ||
"aws.eventbridge.region", "us-east-1", | ||
"aws.eventbridge.eventbus.arn", "arn:aws:events:us-east-1:000000000000:event-bus/e2e"); | ||
|
||
@Test | ||
public void shouldUseDefaultAwsCredentialsProvider() { | ||
|
||
var provider = | ||
EventBridgeAwsCredentialsProviderFactory.getAwsCredentialsProvider( | ||
new EventBridgeSinkConfig(commonProps)); | ||
|
||
assertThat(provider).isInstanceOf(AwsCredentialsProvider.class); | ||
assertThat(provider).isExactlyInstanceOf(DefaultCredentialsProvider.class); | ||
} | ||
|
||
@Test | ||
public void shouldUseStsAssumeRoleCredentialsProviderIfArnIsPresent() { | ||
|
||
var props = new HashMap<>(commonProps); | ||
props.put( | ||
"aws.eventbridge.iam.role.arn", | ||
"arn:aws:iam::123456789012:oidc-provider/server.example.org"); | ||
var provider = | ||
EventBridgeAwsCredentialsProviderFactory.getAwsCredentialsProvider( | ||
new EventBridgeSinkConfig(props)); | ||
|
||
assertThat(provider).isInstanceOf(AwsCredentialsProvider.class); | ||
assertThat(provider).isExactlyInstanceOf(StsAssumeRoleCredentialsProvider.class); | ||
} | ||
|
||
@Test | ||
public void shouldUseAwsCredentialsProviderByProvidedClass() { | ||
|
||
var props = new HashMap<>(commonProps); | ||
props.put( | ||
"aws.eventbridge.auth.credentials_provider.class", | ||
AwsCredentialProviderImpl.class.getCanonicalName()); | ||
|
||
var provider = | ||
EventBridgeAwsCredentialsProviderFactory.getAwsCredentialsProvider( | ||
new EventBridgeSinkConfig(props)); | ||
|
||
assertThat(provider).isInstanceOf(AwsCredentialsProvider.class); | ||
assertThat(provider).isExactlyInstanceOf(AwsCredentialProviderImpl.class); | ||
} | ||
} |