From ae5c19faca8a8d07758c30f27dc0d1e7cd7eb3d1 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Wed, 4 Aug 2021 21:54:17 -0400 Subject: [PATCH] =?UTF-8?q?#8=20Ajout=20de=20ConfigurationBase,=20dont=20C?= =?UTF-8?q?onfiguration=20et=20SecureConfiguration=20h=C3=A9ritent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/Configuration.kt | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/dev/fyloz/colorrecipesexplorer/model/Configuration.kt b/src/main/kotlin/dev/fyloz/colorrecipesexplorer/model/Configuration.kt index c1c4384..3f6f8f8 100644 --- a/src/main/kotlin/dev/fyloz/colorrecipesexplorer/model/Configuration.kt +++ b/src/main/kotlin/dev/fyloz/colorrecipesexplorer/model/Configuration.kt @@ -12,20 +12,25 @@ import javax.persistence.Id import javax.persistence.Table import javax.validation.constraints.NotBlank -data class Configuration( +sealed class ConfigurationBase( @JsonIgnore val type: ConfigurationType, - val content: String, val lastUpdated: LocalDateTime ) { val key = type.key val requireRestart = type.requireRestart val editable = !type.computed +} +class Configuration(type: ConfigurationType, val content: String, lastUpdated: LocalDateTime) : + ConfigurationBase(type, lastUpdated) { fun toEntity() = ConfigurationEntity(key, content, lastUpdated) } +class SecureConfiguration(type: ConfigurationType, lastUpdated: LocalDateTime) : + ConfigurationBase(type, lastUpdated) + @Entity @Table(name = "configuration") data class ConfigurationEntity( @@ -92,7 +97,13 @@ enum class ConfigurationType( DATABASE_URL("database.url", defaultContent = "mysql://localhost/cre", file = true, requireRestart = true), DATABASE_USER("database.user", defaultContent = "cre", file = true, requireRestart = true), - DATABASE_PASSWORD("database.password", defaultContent = "asecurepassword", file = true, requireRestart = true, secure = true), + DATABASE_PASSWORD( + "database.password", + defaultContent = "asecurepassword", + file = true, + requireRestart = true, + secure = true + ), DATABASE_SUPPORTED_VERSION("database.version.supported", computed = true), RECIPE_APPROBATION_EXPIRATION("recipe.approbation.expiration", defaultContent = 4.months), @@ -128,15 +139,15 @@ class InvalidConfigurationKeyException(val key: String) : ) class InvalidImageConfigurationException(val type: ConfigurationType) : - RestException( - "invalid-configuration-image", - "Invalid image configuration", - HttpStatus.BAD_REQUEST, - "The configuration with the key '${type.key}' does not accept images as content", - mapOf( - "key" to type.key - ) - ) + RestException( + "invalid-configuration-image", + "Invalid image configuration", + HttpStatus.BAD_REQUEST, + "The configuration with the key '${type.key}' does not accept images as content", + mapOf( + "key" to type.key + ) + ) class ConfigurationNotSetException(val type: ConfigurationType) : RestException(