use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class SqlServerMetadataHandlerTest method setup.
@Before
public void setup() {
System.setProperty("aws.region", "us-east-1");
this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
this.connection = Mockito.mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
logger.info(" this.connection.." + this.connection);
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("{\"user\": \"testUser\", \"password\": \"testPassword\"}"));
this.sqlServerMetadataHandler = new SqlServerMetadataHandler(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 VerticaMetadataHandlerTest method setUp.
@Before
public void setUp() throws SQLException {
this.verticaConnectionFactory = Mockito.mock(VerticaConnectionFactory.class);
this.verticaSchemaUtils = Mockito.mock(VerticaSchemaUtils.class);
this.queryFactory = Mockito.mock(QueryFactory.class);
this.verticaExportQueryBuilder = Mockito.mock(VerticaExportQueryBuilder.class);
this.connection = Mockito.mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
this.secretsManager = Mockito.mock(AWSSecretsManager.class);
this.athena = Mockito.mock(AmazonAthena.class);
this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
this.databaseMetaData = Mockito.mock(DatabaseMetaData.class);
this.tableName = Mockito.mock(TableName.class);
this.schema = Mockito.mock(Schema.class);
this.constraints = Mockito.mock(Constraints.class);
this.schemaBuilder = Mockito.mock(SchemaBuilder.class);
this.blockWriter = Mockito.mock(BlockWriter.class);
this.queryStatusChecker = Mockito.mock(QueryStatusChecker.class);
this.amazonS3 = Mockito.mock(AmazonS3.class);
Mockito.when(this.secretsManager.getSecretValue(Mockito.eq(new GetSecretValueRequest().withSecretId("testSecret")))).thenReturn(new GetSecretValueResult().withSecretString("{\"username\": \"testUser\", \"password\": \"testPassword\"}"));
Mockito.when(this.verticaConnectionFactory.getOrCreateConn(anyString())).thenReturn(connection);
Mockito.when(connection.getMetaData()).thenReturn(databaseMetaData);
Mockito.when(amazonS3.getRegion()).thenReturn(Region.US_West_2);
this.verticaMetadataHandler = new VerticaMetadataHandler(new LocalKeyFactory(), verticaConnectionFactory, secretsManager, athena, "spill-bucket", "spill-prefix", verticaSchemaUtils, amazonS3);
this.allocator = new BlockAllocatorImpl();
this.databaseMetaData = this.connection.getMetaData();
verticaMetadataHandlerMocked = Mockito.spy(this.verticaMetadataHandler);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class ImpalaRecordHandlerTest 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 ImpalaQueryStringBuilder("`");
final DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", ImpalaConstants.IMPALA_NAME, "impala://jdbc:impala://54.89.6.2:10000/authena;{testSecret}", "testSecret");
this.impalaRecordHandler = new ImpalaRecordHandler(databaseConnectionConfig, amazonS3, secretsManager, athena, jdbcConnectionFactory, jdbcSplitQueryBuilder);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class ImpalaMetadataHandlerTest 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.impalaMetadataHandler = new ImpalaMetadataHandler(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 CachableSecretsManager method getSecret.
/**
* Retrieves a secret from SecretsManager, first checking the cache. Newly fetched secrets are added to the cache.
*
* @param secretName The name of the secret to retrieve.
* @return The value of the secret, throws if no such secret is found.
*/
public String getSecret(String secretName) {
CacheEntry cacheEntry = cache.get(secretName);
if (cacheEntry == null || cacheEntry.getAge() > MAX_CACHE_AGE_MS) {
logger.info("getSecret: Resolving secret[{}].", secretName);
GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest().withSecretId(secretName));
cacheEntry = new CacheEntry(secretName, secretValueResult.getSecretString());
evictCache(cache.size() >= MAX_CACHE_SIZE);
cache.put(secretName, cacheEntry);
}
return cacheEntry.getValue();
}
Aggregations