refactrored desktop mappings

This commit is contained in:
jerger 2022-07-05 20:16:29 +02:00
parent b265824b63
commit a608382a58

View file

@ -15,15 +15,11 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami
fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) { fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
val submodules = cmd.submodules
// 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()
if (submodules == null) { prov.provisionDesktopImpl(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)
} else {
prov.provisionDesktopSubmodules(submodules)
}
} }
@ -35,36 +31,38 @@ fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
* *
* Prerequisites: user must be able to sudo without entering the password * Prerequisites: user must be able to sudo without entering the password
*/ */
fun Prov.provisionDesktop( fun Prov.provisionDesktopImpl(
desktopType: DesktopType = DesktopType.BASIC, desktopType: DesktopType = DesktopType.BASIC,
ssh: KeyPair? = null, ssh: KeyPair? = null,
gpg: KeyPair? = null, gpg: KeyPair? = null,
gitUserName: String? = null, gitUserName: String? = null,
gitEmail: String? = null, gitEmail: String? = null,
submodules: List<String>?
) = task { ) = task {
// TODO: jem - 2022-06-30: why?? We got already a typed var! // TODO: jem - 2022-06-30: why?? We got already a typed var!
DesktopType.valueOf(desktopType.name) // throws exception when desktopType.name is unknown DesktopType.valueOf(desktopType.name) // throws exception when desktopType.name is unknown
validatePrecondition() validatePrecondition()
provisionBaseDesktop(gpg, ssh, gitUserName, gitEmail) provisionBaseDesktop(gpg, ssh, gitUserName, gitEmail, submodules)
if (desktopType == DesktopType.OFFICE || desktopType == DesktopType.IDE) { if (desktopType == DesktopType.OFFICE || desktopType == DesktopType.IDE) {
provisionOfficeDesktop() provisionOfficeDesktop(submodules)
} }
if (desktopType == DesktopType.IDE) { if (desktopType == DesktopType.IDE) {
provisionIdeDesktop() provisionIdeDesktop(submodules)
} }
ProvResult(true) ProvResult(true)
} }
private fun Prov.validatePrecondition() { fun Prov.validatePrecondition() {
if (!currentUserCanSudo()) { if (!currentUserCanSudo()) {
throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionDesktop") throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionDesktop")
} }
} }
private fun Prov.provisionIdeDesktop() { fun Prov.provisionIdeDesktop(submodules: List<String>?) {
if (submodules != null) {
aptInstall(JAVA) aptInstall(JAVA)
aptInstall(OPEN_VPM) aptInstall(OPEN_VPM)
aptInstall(OPENCONNECT) aptInstall(OPENCONNECT)
@ -79,8 +77,17 @@ private fun Prov.provisionIdeDesktop() {
installDevOps() installDevOps()
provisionPython() provisionPython()
} }
}
private fun Prov.provisionOfficeDesktop() { fun Prov.provisionMSDesktop(submodules: List<String>?) {
if (submodules?.contains(DesktopSubmodule.TEAMS.name.lowercase()) == true) {
installMsTeams()
} else {
}
}
fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
if (submodules != null) {
aptInstall(ZIP_UTILS) aptInstall(ZIP_UTILS)
aptInstall(BROWSER) aptInstall(BROWSER)
aptInstall(EMAIL_CLIENT) aptInstall(EMAIL_CLIENT)
@ -97,13 +104,16 @@ private fun Prov.provisionOfficeDesktop() {
aptInstall(SPELLCHECKING_DE) aptInstall(SPELLCHECKING_DE)
} }
}
private fun Prov.provisionBaseDesktop( private fun Prov.provisionBaseDesktop(
gpg: KeyPair?, gpg: KeyPair?,
ssh: KeyPair?, ssh: KeyPair?,
gitUserName: String?, gitUserName: String?,
gitEmail: String? gitEmail: String?,
submodules: List<String>?
) { ) {
if (submodules != null) {
aptInstall(KEY_MANAGEMENT) aptInstall(KEY_MANAGEMENT)
aptInstall(VERSION_MANAGEMENT) aptInstall(VERSION_MANAGEMENT)
aptInstall(NETWORK_TOOLS) aptInstall(NETWORK_TOOLS)
@ -130,12 +140,4 @@ private fun Prov.provisionBaseDesktop(
configureNoSwappiness() configureNoSwappiness()
configureBash() configureBash()
} }
private fun Prov.provisionDesktopSubmodules(
submodules: List<String>,
) = task {
if (submodules.contains(DesktopSubmodule.TEAMS.name.lowercase())) {
installMsTeams()
}
} }