use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class SaphanaMetadataHandlerTest method setup.
@Before
public void setup() {
this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
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.saphanaMetadataHandler = new SaphanaMetadataHandler(databaseConnectionConfig, this.secretsManager, this.athena, this.jdbcConnectionFactory);
this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
this.blockAllocator = Mockito.mock(BlockAllocator.class);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class RedshiftMetadataHandlerTest 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);
Mockito.when(this.secretsManager.getSecretValue(Mockito.eq(new GetSecretValueRequest().withSecretId("testSecret")))).thenReturn(new GetSecretValueResult().withSecretString("{\"username\": \"testUser\", \"password\": \"testPassword\"}"));
this.redshiftMetadataHandler = new RedshiftMetadataHandler(databaseConnectionConfig, this.secretsManager, this.athena, this.jdbcConnectionFactory);
this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class TeradataMetadataHandlerTest method setup.
@Before
public void setup() throws Exception {
this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
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.teradataMetadataHandler = new TeradataMetadataHandler(databaseConnectionConfig, this.secretsManager, this.athena, this.jdbcConnectionFactory);
this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
this.blockAllocator = Mockito.mock(BlockAllocator.class);
environmentVariablesRule.set("partitioncount", "1000");
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class SecretsManagerCredentialsProvider method getCredentials.
/**
* Gets the SecretManager credentials obtained using a secret name stored in the test-config.json file.
* @param testConfig Contains the test configurations from the test-config.json file.
* @return Optional credentials object, or empty Optional if the secrets_manager_secret attribute is not in the
* configuration file or is empty.
* @throws RuntimeException Error encountered attempting to parse the json string returned from SecretsManager.
*/
public static Optional<SecretsManagerCredentials> getCredentials(TestConfig testConfig) throws RuntimeException {
Optional<String> secretsManagerSecret = testConfig.getStringItem(TEST_CONFIG_SECRETS_MANAGER_SECRET);
if (secretsManagerSecret.isPresent()) {
String secret = secretsManagerSecret.get();
AWSSecretsManager secretsManager = AWSSecretsManagerClientBuilder.defaultClient();
try {
GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest().withSecretId(secret));
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> credentials = objectMapper.readValue(secretValueResult.getSecretString(), HashMap.class);
return Optional.of(new SecretsManagerCredentials(secret, credentials.get("username"), credentials.get("password"), secretValueResult.getARN()));
} 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();
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class HiveMetadataHandlerTest method setup.
@Before
public void setup() {
this.blockAllocator = Mockito.mock(BlockAllocator.class);
this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
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.hiveMetadataHandler = new HiveMetadataHandler(databaseConnectionConfig, this.secretsManager, this.athena, this.jdbcConnectionFactory);
this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
}
Aggregations