[skip ci] Refactor submodule -> onlyModule

This commit is contained in:
erik 2022-09-09 13:56:21 +02:00
parent db84284f8c
commit ff4acea461
12 changed files with 45 additions and 50 deletions

View file

@ -6,7 +6,7 @@ import org.domaindrivenarchitecture.provs.configuration.application.CliTargetPar
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopCliCommand import org.domaindrivenarchitecture.provs.desktop.domain.DesktopCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopSubmodule import org.domaindrivenarchitecture.provs.desktop.domain.DesktopOnlyModule
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType
@ -30,14 +30,14 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
passwordInteractive passwordInteractive
), ),
module.configFileName, module.configFileName,
module.submodules module.onlyModules
) )
} }
abstract class DesktopSubcommand(name: String, description: String) : Subcommand(name, description) { abstract class DesktopSubcommand(name: String, description: String) : Subcommand(name, description) {
var parsed: Boolean = false var parsed: Boolean = false
var configFileName: ConfigFileName? = null var configFileName: ConfigFileName? = null
var submodules: List<String>? = null var onlyModules: List<String>? = null
val cliConfigFileName by option( val cliConfigFileName by option(
ArgType.String, ArgType.String,
@ -46,7 +46,7 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
"the filename containing the yaml config", "the filename containing the yaml config",
) )
val only by option( val only by option(
ArgType.Choice<DesktopSubmodule>(), ArgType.Choice<DesktopOnlyModule>(),
"only", "only",
"o", "o",
"provisions only parts ", "provisions only parts ",
@ -55,7 +55,7 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
override fun execute() { override fun execute() {
configFileName = cliConfigFileName?.let { ConfigFileName(it) } configFileName = cliConfigFileName?.let { ConfigFileName(it) }
parsed = true parsed = true
submodules = if (only != null) listOf(only!!.name.lowercase()) else null onlyModules = if (only != null) listOf(only!!.name.lowercase()) else null
} }
} }

View file

@ -8,7 +8,7 @@ class DesktopCliCommand(
val type: DesktopType, val type: DesktopType,
val target: TargetCliCommand, val target: TargetCliCommand,
val configFile: ConfigFileName?, val configFile: ConfigFileName?,
val submodules: List<String>? = null val onlyModules: List<String>? = null
) { ) {
fun isValid(): Boolean { fun isValid(): Boolean {
return target.isValid() return target.isValid()

View file

@ -1,5 +1,5 @@
package org.domaindrivenarchitecture.provs.desktop.domain package org.domaindrivenarchitecture.provs.desktop.domain
enum class DesktopSubmodule { enum class DesktopOnlyModule {
TEAMS, FIREFOX, VERIFY TEAMS, FIREFOX, VERIFY
} }

View file

@ -17,7 +17,7 @@ internal fun provisionDesktopCmd(prov: Prov, cmd: DesktopCliCommand) {
// retrieve config // retrieve config
val conf = if (cmd.configFile != null) getConfig(cmd.configFile.fileName) else DesktopConfig() val conf = if (cmd.configFile != null) getConfig(cmd.configFile.fileName) else DesktopConfig()
prov.provisionDesktop(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail, cmd.submodules) prov.provisionDesktop(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail, cmd.onlyModules)
} }
@ -35,18 +35,18 @@ internal fun Prov.provisionDesktop(
gpg: KeyPair? = null, gpg: KeyPair? = null,
gitUserName: String? = null, gitUserName: String? = null,
gitEmail: String? = null, gitEmail: String? = null,
submodules: List<String>? onlyModules: List<String>?
) = task { ) = task {
validatePrecondition() validatePrecondition()
provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail, submodules) provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail, onlyModules)
if (desktopType == DesktopType.OFFICE) { if (desktopType == DesktopType.OFFICE) {
provisionOfficeDesktop(submodules) provisionOfficeDesktop(onlyModules)
verifyOfficeSetup() verifyOfficeSetup()
} }
if (desktopType == DesktopType.IDE) { if (desktopType == DesktopType.IDE) {
provisionOfficeDesktop(submodules) provisionOfficeDesktop(onlyModules)
provisionIdeDesktop(submodules) provisionIdeDesktop(onlyModules)
verifyIdeSetup() verifyIdeSetup()
} }
ProvResult(true) ProvResult(true)
@ -58,8 +58,8 @@ fun Prov.validatePrecondition() {
} }
} }
fun Prov.provisionIdeDesktop(submodules: List<String>?) { fun Prov.provisionIdeDesktop(onlyModules: List<String>?) {
if (submodules == null) { if (onlyModules == null) {
aptInstall(OPEN_VPM) aptInstall(OPEN_VPM)
aptInstall(OPENCONNECT) aptInstall(OPENCONNECT)
aptInstall(VPNC) aptInstall(VPNC)
@ -75,24 +75,24 @@ fun Prov.provisionIdeDesktop(submodules: List<String>?) {
// IDEs // IDEs
installVSC("python", "clojure") installVSC("python", "clojure")
installIntelliJ() installIntelliJ()
} else if (submodules.contains(DesktopSubmodule.VERIFY.name.lowercase())) { } else if (onlyModules.contains(DesktopOnlyModule.VERIFY.name.lowercase())) {
verifyIdeSetup() verifyIdeSetup()
} else if (submodules.contains(DesktopSubmodule.FIREFOX.name.lowercase())) { } else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
installFirefox() installFirefox()
} }
} }
@Suppress("unused") @Suppress("unused")
fun Prov.provisionMSDesktop(submodules: List<String>?) { fun Prov.provisionMSDesktop(onlyModules: List<String>?) {
if (submodules == null) { if (onlyModules == null) {
installMsTeams() installMsTeams()
} else if (submodules.contains(DesktopSubmodule.TEAMS.name.lowercase())) { } else if (onlyModules.contains(DesktopOnlyModule.TEAMS.name.lowercase())) {
installMsTeams() installMsTeams()
} }
} }
fun Prov.provisionOfficeDesktop(submodules: List<String>?) { fun Prov.provisionOfficeDesktop(onlyModules: List<String>?) {
if (submodules == null) { if (onlyModules == null) {
aptInstall(ZIP_UTILS) aptInstall(ZIP_UTILS)
aptInstall(BROWSER) aptInstall(BROWSER)
aptInstall(EMAIL_CLIENT) aptInstall(EMAIL_CLIENT)
@ -106,9 +106,9 @@ fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
} }
aptInstall(SPELLCHECKING_DE) aptInstall(SPELLCHECKING_DE)
} else if (submodules.contains(DesktopSubmodule.VERIFY.name.lowercase())) { } else if (onlyModules.contains(DesktopOnlyModule.VERIFY.name.lowercase())) {
verifyOfficeSetup() verifyOfficeSetup()
} else if (submodules.contains(DesktopSubmodule.FIREFOX.name.lowercase())) { } else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
installFirefox() installFirefox()
} }
} }
@ -118,9 +118,9 @@ fun Prov.provisionBasicDesktop(
ssh: KeyPair?, ssh: KeyPair?,
gitUserName: String?, gitUserName: String?,
gitEmail: String?, gitEmail: String?,
submodules: List<String>? onlyModules: List<String>?
) { ) {
if (submodules == null) { if (onlyModules == null) {
aptInstall(KEY_MANAGEMENT) aptInstall(KEY_MANAGEMENT)
aptInstall(VERSION_MANAGEMENT) aptInstall(VERSION_MANAGEMENT)
aptInstall(NETWORK_TOOLS) aptInstall(NETWORK_TOOLS)
@ -147,7 +147,7 @@ fun Prov.provisionBasicDesktop(
configureNoSwappiness() configureNoSwappiness()
configureBash() configureBash()
installVirtualBoxGuestAdditions() installVirtualBoxGuestAdditions()
} else if (submodules.contains(DesktopSubmodule.FIREFOX.name.lowercase())) { } else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
installFirefox() installFirefox()
} }
} }

View file

@ -9,7 +9,7 @@ import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
import org.domaindrivenarchitecture.provs.server.domain.ServerType import org.domaindrivenarchitecture.provs.server.domain.ServerType
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
import org.domaindrivenarchitecture.provs.server.domain.k3s.ServerSubmodule import org.domaindrivenarchitecture.provs.server.domain.k3s.ServerOnlyModule
class CliArgumentsParser(name: String) : CliTargetParser(name) { class CliArgumentsParser(name: String) : CliTargetParser(name) {
@ -34,7 +34,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
), ),
module.configFileName, module.configFileName,
module.applicationFileName, module.applicationFileName,
module.submodules, module.onlyModules,
module.reprovision, module.reprovision,
) )
else -> return ServerCliCommand( else -> return ServerCliCommand(
@ -52,7 +52,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
var parsed: Boolean = false var parsed: Boolean = false
var configFileName: ConfigFileName? = null var configFileName: ConfigFileName? = null
var applicationFileName: ApplicationFileName? = null var applicationFileName: ApplicationFileName? = null
var submodules: List<String>? = null var onlyModules: List<String>? = null
var reprovision: Boolean = false var reprovision: Boolean = false
} }
@ -70,7 +70,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
"the filename containing the yaml a application deployment" "the filename containing the yaml a application deployment"
) )
val only by option( val only by option(
ArgType.Choice<ServerSubmodule>(), ArgType.Choice<ServerOnlyModule>(),
"only", "only",
"o", "o",
"provisions only parts ", "provisions only parts ",
@ -84,7 +84,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
override fun execute() { override fun execute() {
super.configFileName = cliConfigFileName?.let { ConfigFileName(it) } super.configFileName = cliConfigFileName?.let { ConfigFileName(it) }
super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) } super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) }
super.submodules = if (only != null) listOf(only!!.name.lowercase()) else null super.onlyModules = if (only != null) listOf(only!!.name.lowercase()) else null
super.reprovision = cliReprovision == true super.reprovision = cliReprovision == true
super.parsed = true super.parsed = true
} }

View file

@ -12,9 +12,7 @@ open class ServerCliCommand(
val target: TargetCliCommand, val target: TargetCliCommand,
val configFileName: ConfigFileName?,) val configFileName: ConfigFileName?,)
{ {
fun isValidServerType(): Boolean {
return serverType == ServerType.K3S
}
fun isValidTarget(): Boolean { fun isValidTarget(): Boolean {
return target.isValid() return target.isValid()
} }

View file

@ -10,7 +10,7 @@ class K3sCliCommand(
target: TargetCliCommand, target: TargetCliCommand,
configFileName: ConfigFileName?, configFileName: ConfigFileName?,
val applicationFileName: ApplicationFileName?, val applicationFileName: ApplicationFileName?,
val submodules: List<String>? = null, val onlyModules: List<String>? = null,
val reprovision: Reprovision = false, val reprovision: Reprovision = false,
) : ) :
ServerCliCommand( ServerCliCommand(

View file

@ -11,7 +11,7 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret() val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
if (cli.submodules == 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)
@ -20,7 +20,7 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
} }
provisionK3s(k3sConfig, grafanaConfigResolved, cli.applicationFileName) provisionK3s(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
} else { } else {
provisionGrafana(cli.submodules, grafanaConfigResolved) provisionGrafana(cli.onlyModules, grafanaConfigResolved)
} }
} }
@ -56,10 +56,10 @@ fun Prov.provisionK3s(
} }
private fun Prov.provisionGrafana( private fun Prov.provisionGrafana(
submodules: List<String>?, onlyModules: List<String>?,
grafanaConfigResolved: GrafanaAgentConfigResolved?) = task { grafanaConfigResolved: GrafanaAgentConfigResolved?) = task {
if (submodules != null && submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) { if (onlyModules != null && onlyModules.contains(ServerOnlyModule.GRAFANA.name.lowercase())) {
if (grafanaConfigResolved == null) { if (grafanaConfigResolved == null) {
println("ERROR: Could not find grafana config.") println("ERROR: Could not find grafana config.")
exitProcess(7) exitProcess(7)

View file

@ -1,5 +1,5 @@
package org.domaindrivenarchitecture.provs.server.domain.k3s package org.domaindrivenarchitecture.provs.server.domain.k3s
enum class ServerSubmodule { enum class ServerOnlyModule {
GRAFANA GRAFANA
} }

View file

@ -16,11 +16,11 @@ internal class CliArgumentsParserTest {
} }
@Test @Test
fun parse_cliCommand_with_only_submodule_teams_and_local_target() { fun parse_cliCommand_with_onlyModule_teams_and_local_target() {
val cli = CliArgumentsParser("test").parseCommand(args = arrayOf("ide", "local", "-o", "teams")) val cli = CliArgumentsParser("test").parseCommand(args = arrayOf("ide", "local", "-o", "teams"))
assertTrue(cli.isValid()) assertTrue(cli.isValid())
assertEquals(true, cli.target.isValidLocalhost()) assertEquals(true, cli.target.isValidLocalhost())
assertEquals(true, cli.submodules?.contains("teams")) assertEquals(true, cli.onlyModules?.contains("teams"))
} }
} }

View file

@ -21,7 +21,7 @@ internal class DesktopServiceKtTest {
DesktopType.BASIC, DesktopType.BASIC,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
submodules = null onlyModules = null
) )
// then // then
@ -46,7 +46,7 @@ internal class DesktopServiceKtTest {
DesktopType.IDE, DesktopType.IDE,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
submodules = null onlyModules = null
) )
// then // then
@ -68,7 +68,7 @@ internal class DesktopServiceKtTest {
config.gpg?.keyPair(), config.gpg?.keyPair(),
config.gitUserName, config.gitUserName,
config.gitEmail, config.gitEmail,
submodules = null onlyModules = null
) )
// then // then

View file

@ -18,7 +18,6 @@ internal class CliArgumentParserTest {
val result = parser.parseCommand(args = arrayOf("k3s", "local", "-c", "config.yaml")) val result = parser.parseCommand(args = arrayOf("k3s", "local", "-c", "config.yaml"))
// then // then
assertTrue(result.isValidServerType())
assertTrue(result.isValidTarget()) assertTrue(result.isValidTarget())
} }
@ -31,9 +30,8 @@ internal class CliArgumentParserTest {
val result: K3sCliCommand = parser.parseCommand(args = arrayOf("k3s", "local", "-o", "grafana")) as K3sCliCommand val result: K3sCliCommand = parser.parseCommand(args = arrayOf("k3s", "local", "-o", "grafana")) as K3sCliCommand
// then // then
assertTrue(result.isValidServerType())
assertTrue(result.isValidTarget()) assertTrue(result.isValidTarget())
assertEquals(listOf("grafana"), result.submodules) assertEquals(listOf("grafana"), result.onlyModules)
assertEquals(TargetCliCommand("local"), result.target) assertEquals(TargetCliCommand("local"), result.target)
} }
@ -47,7 +45,6 @@ internal class CliArgumentParserTest {
// then // then
assertTrue(result.isValidTarget()) assertTrue(result.isValidTarget())
assertTrue(result.isValidServerType())
assertEquals(ApplicationFileName("app.yaml"), result.applicationFileName) assertEquals(ApplicationFileName("app.yaml"), result.applicationFileName)
assertEquals(TargetCliCommand("user@host.com"), result.target) assertEquals(TargetCliCommand("user@host.com"), result.target)
} }