Search in sources :

Example 46 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.

the class CacheableSecretsManagerTest method expirationTest.

@Test
public void expirationTest() {
    cachableSecretsManager.addCacheEntry("test", "value", System.currentTimeMillis());
    assertEquals("value", cachableSecretsManager.getSecret("test"));
    verifyNoMoreInteractions(mockSecretsManager);
    reset(mockSecretsManager);
    when(mockSecretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenAnswer((InvocationOnMock invocation) -> {
        GetSecretValueRequest request = invocation.getArgumentAt(0, GetSecretValueRequest.class);
        if (request.getSecretId().equalsIgnoreCase("test")) {
            return new GetSecretValueResult().withSecretString("value2");
        }
        throw new RuntimeException();
    });
    cachableSecretsManager.addCacheEntry("test", "value", 0);
    assertEquals("value2", cachableSecretsManager.getSecret("test"));
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) Test(org.junit.Test)

Example 47 with GetSecretValueResult

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);
}
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 48 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.

the class JdbcRecordHandlerTest method setup.

@Before
public void setup() throws SQLException {
    this.connection = Mockito.mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
    this.jdbcConnectionFactory = Mockito.mock(JdbcConnectionFactory.class);
    Mockito.when(this.jdbcConnectionFactory.getConnection(Mockito.any(JdbcCredentialProvider.class))).thenReturn(this.connection);
    this.amazonS3 = Mockito.mock(AmazonS3.class);
    this.secretsManager = Mockito.mock(AWSSecretsManager.class);
    this.athena = Mockito.mock(AmazonAthena.class);
    this.queryStatusChecker = Mockito.mock(QueryStatusChecker.class);
    Mockito.when(this.secretsManager.getSecretValue(Mockito.eq(new GetSecretValueRequest().withSecretId("testSecret")))).thenReturn(new GetSecretValueResult().withSecretString("{\"username\": \"testUser\", \"password\": \"testPassword\"}"));
    this.preparedStatement = Mockito.mock(PreparedStatement.class);
    Mockito.when(this.connection.prepareStatement("someSql")).thenReturn(this.preparedStatement);
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", "fakedatabase", "fakedatabase://jdbc:fakedatabase://hostname/${testSecret}", "testSecret");
    this.jdbcRecordHandler = new JdbcRecordHandler(this.amazonS3, this.secretsManager, this.athena, databaseConnectionConfig, this.jdbcConnectionFactory) {

        @Override
        public PreparedStatement buildSplitSql(Connection jdbcConnection, String catalogName, TableName tableName, Schema schema, Constraints constraints, Split split) throws SQLException {
            return jdbcConnection.prepareStatement("someSql");
        }
    };
    this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) SQLException(java.sql.SQLException) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Schema(org.apache.arrow.vector.types.pojo.Schema) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) TableName(com.amazonaws.athena.connector.lambda.domain.TableName) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) Constraints(com.amazonaws.athena.connector.lambda.domain.predicate.Constraints) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) JdbcCredentialProvider(com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider) Split(com.amazonaws.athena.connector.lambda.domain.Split) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 49 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.

the class JdbcMetadataHandlerTest 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\"}"));
    DatabaseConnectionConfig databaseConnectionConfig = new DatabaseConnectionConfig("testCatalog", "fakedatabase", "fakedatabase://jdbc:fakedatabase://hostname/${testSecret}", "testSecret");
    this.jdbcMetadataHandler = new JdbcMetadataHandler(databaseConnectionConfig, this.secretsManager, this.athena, jdbcConnectionFactory) {

        @Override
        public Schema getPartitionSchema(final String catalogName) {
            return PARTITION_SCHEMA;
        }

        @Override
        public void getPartitions(final BlockWriter blockWriter, final GetTableLayoutRequest getTableLayoutRequest, QueryStatusChecker queryStatusChecker) {
        }

        @Override
        public GetSplitsResponse doGetSplits(BlockAllocator blockAllocator, GetSplitsRequest getSplitsRequest) {
            return null;
        }
    };
    this.federatedIdentity = Mockito.mock(FederatedIdentity.class);
    this.blockAllocator = Mockito.mock(BlockAllocator.class);
}
Also used : JdbcConnectionFactory(com.amazonaws.athena.connectors.jdbc.connection.JdbcConnectionFactory) GetSplitsRequest(com.amazonaws.athena.connector.lambda.metadata.GetSplitsRequest) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) Schema(org.apache.arrow.vector.types.pojo.Schema) Connection(java.sql.Connection) DatabaseConnectionConfig(com.amazonaws.athena.connectors.jdbc.connection.DatabaseConnectionConfig) GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) QueryStatusChecker(com.amazonaws.athena.connector.lambda.QueryStatusChecker) FederatedIdentity(com.amazonaws.athena.connector.lambda.security.FederatedIdentity) GetSplitsResponse(com.amazonaws.athena.connector.lambda.metadata.GetSplitsResponse) GetTableLayoutRequest(com.amazonaws.athena.connector.lambda.metadata.GetTableLayoutRequest) BlockAllocator(com.amazonaws.athena.connector.lambda.data.BlockAllocator) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) BlockWriter(com.amazonaws.athena.connector.lambda.data.BlockWriter) JdbcCredentialProvider(com.amazonaws.athena.connectors.jdbc.connection.JdbcCredentialProvider) AmazonAthena(com.amazonaws.services.athena.AmazonAthena) Before(org.junit.Before)

Example 50 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.

the class PostGreSqlMetadataHandlerTest 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.postGreSqlMetadataHandler = new PostGreSqlMetadataHandler(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) Before(org.junit.Before)

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