Removing internal references

This commit is contained in:
Meher Mankikar 2023-06-09 13:57:10 -07:00
parent f7d286ac2e
commit d191401c18
2 changed files with 3 additions and 136 deletions

View file

@ -26,7 +26,6 @@ import software.amazon.kinesis.common.ConfigsBuilder;
import software.amazon.kinesis.common.InitialPositionInStream;
import software.amazon.kinesis.processor.ShardRecordProcessorFactory;
import software.amazon.kinesis.retrieval.RetrievalConfig;
import software.amazon.kinesis.utils.OdinCredentialsHelper;
import java.io.IOException;
import java.net.Inet4Address;
@ -67,18 +66,6 @@ public interface KCLAppConfig {
// "default" profile, should match with profiles listed in "cat ~/.aws/config"
String getProfile();
default String odinMaterialName() {
return null;
}
default AWSCredentialsProvider getSyncAwsCredentials() throws IOException {
return OdinCredentialsHelper.getSyncAwsCredentialsFromMaterialSet( odinMaterialName() );
}
default AwsCredentialsProvider getAsyncAwsCredentials() throws IOException {
return OdinCredentialsHelper.getAsyncAwsCredentialsFromMaterialSet( odinMaterialName() );
}
// '-1' means round robin across 0, 5_000, 15_000, 30_000 milliseconds delay.
// The delay period is picked according to current time, so expected to be unpredictable across different KCL runs.
// '0' means PassThroughRecordProcessor
@ -136,9 +123,7 @@ public interface KCLAppConfig {
kinesisAsyncClientBuilder.httpClient( sdkAsyncHttpClient );
if ( getAsyncAwsCredentials() != null ) {
kinesisAsyncClientBuilder.credentialsProvider( getAsyncAwsCredentials() );
} else if ( getProfile() != null ) {
if ( getProfile() != null ) {
kinesisAsyncClientBuilder.credentialsProvider( ProfileCredentialsProvider.builder().profileName( getProfile() ).build() );
} else {
kinesisAsyncClientBuilder.credentialsProvider( DefaultCredentialsProvider.create() );
@ -150,9 +135,7 @@ public interface KCLAppConfig {
default DynamoDbAsyncClient buildAsyncDynamoDbClient() throws IOException {
final DynamoDbAsyncClientBuilder builder = DynamoDbAsyncClient.builder().region( getRegion() );
if ( getAsyncAwsCredentials() != null ) {
builder.credentialsProvider( getAsyncAwsCredentials() );
} else if ( getProfile() != null ) {
if ( getProfile() != null ) {
builder.credentialsProvider( ProfileCredentialsProvider.builder().profileName( getProfile() ).build() );
} else {
builder.credentialsProvider( DefaultCredentialsProvider.create() );
@ -164,9 +147,7 @@ public interface KCLAppConfig {
default CloudWatchAsyncClient buildAsyncCloudWatchClient() throws IOException {
final CloudWatchAsyncClientBuilder builder = CloudWatchAsyncClient.builder().region( getRegion() );
if ( getAsyncAwsCredentials() != null ) {
builder.credentialsProvider( getAsyncAwsCredentials() );
} else if ( getProfile() != null ) {
if ( getProfile() != null ) {
builder.credentialsProvider( ProfileCredentialsProvider.builder().profileName( getProfile() ).build() );
} else {
builder.credentialsProvider( DefaultCredentialsProvider.create() );

View file

@ -1,114 +0,0 @@
package software.amazon.kinesis.utils;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.google.common.io.CharStreams;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
/**
* Helper class to hold odin credentials because odin is not available externally and this package doesn't use brazil.
*/
@Slf4j
public class OdinCredentialsHelper {
private final static String PRINCIPAL = "Principal";
private final static String CREDENTIAL = "Credential";
private final static String ODIN_COMMAND = "/apollo/env/envImprovement/bin/odin-get -t";
private static String getMaterial(String materialName, String materialType) throws IOException {
final InputStream inputStream = Runtime.getRuntime().exec(String.format("%s %s %s", ODIN_COMMAND, materialType, materialName)).getInputStream();
return CharStreams.toString(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).trim();
}
private static String getPrincipal(String materialName) throws IOException {
return getMaterial(materialName, PRINCIPAL);
}
private static String getCredential(String materialName) throws IOException {
return getMaterial(materialName, CREDENTIAL);
}
/**
* Helper method to pull credentials from odin for testing for AWS SDK sync clients (1.x).
*
* @param materialName name of the material set to fetch.
* @return access/secret key pair from Odin if specified for testing.
* @throws IOException
*/
public static AWSCredentialsProvider getSyncAwsCredentialsFromMaterialSet(String materialName) throws IOException {
if (materialName == null) {
log.debug("No material name found.");
return null;
}
log.debug("Fetching credentials for material - {}.", materialName);
final String principal = getPrincipal(materialName);
final String credential = getCredential(materialName);
final AWSCredentialsProvider awsCredentialsProvider = new AWSCredentialsProvider() {
@Override
public AWSCredentials getCredentials() {
return new AWSCredentials() {
@Override
public String getAWSAccessKeyId() {
return principal;
}
@Override
public String getAWSSecretKey() {
return credential;
}
};
}
@Override
public void refresh() {
}
};
log.debug("Successfully retrieved credentials from odin. Access key - {}.", principal);
return awsCredentialsProvider;
}
/**
* Helper method to pull credentials from odin for testing for AWS SDK async clients (2.x).
*
* @param materialName name of the material set to fetch.
* @return access/secret key pair from Odin if specified for testing.
* @throws IOException
*/
public static AwsCredentialsProvider getAsyncAwsCredentialsFromMaterialSet(String materialName) throws IOException {
if (materialName == null) {
log.debug("No material name found.");
return null;
}
log.debug("Fetching credentials for material - {}.", materialName);
final String principal = getPrincipal(materialName);
final String credential = getCredential(materialName);
final AwsCredentialsProvider awsCredentialsProvider = () -> new AwsCredentials() {
@Override
public String accessKeyId() {
return principal;
}
@Override
public String secretAccessKey() {
return credential;
}
};
log.debug("Successfully retrieved credentials from odin. Access key - {}.", principal);
return awsCredentialsProvider;
}
}