From 81ad77fa59791c128545a2dfd005c0da676c6921 Mon Sep 17 00:00:00 2001 From: Andrei Isvoran Date: Fri, 14 Jul 2023 10:39:57 +0300 Subject: [PATCH] RED-6593 - Fix azure test connection + move create schema logic --- build.gradle.kts | 2 +- .../service/TenantManagementService.java | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 230d2e4..77014d0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -77,7 +77,7 @@ dependencies { implementation("org.apache.commons:commons-lang3:3.12.0") implementation("commons-validator:commons-validator:1.7") implementation("org.springframework.boot:spring-boot-configuration-processor") - implementation("com.iqser.red.commons:storage-commons:2.3.0") + implementation("com.iqser.red.commons:storage-commons:2.4.0") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.cloud:spring-cloud-starter-openfeign") testImplementation("org.projectlombok:lombok") diff --git a/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java b/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java index ff80562..4c4f5d3 100644 --- a/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java +++ b/src/main/java/com/knecon/fforesight/tenantusermanagement/service/TenantManagementService.java @@ -93,9 +93,6 @@ public class TenantManagementService implements TenantProvider { log.info("Creating tenant: {}", tenantRequest.getTenantId()); var jdbcUrl = JDBCUtils.buildJdbcUrlWithSchema(tenantRequest.getDatabaseConnection()); validateJdbcUrl(jdbcUrl); - createSchema(tenantRequest); - - log.info("Created schema for tenant: {}", tenantRequest.getTenantId()); TenantEntity tenantEntity = TenantEntity.builder() .tenantId(tenantRequest.getTenantId()) @@ -122,7 +119,8 @@ public class TenantManagementService implements TenantProvider { .build(); if (tenantRequest.getAzureStorageConnection() != null) { - testAzureConnection(tenantRequest.getAzureStorageConnection().getConnectionString()); + testAzureConnection(tenantRequest.getAzureStorageConnection().getConnectionString(), + tenantRequest.getAzureStorageConnection().getContainerName()); tenantEntity.setAzureStorageConnection(AzureStorageConnectionEntity.builder() .connectionString(encryptionService.encrypt(tenantRequest.getAzureStorageConnection().getConnectionString())) @@ -143,6 +141,10 @@ public class TenantManagementService implements TenantProvider { .build()); } + createSchema(tenantRequest); + + log.info("Created schema for tenant: {}", tenantRequest.getTenantId()); + propagateTenantToKeyCloak(tenantRequest); log.info("Updated roles for tenant: {}", tenantRequest.getTenantId()); @@ -395,7 +397,8 @@ public class TenantManagementService implements TenantProvider { var azureStorageConnection = tenantRequest.getAzureStorageConnection(); if (azureStorageConnection != null) { - testAzureConnection(tenantRequest.getAzureStorageConnection().getConnectionString()); + testAzureConnection(azureStorageConnection.getConnectionString(), + azureStorageConnection.getContainerName()); tenantEntity .setAzureStorageConnection(AzureStorageConnectionEntity.builder() .connectionString(encryptionService.encrypt(azureStorageConnection.getConnectionString())) @@ -485,9 +488,9 @@ public class TenantManagementService implements TenantProvider { return tenantResponse; } - private void testAzureConnection(String connectionString) { + private void testAzureConnection(String connectionString, String containerName) { - var connection = storageConfiguration.getAzureBlobStorageService().testConnection(connectionString); + var connection = storageConfiguration.getAzureBlobStorageService().testConnection(connectionString, containerName); if (!connection) { throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Could not connect to Azure storage");