create common kernel

This commit is contained in:
jem 2022-02-03 09:24:46 +01:00
parent 03cf8ee3ce
commit 718bc99d55
16 changed files with 49 additions and 47 deletions

View file

@ -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<String>
): TargetCliCommand {
val parser = CliTargetParser(programName)
parser.parse(args)
return TargetCliCommand(
parser.localHost,
parser.remoteHost,
parser.userName,
parser.sshWithPasswordPrompt,
parser.sshWithGopassPath,
parser.sshWithKey
)
}

View file

@ -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<String>
): TargetCliCommand {
val parser = CliTargetParser(programName)
parser.parse(args)
return TargetCliCommand(
parser.localHost,
parser.remoteHost,
parser.userName,
parser.sshWithPasswordPrompt,
parser.sshWithGopassPath,
parser.sshWithKey
)
}

View file

@ -0,0 +1,3 @@
package org.domaindrivenarchitecture.provs.configuration.domain
data class ConfigFileName(val fileName: String)

View file

@ -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<String>): DesktopCliCommand {
super.parse(args)
return DesktopCliCommand(
configFileName ?: "WorkplaceConfig.yaml",
ConfigFileName(configFileName),
TargetCliCommand(
localHost,
remoteHost,

View file

@ -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()
}
}

View file

@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -1,3 +0,0 @@
package org.domaindrivenarchitecture.provs.server.domain
data class ConfigFileName(val fileName: String)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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() {

View file

@ -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

View file

@ -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<Prov>().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<Prov>().provisionWorkplace(any()) }

View file

@ -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