Search in sources :

Example 56 with GetSecretValueResult

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

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

the class DataLakeGen2MetadataHandlerTest 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.dataLakeGen2MetadataHandler = new DataLakeGen2MetadataHandler(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 58 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project spring-cloud-aws by awspring.

the class AwsSecretsManagerPropertySourceTest method shouldParseSecretValue.

@Test
void shouldParseSecretValue() {
    GetSecretValueResult secretValueResult = new GetSecretValueResult();
    secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
    when(client.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult);
    propertySource.init();
    assertThat(propertySource.getPropertyNames()).containsExactly("key1", "key2");
    assertThat(propertySource.getProperty("key1")).isEqualTo("value1");
    assertThat(propertySource.getProperty("key2")).isEqualTo("value2");
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) Test(org.junit.jupiter.api.Test)

Example 59 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project spring-cloud-aws by awspring.

the class AwsSecretsManagerPropertySourceLocatorTest method contextExpectSpecificOrderAndEmptyPrefix.

@Test
void contextExpectSpecificOrderAndEmptyPrefix() {
    AwsSecretsManagerProperties properties = new AwsSecretsManagerPropertiesBuilder().withDefaultContext("application").withPrefix("").withName("messaging-service").build();
    GetSecretValueResult secretValueResult = new GetSecretValueResult();
    secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
    when(smClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult);
    AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(smClient, properties);
    env.setActiveProfiles("test");
    locator.locate(env);
    List<String> contextToBeTested = new ArrayList<>(locator.getContexts());
    assertThat(contextToBeTested.get(0)).isEqualTo("/messaging-service_test");
    assertThat(contextToBeTested.get(1)).isEqualTo("/messaging-service");
    assertThat(contextToBeTested.get(2)).isEqualTo("/application_test");
    assertThat(contextToBeTested.get(3)).isEqualTo("/application");
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) ArrayList(java.util.ArrayList) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) Test(org.junit.jupiter.api.Test)

Example 60 with GetSecretValueResult

use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project spring-cloud-aws by awspring.

the class AwsSecretsManagerPropertySourceLocatorTest method locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName.

@Test
void locate_nameNotSpecifiedInConstructor_returnsPropertySourceWithDefaultName() {
    GetSecretValueResult secretValueResult = new GetSecretValueResult();
    secretValueResult.setSecretString("{\"key1\": \"value1\", \"key2\": \"value2\"}");
    when(smClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult);
    AwsSecretsManagerProperties properties = new AwsSecretsManagerProperties();
    AwsSecretsManagerPropertySourceLocator locator = new AwsSecretsManagerPropertySourceLocator(smClient, properties);
    PropertySource propertySource = locator.locate(env);
    assertThat(propertySource.getName()).isEqualTo("aws-secrets-manager");
}
Also used : GetSecretValueResult(com.amazonaws.services.secretsmanager.model.GetSecretValueResult) GetSecretValueRequest(com.amazonaws.services.secretsmanager.model.GetSecretValueRequest) PropertySource(org.springframework.core.env.PropertySource) CompositePropertySource(org.springframework.core.env.CompositePropertySource) Test(org.junit.jupiter.api.Test)

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