Refactor into configuration package

Implement existence check in k3sService.
This commit is contained in:
erik 2022-11-23 15:03:02 +01:00
parent 5cf191568e
commit 0ef50ea233
5 changed files with 22 additions and 10 deletions

View file

@ -1,6 +1,11 @@
package org.domaindrivenarchitecture.provs.configuration.domain package org.domaindrivenarchitecture.provs.configuration.domain
import java.io.File
class ConfigFileName(fileName: String) class ConfigFileName(fileName: String)
{ {
val fileName = fileName.trim() val fileName = fileName.trim()
fun fullqualified() : String {
return File(fileName).absoluteFile.absolutePath
}
} }

View file

@ -1,4 +1,4 @@
package org.domaindrivenarchitecture.provs.server.domain.k3s package org.domaindrivenarchitecture.provs.configuration.domain
interface ConfigFileRepository { interface ConfigFileRepository {
fun assertExists(configFileName: ConfigFileName?) fun assertExists(configFileName: ConfigFileName?)

View file

@ -0,0 +1,14 @@
package org.domaindrivenarchitecture.provs.configuration.infrastructure
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.checkLocalFile
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileRepository
class DefaultConfigFileRepository : ConfigFileRepository {
override fun assertExists(configFileName: ConfigFileName?) {
if (configFileName != null && !checkLocalFile(configFileName.fullqualified())) {
throw RuntimeException("Application file ${configFileName.fileName} not found. Please check if path is correct.")
}
}
}

View file

@ -1,9 +0,0 @@
package org.domaindrivenarchitecture.provs.server.domain.k3s
import java.io.File
data class ConfigFileName(val fileName: String) {
fun fullqualified() : String {
return File(fileName).absoluteFile.absolutePath
}
}

View file

@ -1,5 +1,6 @@
package org.domaindrivenarchitecture.provs.server.domain.k3s package org.domaindrivenarchitecture.provs.server.domain.k3s
import org.domaindrivenarchitecture.provs.configuration.infrastructure.DefaultConfigFileRepository
import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.Prov
import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.GrafanaAgentConfigResolved import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.GrafanaAgentConfigResolved
import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.provisionGrafanaAgent import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.provisionGrafanaAgent
@ -14,6 +15,7 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
if (cli.onlyModules == null ) { if (cli.onlyModules == null ) {
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName) val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
DefaultApplicationFileRepository().assertExists(cli.applicationFileName) DefaultApplicationFileRepository().assertExists(cli.applicationFileName)
DefaultConfigFileRepository().assertExists(cli.configFileName)
if (cli.reprovision || k3sConfig.reprovision) { if (cli.reprovision || k3sConfig.reprovision) {
deprovisionK3sInfra() deprovisionK3sInfra()