diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java index 050e988ae0a..8f0da168ea0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java @@ -45,6 +45,7 @@ import org.jdbi.v3.sqlobject.customizer.BindMap; import org.jdbi.v3.sqlobject.customizer.Define; import org.jdbi.v3.sqlobject.statement.SqlQuery; import org.jdbi.v3.sqlobject.statement.SqlUpdate; +import org.openmetadata.api.configuration.LogoConfiguration; import org.openmetadata.common.utils.CommonUtil; import org.openmetadata.schema.TokenInterface; import org.openmetadata.schema.analytics.ReportData; @@ -3132,6 +3133,9 @@ public interface CollectionDAO { case EMAIL_CONFIGURATION: value = JsonUtils.readValue(json, SmtpSettings.class); break; + case CUSTOM_LOGO_CONFIGURATION: + value = JsonUtils.readValue(json, LogoConfiguration.class); + break; default: throw new IllegalArgumentException("Invalid Settings Type " + configType); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java index d8975cb9a9b..c240edfce23 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java @@ -13,6 +13,7 @@ package org.openmetadata.service.resources.settings; +import static org.openmetadata.schema.settings.SettingsType.CUSTOM_LOGO_CONFIGURATION; import static org.openmetadata.schema.settings.SettingsType.EMAIL_CONFIGURATION; import com.google.common.cache.CacheBuilder; @@ -21,6 +22,7 @@ import com.google.common.cache.LoadingCache; import java.util.concurrent.TimeUnit; import javax.annotation.CheckForNull; import lombok.extern.slf4j.Slf4j; +import org.openmetadata.api.configuration.LogoConfiguration; import org.openmetadata.schema.email.SmtpSettings; import org.openmetadata.schema.settings.Settings; import org.openmetadata.schema.settings.SettingsType; @@ -44,11 +46,12 @@ public class SettingsCache { CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new SettingsLoader()); systemRepository = new SystemRepository(dao.systemDAO()); INITIALIZED = true; - createEmailConfiguration(config); + createDefaultConfiguration(config); } } - private static void createEmailConfiguration(OpenMetadataApplicationConfig applicationConfig) { + private static void createDefaultConfiguration(OpenMetadataApplicationConfig applicationConfig) { + // Initialise Email Setting Settings storedSettings = systemRepository.getConfigWithKey(EMAIL_CONFIGURATION.toString()); if (storedSettings == null) { // Only in case a config doesn't exist in DB we insert it @@ -56,6 +59,17 @@ public class SettingsCache { Settings setting = new Settings().withConfigType(EMAIL_CONFIGURATION).withConfigValue(emailConfig); systemRepository.createNewSetting(setting); } + + // Initialise Logo Setting + Settings storedCustomLogoConf = systemRepository.getConfigWithKey(CUSTOM_LOGO_CONFIGURATION.toString()); + if (storedCustomLogoConf == null) { + // Only in case a config doesn't exist in DB we insert it + LogoConfiguration logoConfig = applicationConfig.getApplicationConfiguration().getLogoConfig(); + if (logoConfig != null) { + Settings setting = new Settings().withConfigType(CUSTOM_LOGO_CONFIGURATION).withConfigValue(logoConfig); + systemRepository.createNewSetting(setting); + } + } } public static SettingsCache getInstance() { diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java index 26d409da48c..6b2b337f7b0 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/system/SystemResourceTest.java @@ -2,17 +2,27 @@ package org.openmetadata.service.resources.system; import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.dropwizard.configuration.ConfigurationException; +import io.dropwizard.configuration.FileConfigurationSourceProvider; +import io.dropwizard.configuration.YamlConfigurationFactory; +import io.dropwizard.jackson.Jackson; +import io.dropwizard.jersey.validation.Validators; import java.io.IOException; import java.net.URISyntaxException; +import javax.validation.Validator; import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.HttpResponseException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.TestMethodOrder; +import org.openmetadata.api.configuration.LogoConfiguration; import org.openmetadata.schema.api.data.CreateContainer; import org.openmetadata.schema.api.data.CreateDashboard; import org.openmetadata.schema.api.data.CreateGlossary; @@ -30,11 +40,15 @@ import org.openmetadata.schema.api.teams.CreateTeam; import org.openmetadata.schema.api.teams.CreateUser; import org.openmetadata.schema.api.tests.CreateTestSuite; import org.openmetadata.schema.auth.SSOAuthMechanism; +import org.openmetadata.schema.email.SmtpSettings; import org.openmetadata.schema.entity.data.Table; import org.openmetadata.schema.entity.teams.AuthenticationMechanism; import org.openmetadata.schema.security.client.GoogleSSOClientConfig; +import org.openmetadata.schema.settings.Settings; +import org.openmetadata.schema.settings.SettingsType; import org.openmetadata.schema.util.EntitiesCount; import org.openmetadata.schema.util.ServicesCount; +import org.openmetadata.service.OpenMetadataApplicationConfig; import org.openmetadata.service.OpenMetadataApplicationTest; import org.openmetadata.service.resources.EntityResourceTest; import org.openmetadata.service.resources.dashboards.DashboardResourceTest; @@ -53,11 +67,23 @@ import org.openmetadata.service.resources.storages.ContainerResourceTest; import org.openmetadata.service.resources.teams.TeamResourceTest; import org.openmetadata.service.resources.teams.UserResourceTest; import org.openmetadata.service.resources.topics.TopicResourceTest; +import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.TestUtils; @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class SystemResourceTest extends OpenMetadataApplicationTest { + static OpenMetadataApplicationConfig config; + + @BeforeAll + static void setup() throws IOException, ConfigurationException { + // Get config object from test yaml file + ObjectMapper objectMapper = Jackson.newObjectMapper(); + Validator validator = Validators.newValidator(); + YamlConfigurationFactory factory = + new YamlConfigurationFactory<>(OpenMetadataApplicationConfig.class, validator, objectMapper, "dw"); + config = factory.build(new FileConfigurationSourceProvider(), CONFIG_PATH); + } @BeforeAll public static void setup(TestInfo test) throws IOException, URISyntaxException { @@ -66,7 +92,7 @@ public class SystemResourceTest extends OpenMetadataApplicationTest { } @Test - public void entitiesCount(TestInfo test) throws HttpResponseException { + void entitiesCount(TestInfo test) throws HttpResponseException { // Get count before adding entities EntitiesCount beforeCount = getEntitiesCount(); @@ -139,7 +165,52 @@ public class SystemResourceTest extends OpenMetadataApplicationTest { } @Test - public void servicesCount(TestInfo test) throws HttpResponseException { + @Order(1) + void testSystemConfigs() throws HttpResponseException { + // Test Email Config + Settings emailSettings = getSystemConfig(SettingsType.EMAIL_CONFIGURATION); + SmtpSettings smtp = JsonUtils.convertValue(emailSettings.getConfigValue(), SmtpSettings.class); + // Password for Email is always sent in hidden + SmtpSettings expected = config.getSmtpSettings(); + expected.setPassword("***********"); + Assertions.assertEquals(expected, smtp); + + // Test Custom Log Config + Settings logoConfigWrapped = getSystemConfig(SettingsType.CUSTOM_LOGO_CONFIGURATION); + LogoConfiguration loginConfiguration = + JsonUtils.convertValue(logoConfigWrapped.getConfigValue(), LogoConfiguration.class); + + Assertions.assertEquals(config.getApplicationConfiguration().getLogoConfig(), loginConfiguration); + } + + @Test + void testSystemConfigsUpdate(TestInfo test) throws HttpResponseException { + // Test Email Config + SmtpSettings smtpSettings = config.getSmtpSettings(); + // Update a few Email fields + smtpSettings.setUsername(test.getDisplayName()); + smtpSettings.setEmailingEntity(test.getDisplayName()); + + updateSystemConfig(new Settings().withConfigType(SettingsType.EMAIL_CONFIGURATION).withConfigValue(smtpSettings)); + SmtpSettings updateEmailSettings = + JsonUtils.convertValue(getSystemConfig(SettingsType.EMAIL_CONFIGURATION).getConfigValue(), SmtpSettings.class); + Assertions.assertEquals(updateEmailSettings.getUsername(), test.getDisplayName()); + Assertions.assertEquals(updateEmailSettings.getEmailingEntity(), test.getDisplayName()); + + // Test Custom Logo Update + LogoConfiguration updateConfigReq = + new LogoConfiguration().withCustomLogoUrlPath("http://test.com").withCustomMonogramUrlPath("http://test.com"); + // Update Custom Logo Settings + updateSystemConfig( + new Settings().withConfigType(SettingsType.CUSTOM_LOGO_CONFIGURATION).withConfigValue(updateConfigReq)); + LogoConfiguration updatedConfig = + JsonUtils.convertValue( + getSystemConfig(SettingsType.CUSTOM_LOGO_CONFIGURATION).getConfigValue(), LogoConfiguration.class); + Assertions.assertEquals(updateConfigReq, updatedConfig); + } + + @Test + void servicesCount(TestInfo test) throws HttpResponseException { // Get count before adding services ServicesCount beforeCount = getServicesCount(); @@ -183,7 +254,7 @@ public class SystemResourceTest extends OpenMetadataApplicationTest { } @Test - public void botUserCountCheck(TestInfo test) throws HttpResponseException { + void botUserCountCheck(TestInfo test) throws HttpResponseException { int beforeUserCount = getEntitiesCount().getUserCount(); // Create a bot user. @@ -216,4 +287,14 @@ public class SystemResourceTest extends OpenMetadataApplicationTest { WebTarget target = getResource("system/services/count"); return TestUtils.get(target, ServicesCount.class, ADMIN_AUTH_HEADERS); } + + private static Settings getSystemConfig(SettingsType settingsType) throws HttpResponseException { + WebTarget target = getResource(String.format("system/settings/%s", settingsType.value())); + return TestUtils.get(target, Settings.class, ADMIN_AUTH_HEADERS); + } + + private static void updateSystemConfig(Settings updatedSetting) throws HttpResponseException { + WebTarget target = getResource("system/settings"); + TestUtils.put(target, updatedSetting, Response.Status.OK, ADMIN_AUTH_HEADERS); + } } diff --git a/openmetadata-spec/src/main/resources/json/schema/settings/settings.json b/openmetadata-spec/src/main/resources/json/schema/settings/settings.json index d9f8cc29325..3824701a7fa 100644 --- a/openmetadata-spec/src/main/resources/json/schema/settings/settings.json +++ b/openmetadata-spec/src/main/resources/json/schema/settings/settings.json @@ -22,7 +22,8 @@ "secretsManagerConfiguration", "sandboxModeEnabled", "slackChat", - "emailConfiguration" + "emailConfiguration", + "customLogoConfiguration" ] } },