Add testing for property key parsing. Update documentation for providers.
This commit is contained in:
parent
95253af6f2
commit
0d890a24d8
4 changed files with 42 additions and 4 deletions
|
|
@ -17,7 +17,6 @@ package software.amazon.kinesis.multilang.config;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -63,7 +62,7 @@ public class KinesisClientLibConfigurator {
|
|||
properties.entrySet().forEach(e -> {
|
||||
try {
|
||||
log.info("Processing (key={}, value={})", e.getKey(), e.getValue());
|
||||
utilsBean.setProperty(configuration, processKey(e), e.getValue());
|
||||
utilsBean.setProperty(configuration, processKey((String) e.getKey()), e.getValue());
|
||||
} catch (IllegalAccessException | InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
|
@ -112,8 +111,13 @@ public class KinesisClientLibConfigurator {
|
|||
return getConfiguration(properties);
|
||||
}
|
||||
|
||||
private String processKey(Map.Entry<Object, Object> e) {
|
||||
String key = (String) e.getKey();
|
||||
/**
|
||||
* Processes a configuration key to normalize AWS credentials provider naming. Necessary to conform to
|
||||
* autogenerated setters.
|
||||
* @param key the config param key
|
||||
* @return case-configured param key name
|
||||
*/
|
||||
String processKey(String key) {
|
||||
if (key.toLowerCase().startsWith("awscredentialsprovider")) {
|
||||
key = key.replaceAll("(?i)awscredentialsprovider", "awsCredentialsProvider");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -456,6 +456,34 @@ public class KinesisClientLibConfiguratorTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKeyWithExpectedCasing() {
|
||||
String key = "AwsCredentialsProvider";
|
||||
String result = configurator.processKey(key);
|
||||
assertEquals("awsCredentialsProvider", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKeyWithOldCasing() {
|
||||
String key = "AWSCredentialsProvider";
|
||||
String result = configurator.processKey(key);
|
||||
assertEquals("awsCredentialsProvider", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKeyWithMixedCasing() {
|
||||
String key = "AwScReDeNtIaLsPrOvIdEr";
|
||||
String result = configurator.processKey(key);
|
||||
assertEquals("awsCredentialsProvider", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessKeyWithSuffix() {
|
||||
String key = "awscredentialsproviderDynamoDB";
|
||||
String result = configurator.processKey(key);
|
||||
assertEquals("awsCredentialsProviderDynamoDB", result);
|
||||
}
|
||||
|
||||
// TODO: fix this test
|
||||
@Test
|
||||
public void testWithDifferentAwsCredentialsForDynamoDBAndCloudWatch() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ streamName = kclpysample
|
|||
applicationName = MultiLangTest
|
||||
|
||||
# Users can change the credentials provider the KCL will use to retrieve credentials.
|
||||
# Expected key name (case-sensitive):
|
||||
# AwsCredentialsProvider / AwsCredentialsProviderDynamoDB / AwsCredentialsProviderCloudWatch
|
||||
# The DefaultCredentialsProvider checks several other providers, which is
|
||||
# described here:
|
||||
# https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ AwsCredentialsProvider = StsAssumeRoleCredentialsProvider|<arn>|<sessionName>
|
|||
```
|
||||
This basic configuration creates an [StsAssumeRoleCredentialsProvider][sts-assume-provider] with an ARN and session name.
|
||||
|
||||
The providers generated by this config property will be [AWS SDK v2 AwsCredentialsProviders][aws-credentials-provider].
|
||||
These differ from the SDK v1 AWSCredentialsProviders in a number of ways. See [Credentials Provider Changes][credentials-provider-changes].
|
||||
|
||||
While functional, this configuration is limited.
|
||||
For example, this configuration cannot set a regional endpoint (e.g., VPC use case).
|
||||
|
||||
|
|
@ -84,3 +87,4 @@ AwsCredentialsProvider = KclStsAssumeRoleCredentialsProvider|<arn>|<sessionName>
|
|||
[sts-assume-provider]: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/sts/auth/StsAssumeRoleCredentialsProvider.html
|
||||
[profile-credentials-provider-create]: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.html#create(java.lang.String)
|
||||
[default-credentials-provider]: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html
|
||||
[credentials-provider-changes]: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/migration-client-credentials.html
|
||||
|
|
|
|||
Loading…
Reference in a new issue