Search in sources :

Example 16 with GetSecretValueResult

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);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Connection(java.sql.Connection) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) JdbcCredentialProvider(com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 17 with GetSecretValueResult

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);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) QueryFactory(com.amazonaws.athena.connectors.vertica.query.QueryFactory) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Schema(org.apache.arrow.vector.types.pojo.Schema) LocalKeyFactory(com.amazonaws.athena.connector.lambda.security.LocalKeyFactory) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) Constraints(com.amazonaws.athena.connector.lambda.domain.predicate.Constraints) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) VerticaExportQueryBuilder(com.amazonaws.athena.connectors.vertica.query.VerticaExportQueryBuilder) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 18 with GetSecretValueResult

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);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Connection(java.sql.Connection) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) JdbcCredentialProvider(com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 19 with GetSecretValueResult

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);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) JdbcCredentialProvider(com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 20 with GetSecretValueResult

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();
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)

Aggregations

GetSecretValueResult (com.amazonaws.services.secretsmanager.model.GetSecretValueResult)60 GetSecretValueRequest (com.amazonaws.services.secretsmanager.model.GetSecretValueRequest)51 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)25 Before (org.junit.Before)21 JdbcConnectionFactory (com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory)18 JdbcCredentialProvider (com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider)18 AmazonAthena (com.amazonaws.services.athena.AmazonAthena)17 FederatedIdentity (com.amazonaws.athena.connector.lambda.security.FederatedIdentity)16 Connection (java.sql.Connection)13 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)8 AmazonS3 (com.amazonaws.services.s3.AmazonS3)6 DatabaseConnectionConfig (com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Map (java.util.Map)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 QueryStatusChecker (com.amazonaws.athena.connector.lambda.QueryStatusChecker)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3