Skip to content

Commit

Permalink
remaining changes missed with initial passes
Browse files Browse the repository at this point in the history
  • Loading branch information
aimethed committed May 24, 2024
1 parent cd75a48 commit fb591ee
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import com.amazonaws.services.s3.model.PutObjectResult;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.google.common.io.ByteStreams;
import org.junit.After;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.amazonaws.services.s3.model.PutObjectResult;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteStreams;
import org.apache.arrow.vector.types.Types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.amazonaws.athena.connector.lambda.security.LocalKeyFactory;
import com.amazonaws.services.athena.AmazonAthena;
import com.amazonaws.services.glue.AWSGlue;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.google.common.collect.ImmutableList;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoClient;
Expand Down
11 changes: 5 additions & 6 deletions athena-federation-integ-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
<version>${aws-sdk-v2.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
Expand All @@ -154,12 +159,6 @@
<artifactId>aws-java-sdk-cloudformation</artifactId>
<version>${aws-sdk.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-secretsmanager -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>${aws-sdk.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awscdk/core -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import com.amazonaws.athena.connector.integ.data.SecretsManagerCredentials;
import com.amazonaws.athena.connector.integ.data.TestConfig;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -55,23 +54,21 @@ public static Optional<SecretsManagerCredentials> getCredentials(TestConfig test

if (secretsManagerSecret.isPresent()) {
String secret = secretsManagerSecret.get();
AWSSecretsManager secretsManager = AWSSecretsManagerClientBuilder.defaultClient();
SecretsManagerClient secretsManager = SecretsManagerClient.create();
try {
GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest()
.withSecretId(secret));
GetSecretValueResponse secretValueResult = secretsManager.getSecretValue(GetSecretValueRequest.builder()
.secretId(secret)
.build());
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> credentials = objectMapper.readValue(secretValueResult.getSecretString(),
Map<String, String> credentials = objectMapper.readValue(secretValueResult.secretString(),
HashMap.class);
return Optional.of(new SecretsManagerCredentials(secret, credentials.get("username"),
credentials.get("password"), secretValueResult.getARN()));
credentials.get("password"), secretValueResult.arn()));
}
catch (IOException e) {
throw new RuntimeException(String.format("Unable to parse SecretsManager secret (%s): %s",
secret, e.getMessage()), e);
}
finally {
secretsManager.shutdown();
}
}

return Optional.empty();
Expand Down
12 changes: 0 additions & 12 deletions athena-federation-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>${aws-sdk.version}</version>
<exclusions>
<!-- replaced with jcl-over-slf4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
package com.amazonaws.athena.connectors.google.bigquery;

import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
import com.google.auth.oauth2.ServiceAccountCredentials;
import org.junit.After;
import org.junit.Before;
Expand All @@ -31,6 +28,9 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -47,12 +47,12 @@ public class BigQueryCompositeHandlerTest
System.setProperty("aws.region", "us-east-1");
}

MockedStatic<AWSSecretsManagerClientBuilder> awsSecretManagerClient;
MockedStatic<SecretsManagerClient> awsSecretManagerClient;
MockedStatic<ServiceAccountCredentials> serviceAccountCredentialsStatic;
MockedStatic<BigQueryUtils> bigQueryUtils;
private BigQueryCompositeHandler bigQueryCompositeHandler;
@Mock
private AWSSecretsManager secretsManager;
private SecretsManagerClient secretsManager;
@Mock
private ServiceAccountCredentials serviceAccountCredentials;

Expand All @@ -61,7 +61,7 @@ public void setUp()
{
bigQueryUtils = mockStatic(BigQueryUtils.class);
serviceAccountCredentialsStatic = mockStatic(ServiceAccountCredentials.class);
awsSecretManagerClient = mockStatic(AWSSecretsManagerClientBuilder.class);
awsSecretManagerClient = mockStatic(SecretsManagerClient.class);
}

@After
Expand All @@ -77,15 +77,18 @@ public void bigQueryCompositeHandlerTest() throws IOException
{
Exception ex = null;

Mockito.when(AWSSecretsManagerClientBuilder.defaultClient()).thenReturn(secretsManager);
GetSecretValueResult getSecretValueResult = new GetSecretValueResult().withVersionStages(Arrays.asList("v1")).withSecretString("{\n" +
" \"type\": \"service_account\",\n" +
" \"project_id\": \"mockProjectId\",\n" +
" \"private_key_id\": \"mockPrivateKeyId\",\n" +
" \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nmockPrivateKeydsfhdskfhjdfjkdhgfdjkghfdngvfkvfnjvfdjkg\\n-----END PRIVATE KEY-----\\n\",\n" +
" \"client_email\": \"mockabc@mockprojectid.iam.gserviceaccount.com\",\n" +
" \"client_id\": \"000000000000000000000\"\n" +
"}");
Mockito.when(SecretsManagerClient.create()).thenReturn(secretsManager);
GetSecretValueResponse getSecretValueResponse = GetSecretValueResponse.builder()
.versionStages(Arrays.asList("v1"))
.secretString("{\n" +
" \"type\": \"service_account\",\n" +
" \"project_id\": \"mockProjectId\",\n" +
" \"private_key_id\": \"mockPrivateKeyId\",\n" +
" \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nmockPrivateKeydsfhdskfhjdfjkdhgfdjkghfdngvfkvfnjvfdjkg\\n-----END PRIVATE KEY-----\\n\",\n" +
" \"client_email\": \"mockabc@mockprojectid.iam.gserviceaccount.com\",\n" +
" \"client_id\": \"000000000000000000000\"\n" +
"}")
.build();

Mockito.when(ServiceAccountCredentials.fromStream(any())).thenReturn(serviceAccountCredentials);
bigQueryCompositeHandler = new BigQueryCompositeHandler();
Expand Down

0 comments on commit fb591ee

Please sign in to comment.