diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliTargetParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/application/CliTargetParser.kt similarity index 67% rename from src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliTargetParser.kt rename to src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/application/CliTargetParser.kt index 11f4745..deab71c 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliTargetParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/application/CliTargetParser.kt @@ -1,8 +1,9 @@ -package org.domaindrivenarchitecture.provs.framework.core.cli +package org.domaindrivenarchitecture.provs.configuration.application import kotlinx.cli.ArgParser import kotlinx.cli.ArgType import kotlinx.cli.default +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand open class CliTargetParser(name: String) : ArgParser(name) { val remoteHost by option( @@ -34,3 +35,20 @@ open class CliTargetParser(name: String) : ArgParser(name) { description = "provision over ssh using user & ssh key" ).default(false) } + +fun parseTarget( + programName: String = "java -jar provs.jar", + args: Array +): TargetCliCommand { + val parser = CliTargetParser(programName) + parser.parse(args) + + return TargetCliCommand( + parser.localHost, + parser.remoteHost, + parser.userName, + parser.sshWithPasswordPrompt, + parser.sshWithGopassPath, + parser.sshWithKey + ) +} \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliTargetCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/domain/CliTargetCommand.kt similarity index 63% rename from src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliTargetCommand.kt rename to src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/domain/CliTargetCommand.kt index 44d3a31..815657e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliTargetCommand.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/domain/CliTargetCommand.kt @@ -1,4 +1,4 @@ -package org.domaindrivenarchitecture.provs.framework.core.cli +package org.domaindrivenarchitecture.provs.configuration.domain class TargetCliCommand( @@ -27,19 +27,3 @@ class TargetCliCommand( } } -fun parseTarget( - programName: String = "java -jar provs.jar", - args: Array -): TargetCliCommand { - val parser = CliTargetParser(programName) - parser.parse(args) - - return TargetCliCommand( - parser.localHost, - parser.remoteHost, - parser.userName, - parser.sshWithPasswordPrompt, - parser.sshWithGopassPath, - parser.sshWithKey - ) -} diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/domain/ConfigFileName.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/domain/ConfigFileName.kt new file mode 100644 index 0000000..33f06f6 --- /dev/null +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/domain/ConfigFileName.kt @@ -0,0 +1,3 @@ +package org.domaindrivenarchitecture.provs.configuration.domain + +data class ConfigFileName(val fileName: String) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt index 6ee5028..9f04326 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt @@ -1,9 +1,9 @@ package org.domaindrivenarchitecture.provs.desktop.application import kotlinx.cli.ArgType -import kotlinx.cli.optional -import org.domaindrivenarchitecture.provs.framework.core.cli.CliTargetParser -import org.domaindrivenarchitecture.provs.framework.core.cli.TargetCliCommand +import org.domaindrivenarchitecture.provs.configuration.application.CliTargetParser +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand open class CliArgumentsParser(name: String) : CliTargetParser(name) { @@ -11,15 +11,15 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) { val configFileName by argument( ArgType.String, "configFilename", - "the filename containing the yaml config for the workplace" - ).optional() + "the filename containing the yaml config for the desktop" + ) fun parseWorkplaceArguments(args: Array): DesktopCliCommand { super.parse(args) return DesktopCliCommand( - configFileName ?: "WorkplaceConfig.yaml", + ConfigFileName(configFileName), TargetCliCommand( localHost, remoteHost, diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/CliWorkplaceCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/CliWorkplaceCommand.kt index 16ccea3..f3d706f 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/CliWorkplaceCommand.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/CliWorkplaceCommand.kt @@ -1,12 +1,13 @@ package org.domaindrivenarchitecture.provs.desktop.application -import org.domaindrivenarchitecture.provs.framework.core.cli.TargetCliCommand +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand -class DesktopCliCommand(val configFile: String, val target: TargetCliCommand) { +class DesktopCliCommand(val configFile: ConfigFileName, val target: TargetCliCommand) { fun isValid(): Boolean { - return configFile.isNotEmpty() && target.isValid() + return configFile.fileName.isNotEmpty() && target.isValid() } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt index 65df9f6..d408f26 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt @@ -17,7 +17,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) { // retrieve config - val conf = getConfig(cmd.configFile) + val conf = getConfig(cmd.configFile.fileName) with (conf) { prov.provisionWorkplace(type, ssh?.keyPair(), gpg?.keyPair(), gitUserName, gitEmail) } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt index ccad647..38372fe 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt @@ -1,5 +1,6 @@ package org.domaindrivenarchitecture.provs.framework.core.cli +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.Secret import org.domaindrivenarchitecture.provs.framework.core.local diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt index 1102ca6..3ec6570 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt @@ -2,9 +2,9 @@ package org.domaindrivenarchitecture.provs.server.application import kotlinx.cli.ArgType import kotlinx.cli.Subcommand -import org.domaindrivenarchitecture.provs.framework.core.cli.CliTargetParser -import org.domaindrivenarchitecture.provs.framework.core.cli.TargetCliCommand -import org.domaindrivenarchitecture.provs.server.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.application.CliTargetParser +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand import org.domaindrivenarchitecture.provs.server.domain.ServerType diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ConfigFileName.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ConfigFileName.kt deleted file mode 100644 index a581807..0000000 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ConfigFileName.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.domaindrivenarchitecture.provs.server.domain - -data class ConfigFileName(val fileName: String) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt index 339096a..8463c70 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/ServerCliCommand.kt @@ -1,6 +1,7 @@ package org.domaindrivenarchitecture.provs.server.domain -import org.domaindrivenarchitecture.provs.framework.core.cli.TargetCliCommand +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand enum class ServerType { K3D, K3S diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index c250493..f9de730 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -1,7 +1,7 @@ package org.domaindrivenarchitecture.provs.server.domain.k3s import org.domaindrivenarchitecture.provs.framework.core.Prov -import org.domaindrivenarchitecture.provs.server.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName import org.domaindrivenarchitecture.provs.server.infrastructure.* import org.domaindrivenarchitecture.provs.server.infrastructure.k3s.getK3sConfig diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepository.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepository.kt index 6c50899..3f2b96b 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepository.kt @@ -2,7 +2,7 @@ package org.domaindrivenarchitecture.provs.server.infrastructure.k3s import com.charleskorn.kaml.Yaml import kotlinx.serialization.json.Json -import org.domaindrivenarchitecture.provs.server.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName import org.domaindrivenarchitecture.provs.server.domain.k3s.* import java.io.BufferedReader import java.io.FileReader diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/TargetCliCommandTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/cofiguration/application/CliTargetParserTest.kt similarity index 91% rename from src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/TargetCliCommandTest.kt rename to src/test/kotlin/org/domaindrivenarchitecture/provs/cofiguration/application/CliTargetParserTest.kt index 1c79e12..7cb1b94 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/TargetCliCommandTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/cofiguration/application/CliTargetParserTest.kt @@ -1,10 +1,10 @@ -package org.domaindrivenarchitecture.provs.framework.core.cli +package org.domaindrivenarchitecture.provs.cofiguration.application -import org.domaindrivenarchitecture.provs.framework.core.cli.parseTarget +import org.domaindrivenarchitecture.provs.configuration.application.parseTarget import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test -internal class TargetCliCommandTest { +internal class CliTargetParserTest { @Test fun parse_localhost_with_default() { diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliCommandKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/cofiguration/domain/CliTargetCommandTest.kt similarity index 90% rename from src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliCommandKtTest.kt rename to src/test/kotlin/org/domaindrivenarchitecture/provs/cofiguration/domain/CliTargetCommandTest.kt index 845551f..ce02da9 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliCommandKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/cofiguration/domain/CliTargetCommandTest.kt @@ -4,13 +4,11 @@ import io.mockk.every import io.mockk.mockkStatic import io.mockk.unmockkStatic import io.mockk.verify +import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.Secret import org.domaindrivenarchitecture.provs.framework.core.local import org.domaindrivenarchitecture.provs.framework.core.processors.PrintOnlyProcessor -import org.domaindrivenarchitecture.provs.framework.core.cli.TargetCliCommand -import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance -import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword import org.domaindrivenarchitecture.provs.framework.core.remote import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.BeforeAll diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliWorkplaceKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliWorkplaceKtTest.kt index f3b5bbb..536e8b3 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliWorkplaceKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliWorkplaceKtTest.kt @@ -116,7 +116,7 @@ internal class CliWorkplaceKtTest { System.setOut(originalOut) System.setErr(originalErr) - val expectedOutput = "Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m WorkplaceConfigExample.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs." + val expectedOutput = "Error: File\u001B[31m ConfigFileName(fileName=idontexist.yaml) \u001B[0m was not found.Pls copy file \u001B[31m WorkplaceConfigExample.yaml \u001B[0m to file \u001B[31m ConfigFileName(fileName=idontexist.yaml) \u001B[0m and change the content according to your needs." assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) verify(exactly = 0) { any().provisionWorkplace(any()) } @@ -142,7 +142,7 @@ internal class CliWorkplaceKtTest { System.setOut(originalOut) System.setErr(originalErr) - val expectedOutput = "Error: File \"src/test/resources/InvalidWorkplaceConfig.yaml\" has an invalid format and or invalid data." + val expectedOutput = "Error: File \"ConfigFileName(fileName=src/test/resources/InvalidWorkplaceConfig.yaml)\" has an invalid format and or invalid data." assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) verify(exactly = 0) { any().provisionWorkplace(any()) } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt index 5bd4993..6f7b2ce 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/k3s/ConfigRepositoryTest.kt @@ -1,8 +1,7 @@ package org.domaindrivenarchitecture.provs.server.infrastructure.k3s -import com.charleskorn.kaml.InvalidPropertyValueException import com.charleskorn.kaml.UnknownPropertyException -import org.domaindrivenarchitecture.provs.server.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName import org.domaindrivenarchitecture.provs.server.domain.k3s.* import org.domaindrivenarchitecture.provs.server.infrastructure.CertManagerEndPoint import org.junit.jupiter.api.Assertions.assertEquals