[skip ci] Refactor submodule -> onlyModule
This commit is contained in:
parent
db84284f8c
commit
ff4acea461
12 changed files with 45 additions and 50 deletions
|
@ -6,7 +6,7 @@ import org.domaindrivenarchitecture.provs.configuration.application.CliTargetPar
|
|||
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||||
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
|
||||
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
|
||||
|
||||
|
||||
|
@ -30,14 +30,14 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
passwordInteractive
|
||||
),
|
||||
module.configFileName,
|
||||
module.submodules
|
||||
module.onlyModules
|
||||
)
|
||||
}
|
||||
|
||||
abstract class DesktopSubcommand(name: String, description: String) : Subcommand(name, description) {
|
||||
var parsed: Boolean = false
|
||||
var configFileName: ConfigFileName? = null
|
||||
var submodules: List<String>? = null
|
||||
var onlyModules: List<String>? = null
|
||||
|
||||
val cliConfigFileName by option(
|
||||
ArgType.String,
|
||||
|
@ -46,7 +46,7 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
"the filename containing the yaml config",
|
||||
)
|
||||
val only by option(
|
||||
ArgType.Choice<DesktopSubmodule>(),
|
||||
ArgType.Choice<DesktopOnlyModule>(),
|
||||
"only",
|
||||
"o",
|
||||
"provisions only parts ",
|
||||
|
@ -55,7 +55,7 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
override fun execute() {
|
||||
configFileName = cliConfigFileName?.let { ConfigFileName(it) }
|
||||
parsed = true
|
||||
submodules = if (only != null) listOf(only!!.name.lowercase()) else null
|
||||
onlyModules = if (only != null) listOf(only!!.name.lowercase()) else null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class DesktopCliCommand(
|
|||
val type: DesktopType,
|
||||
val target: TargetCliCommand,
|
||||
val configFile: ConfigFileName?,
|
||||
val submodules: List<String>? = null
|
||||
val onlyModules: List<String>? = null
|
||||
) {
|
||||
fun isValid(): Boolean {
|
||||
return target.isValid()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package org.domaindrivenarchitecture.provs.desktop.domain
|
||||
|
||||
enum class DesktopSubmodule {
|
||||
enum class DesktopOnlyModule {
|
||||
TEAMS, FIREFOX, VERIFY
|
||||
}
|
|
@ -17,7 +17,7 @@ internal fun provisionDesktopCmd(prov: Prov, cmd: DesktopCliCommand) {
|
|||
// retrieve config
|
||||
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,
|
||||
gitUserName: String? = null,
|
||||
gitEmail: String? = null,
|
||||
submodules: List<String>?
|
||||
onlyModules: List<String>?
|
||||
) = task {
|
||||
validatePrecondition()
|
||||
provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail, submodules)
|
||||
provisionBasicDesktop(gpg, ssh, gitUserName, gitEmail, onlyModules)
|
||||
|
||||
if (desktopType == DesktopType.OFFICE) {
|
||||
provisionOfficeDesktop(submodules)
|
||||
provisionOfficeDesktop(onlyModules)
|
||||
verifyOfficeSetup()
|
||||
}
|
||||
if (desktopType == DesktopType.IDE) {
|
||||
provisionOfficeDesktop(submodules)
|
||||
provisionIdeDesktop(submodules)
|
||||
provisionOfficeDesktop(onlyModules)
|
||||
provisionIdeDesktop(onlyModules)
|
||||
verifyIdeSetup()
|
||||
}
|
||||
ProvResult(true)
|
||||
|
@ -58,8 +58,8 @@ fun Prov.validatePrecondition() {
|
|||
}
|
||||
}
|
||||
|
||||
fun Prov.provisionIdeDesktop(submodules: List<String>?) {
|
||||
if (submodules == null) {
|
||||
fun Prov.provisionIdeDesktop(onlyModules: List<String>?) {
|
||||
if (onlyModules == null) {
|
||||
aptInstall(OPEN_VPM)
|
||||
aptInstall(OPENCONNECT)
|
||||
aptInstall(VPNC)
|
||||
|
@ -75,24 +75,24 @@ fun Prov.provisionIdeDesktop(submodules: List<String>?) {
|
|||
// IDEs
|
||||
installVSC("python", "clojure")
|
||||
installIntelliJ()
|
||||
} else if (submodules.contains(DesktopSubmodule.VERIFY.name.lowercase())) {
|
||||
} else if (onlyModules.contains(DesktopOnlyModule.VERIFY.name.lowercase())) {
|
||||
verifyIdeSetup()
|
||||
} else if (submodules.contains(DesktopSubmodule.FIREFOX.name.lowercase())) {
|
||||
} else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
|
||||
installFirefox()
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun Prov.provisionMSDesktop(submodules: List<String>?) {
|
||||
if (submodules == null) {
|
||||
fun Prov.provisionMSDesktop(onlyModules: List<String>?) {
|
||||
if (onlyModules == null) {
|
||||
installMsTeams()
|
||||
} else if (submodules.contains(DesktopSubmodule.TEAMS.name.lowercase())) {
|
||||
} else if (onlyModules.contains(DesktopOnlyModule.TEAMS.name.lowercase())) {
|
||||
installMsTeams()
|
||||
}
|
||||
}
|
||||
|
||||
fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
|
||||
if (submodules == null) {
|
||||
fun Prov.provisionOfficeDesktop(onlyModules: List<String>?) {
|
||||
if (onlyModules == null) {
|
||||
aptInstall(ZIP_UTILS)
|
||||
aptInstall(BROWSER)
|
||||
aptInstall(EMAIL_CLIENT)
|
||||
|
@ -106,9 +106,9 @@ fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
|
|||
}
|
||||
|
||||
aptInstall(SPELLCHECKING_DE)
|
||||
} else if (submodules.contains(DesktopSubmodule.VERIFY.name.lowercase())) {
|
||||
} else if (onlyModules.contains(DesktopOnlyModule.VERIFY.name.lowercase())) {
|
||||
verifyOfficeSetup()
|
||||
} else if (submodules.contains(DesktopSubmodule.FIREFOX.name.lowercase())) {
|
||||
} else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
|
||||
installFirefox()
|
||||
}
|
||||
}
|
||||
|
@ -118,9 +118,9 @@ fun Prov.provisionBasicDesktop(
|
|||
ssh: KeyPair?,
|
||||
gitUserName: String?,
|
||||
gitEmail: String?,
|
||||
submodules: List<String>?
|
||||
onlyModules: List<String>?
|
||||
) {
|
||||
if (submodules == null) {
|
||||
if (onlyModules == null) {
|
||||
aptInstall(KEY_MANAGEMENT)
|
||||
aptInstall(VERSION_MANAGEMENT)
|
||||
aptInstall(NETWORK_TOOLS)
|
||||
|
@ -147,7 +147,7 @@ fun Prov.provisionBasicDesktop(
|
|||
configureNoSwappiness()
|
||||
configureBash()
|
||||
installVirtualBoxGuestAdditions()
|
||||
} else if (submodules.contains(DesktopSubmodule.FIREFOX.name.lowercase())) {
|
||||
} else if (onlyModules.contains(DesktopOnlyModule.FIREFOX.name.lowercase())) {
|
||||
installFirefox()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
|
|||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||
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) {
|
||||
|
||||
|
@ -34,7 +34,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
),
|
||||
module.configFileName,
|
||||
module.applicationFileName,
|
||||
module.submodules,
|
||||
module.onlyModules,
|
||||
module.reprovision,
|
||||
)
|
||||
else -> return ServerCliCommand(
|
||||
|
@ -52,7 +52,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
var parsed: Boolean = false
|
||||
var configFileName: ConfigFileName? = null
|
||||
var applicationFileName: ApplicationFileName? = null
|
||||
var submodules: List<String>? = null
|
||||
var onlyModules: List<String>? = null
|
||||
var reprovision: Boolean = false
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
"the filename containing the yaml a application deployment"
|
||||
)
|
||||
val only by option(
|
||||
ArgType.Choice<ServerSubmodule>(),
|
||||
ArgType.Choice<ServerOnlyModule>(),
|
||||
"only",
|
||||
"o",
|
||||
"provisions only parts ",
|
||||
|
@ -84,7 +84,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
override fun execute() {
|
||||
super.configFileName = cliConfigFileName?.let { ConfigFileName(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.parsed = true
|
||||
}
|
||||
|
|
|
@ -12,9 +12,7 @@ open class ServerCliCommand(
|
|||
val target: TargetCliCommand,
|
||||
val configFileName: ConfigFileName?,)
|
||||
{
|
||||
fun isValidServerType(): Boolean {
|
||||
return serverType == ServerType.K3S
|
||||
}
|
||||
|
||||
fun isValidTarget(): Boolean {
|
||||
return target.isValid()
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ class K3sCliCommand(
|
|||
target: TargetCliCommand,
|
||||
configFileName: ConfigFileName?,
|
||||
val applicationFileName: ApplicationFileName?,
|
||||
val submodules: List<String>? = null,
|
||||
val onlyModules: List<String>? = null,
|
||||
val reprovision: Reprovision = false,
|
||||
) :
|
||||
ServerCliCommand(
|
||||
|
|
|
@ -11,7 +11,7 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
|
|||
|
||||
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
|
||||
|
||||
if (cli.submodules == null ) {
|
||||
if (cli.onlyModules == null ) {
|
||||
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
||||
DefaultApplicationFileRepository().assertExists(cli.applicationFileName)
|
||||
|
||||
|
@ -20,7 +20,7 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
|
|||
}
|
||||
provisionK3s(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
|
||||
} else {
|
||||
provisionGrafana(cli.submodules, grafanaConfigResolved)
|
||||
provisionGrafana(cli.onlyModules, grafanaConfigResolved)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,10 +56,10 @@ fun Prov.provisionK3s(
|
|||
}
|
||||
|
||||
private fun Prov.provisionGrafana(
|
||||
submodules: List<String>?,
|
||||
onlyModules: List<String>?,
|
||||
grafanaConfigResolved: GrafanaAgentConfigResolved?) = task {
|
||||
|
||||
if (submodules != null && submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) {
|
||||
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.GRAFANA.name.lowercase())) {
|
||||
if (grafanaConfigResolved == null) {
|
||||
println("ERROR: Could not find grafana config.")
|
||||
exitProcess(7)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||
|
||||
enum class ServerSubmodule {
|
||||
enum class ServerOnlyModule {
|
||||
GRAFANA
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ internal class CliArgumentsParserTest {
|
|||
}
|
||||
|
||||
@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"))
|
||||
|
||||
assertTrue(cli.isValid())
|
||||
assertEquals(true, cli.target.isValidLocalhost())
|
||||
assertEquals(true, cli.submodules?.contains("teams"))
|
||||
assertEquals(true, cli.onlyModules?.contains("teams"))
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ internal class DesktopServiceKtTest {
|
|||
DesktopType.BASIC,
|
||||
gitUserName = "testuser",
|
||||
gitEmail = "testuser@test.org",
|
||||
submodules = null
|
||||
onlyModules = null
|
||||
)
|
||||
|
||||
// then
|
||||
|
@ -46,7 +46,7 @@ internal class DesktopServiceKtTest {
|
|||
DesktopType.IDE,
|
||||
gitUserName = "testuser",
|
||||
gitEmail = "testuser@test.org",
|
||||
submodules = null
|
||||
onlyModules = null
|
||||
)
|
||||
|
||||
// then
|
||||
|
@ -68,7 +68,7 @@ internal class DesktopServiceKtTest {
|
|||
config.gpg?.keyPair(),
|
||||
config.gitUserName,
|
||||
config.gitEmail,
|
||||
submodules = null
|
||||
onlyModules = null
|
||||
)
|
||||
|
||||
// then
|
||||
|
|
|
@ -18,7 +18,6 @@ internal class CliArgumentParserTest {
|
|||
val result = parser.parseCommand(args = arrayOf("k3s", "local", "-c", "config.yaml"))
|
||||
|
||||
// then
|
||||
assertTrue(result.isValidServerType())
|
||||
assertTrue(result.isValidTarget())
|
||||
}
|
||||
|
||||
|
@ -31,9 +30,8 @@ internal class CliArgumentParserTest {
|
|||
val result: K3sCliCommand = parser.parseCommand(args = arrayOf("k3s", "local", "-o", "grafana")) as K3sCliCommand
|
||||
|
||||
// then
|
||||
assertTrue(result.isValidServerType())
|
||||
assertTrue(result.isValidTarget())
|
||||
assertEquals(listOf("grafana"), result.submodules)
|
||||
assertEquals(listOf("grafana"), result.onlyModules)
|
||||
assertEquals(TargetCliCommand("local"), result.target)
|
||||
}
|
||||
|
||||
|
@ -47,7 +45,6 @@ internal class CliArgumentParserTest {
|
|||
|
||||
// then
|
||||
assertTrue(result.isValidTarget())
|
||||
assertTrue(result.isValidServerType())
|
||||
assertEquals(ApplicationFileName("app.yaml"), result.applicationFileName)
|
||||
assertEquals(TargetCliCommand("user@host.com"), result.target)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue