From 5f1e9363d91ee3045c8a7d5df1fb3fc21897c12e Mon Sep 17 00:00:00 2001 From: Luca Consalvi Date: Wed, 27 Nov 2024 14:26:04 +0100 Subject: [PATCH] change some properties --- .../rtp/activator/configuration/CosmosDBConfig.java | 9 +++------ .../configuration/CosmosPropertiesConfig.java | 12 ++++++------ src/main/resources/application.properties | 6 +++--- .../terraform/env/cstar-d-weu-rtp/terraform.tfvars | 1 + .../terraform/env/cstar-p-weu-rtp/terraform.tfvars | 1 + .../terraform/env/cstar-u-weu-rtp/terraform.tfvars | 1 + .../activator/configuration/CosmosDBConfigTest.java | 10 +++++----- .../configuration/CosmosPropertiesConfigTest.java | 4 ++-- src/test/resources/application.properties | 7 +++---- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java index bf69f2a..f8a6850 100644 --- a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java +++ b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java @@ -1,8 +1,5 @@ package it.gov.pagopa.rtp.activator.configuration; - -import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -24,7 +21,7 @@ public CosmosDBConfig(CosmosPropertiesConfig cosmosPropertiesConfig){ @Override protected String getDatabaseName() { - return cosmosPropertiesConfig.getDbName(); + return cosmosPropertiesConfig.getDatabase(); } @Bean @@ -33,8 +30,8 @@ public CosmosClientBuilder getCosmosClientBuilder() { .build(); return new CosmosClientBuilder() - .endpoint(cosmosPropertiesConfig.getEndpoint()) - .credential(credential); + .endpoint(cosmosPropertiesConfig.getUri()) + .credential(credential); } } diff --git a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java index 40b83cf..7f5e29c 100644 --- a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java +++ b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java @@ -5,15 +5,15 @@ import lombok.Getter; import lombok.Setter; -@ConfigurationProperties(prefix = "cosmos.credential") +@ConfigurationProperties(prefix = "azure.cosmos") @Getter @Setter public class CosmosPropertiesConfig { - private String dbName; - private String endpoint; + private String database; + private String uri; - public CosmosPropertiesConfig(String dbName, String endpoint) { - this.dbName = dbName; - this.endpoint = endpoint; + public CosmosPropertiesConfig(String database, String uri) { + this.database = database; + this.uri = uri; } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c283c24..01c90d2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -9,8 +9,8 @@ management.endpoint.health.enabled=true management.endpoint.health.probes.enabled=true #repository -cosmos.credential.db-name=${DB_NAME:rtp} -cosmos.credential.endpoint=${COSMOS_ACCOUNT_RTP_ENDPOINT:} - +azure.cosmos.uri=${COSMOS_ACCOUNT_RTP_ENDPOINT:} +azure.cosmos.key=${AZURE_COSMOS_KEY:} +azure.cosmos.database=${DB_NAME:rtp} activation.base-url=${BASE_URL:http://localhost} diff --git a/src/main/terraform/env/cstar-d-weu-rtp/terraform.tfvars b/src/main/terraform/env/cstar-d-weu-rtp/terraform.tfvars index 1df801c..50e6db4 100644 --- a/src/main/terraform/env/cstar-d-weu-rtp/terraform.tfvars +++ b/src/main/terraform/env/cstar-d-weu-rtp/terraform.tfvars @@ -44,6 +44,7 @@ rtp_activator_base_url = "https://mil-d-apim.azure-api. rtp_environment_secrets = { COSMOS_ACCOUNT_RTP_ENDPOINT : "cosmosdb-account-rtp-endpoint" + AZURE_COSMOS_KEY : "azure-cosmos-key" APPLICATIONINSIGHTS_CONNECTION_STRING : "appinsights-connection-string" } diff --git a/src/main/terraform/env/cstar-p-weu-rtp/terraform.tfvars b/src/main/terraform/env/cstar-p-weu-rtp/terraform.tfvars index faba2ab..a0ffc18 100644 --- a/src/main/terraform/env/cstar-p-weu-rtp/terraform.tfvars +++ b/src/main/terraform/env/cstar-p-weu-rtp/terraform.tfvars @@ -44,6 +44,7 @@ rtp_activator_base_url = "https://mil-d-apim.azure-api. rtp_environment_secrets = { COSMOS_ACCOUNT_RTP_ENDPOINT : "cosmosdb-account-rtp-endpoint" APPLICATIONINSIGHTS_CONNECTION_STRING : "appinsights-connection-string" + AZURE_COSMOS_KEY : "azure-cosmos-key" } rtp_environment_configs = { diff --git a/src/main/terraform/env/cstar-u-weu-rtp/terraform.tfvars b/src/main/terraform/env/cstar-u-weu-rtp/terraform.tfvars index e92e10e..07c1af6 100644 --- a/src/main/terraform/env/cstar-u-weu-rtp/terraform.tfvars +++ b/src/main/terraform/env/cstar-u-weu-rtp/terraform.tfvars @@ -45,6 +45,7 @@ rtp_activator_base_url = "https://mil-d-apim.azure-api. rtp_environment_secrets = { COSMOS_ACCOUNT_RTP_ENDPOINT : "cosmosdb-account-rtp-endpoint" APPLICATIONINSIGHTS_CONNECTION_STRING : "appinsights-connection-string" + AZURE_COSMOS_KEY : "azure-cosmos-key" } diff --git a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java index 80cef51..6ec6f87 100644 --- a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java +++ b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java @@ -25,20 +25,20 @@ class CosmosDBConfigTest { @BeforeEach void setUp() { - lenient().when(cosmosPropertiesConfig.getDbName()).thenReturn("test-db"); - lenient().when(cosmosPropertiesConfig.getEndpoint()).thenReturn("https://test-endpoint:443/"); + lenient().when(cosmosPropertiesConfig.getDatabase()).thenReturn("test-db"); + lenient().when(cosmosPropertiesConfig.getUri()).thenReturn("https://test-endpoint:443/"); } @Test void testGetDatabaseName() { - String dbName = cosmosDBConfig.getDatabaseName(); - assertEquals("test-db", dbName); + String database = cosmosDBConfig.getDatabaseName(); + assertEquals("test-db", database); } @Test void testGetCosmosClientBuilder() { CosmosClientBuilder builder = cosmosDBConfig.getCosmosClientBuilder(); - verify(cosmosPropertiesConfig).getEndpoint(); + verify(cosmosPropertiesConfig).getUri(); assertNotNull(builder); } } diff --git a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java index 754b70b..06d7b46 100644 --- a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java +++ b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java @@ -21,8 +21,8 @@ class CosmosPropertiesConfigTest { @Test void testPropertiesLoaded() { assertNotNull(cosmosPropertiesConfig); - assertEquals("https://example.com/db/endpoint", cosmosPropertiesConfig.getEndpoint()); - assertEquals("rtp", cosmosPropertiesConfig.getDbName()); + assertEquals("https://example.com/db/endpoint", cosmosPropertiesConfig.getUri()); + assertEquals("rtp", cosmosPropertiesConfig.getDatabase()); } } \ No newline at end of file diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 70440cc..9b31274 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1,7 +1,6 @@ logging.level.org.springframework.security=DEBUG activation.baseUrl=https://example.com - -cosmos.credential.db-name=rtp -cosmos.credential.endpoint=https://example.com/db/endpoint - +azure.cosmos.uri=https://example.com/db/endpoint +azure.cosmos.key=your-primary-key +azure.cosmos.database=rtp \ No newline at end of file