use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class CacheableSecretsManagerTest method evictionTest.
@Test
public void evictionTest() {
for (int i = 0; i < CachableSecretsManager.MAX_CACHE_SIZE; i++) {
cachableSecretsManager.addCacheEntry("test" + i, "value" + i, System.currentTimeMillis());
}
when(mockSecretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenAnswer((InvocationOnMock invocation) -> {
GetSecretValueRequest request = invocation.getArgumentAt(0, GetSecretValueRequest.class);
return new GetSecretValueResult().withSecretString(request.getSecretId() + "_value");
});
assertEquals("test_value", cachableSecretsManager.getSecret("test"));
assertEquals("test0_value", cachableSecretsManager.getSecret("test0"));
verify(mockSecretsManager, times(2)).getSecretValue(any(GetSecretValueRequest.class));
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class BigQueryUtils method getCredentialsFromSecretsManager.
public static Credentials getCredentialsFromSecretsManager() throws IOException {
AWSSecretsManager secretsManager = AWSSecretsManagerClientBuilder.defaultClient();
GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest();
getSecretValueRequest.setSecretId(getEnvBigQueryCredsSmId());
GetSecretValueResult response = secretsManager.getSecretValue(getSecretValueRequest);
return ServiceAccountCredentials.fromStream(new ByteArrayInputStream(response.getSecretString().getBytes()));
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class BigQueryCompositeHandlerTest method bigQueryCompositeHandlerTest.
@Test
public void bigQueryCompositeHandlerTest() throws IOException {
Exception ex = null;
try {
PowerMockito.mockStatic(AWSSecretsManagerClientBuilder.class);
PowerMockito.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(secretsManager.getSecretValue(Mockito.any())).thenReturn(getSecretValueResult);
PowerMockito.mockStatic(ServiceAccountCredentials.class);
PowerMockito.when(ServiceAccountCredentials.fromStream(Mockito.any())).thenReturn(serviceAccountCredentials);
PowerMockito.mockStatic(System.class);
PowerMockito.when(System.getenv(anyString())).thenReturn("test");
PowerMockito.mockStatic(BigQueryOptions.Builder.class);
PowerMockito.when(builder.build()).thenReturn(bigQueryOptions);
PowerMockito.when(bigQueryOptions.getService()).thenReturn(bigQuery);
bigQueryCompositeHandler = new BigQueryCompositeHandler();
} catch (Exception e) {
ex = e;
}
assertEquals(null, ex);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class HiveRecordHandlerTest method setup.
@Before
public void setup() {
this.amazonS3 = Mockito.mock(AmazonS3.class);
this.secretsManager = Mockito.mock(AWSSecretsManager.class);
this.athena = Mockito.mock(AmazonAthena.class);
Mockito.when(this.secretsManager.getSecretValue(Mockito.eq(new GetSecretValueRequest().withSecretId("testSecret")))).thenReturn(new GetSecretValueResult().withSecretString("{\"username\": \"testUser\", \"password\": \"testPassword\"}"));
this.connection = Mockito.mock(Connection.class);
this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class);
Mockito.when(this.jdbcConnectionFactory.getConnection(Mockito.mock(JdbcCredentialProvider.class))).thenReturn(this.connection);
jdbcSplitQueryBuilder = new HiveQueryStringBuilder("`");
final DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", HiveConstants.HIVE_NAME, "hive2://jdbc:hive2://54.89.6.2:10000/authena;AuthMech=3;UID=hive;PWD=hive");
this.hiveRecordHandler = new HiveRecordHandler(databaseConnectionConfig, amazonS3, secretsManager, athena, jdbcConnectionFactory, jdbcSplitQueryBuilder);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class MySqlMetadataHandlerTest method setup.
@Before
public void setup() {
this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class);
this.connection = Mockito.mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(this.jdbcConnectionFactory.getConnection(Mockito.any(JdbcCredentialProvider.class))).thenReturn(this.connection);
this.secretsManager = Mockito.mock(AWSSecretsManager.class);
this.athena = Mockito.mock(AmazonAthena.class);
Mockito.when(this.secretsManager.getSecretValue(Mockito.eq(new GetSecretValueRequest().withSecretId("testSecret")))).thenReturn(new GetSecretValueResult().withSecretString("{\"username\": \"testUser\", \"password\": \"testPassword\"}"));
this.mySqlMetadataHandler = new MySqlMetadataHandler(databaseConnectionConfig, this.secretsManager, this.athena, this.jdbcConnectionFactory);
this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
}
Aggregations