rename & minor refactoring

This commit is contained in:
jerger 2022-07-18 09:29:25 +02:00
parent eca4489618
commit 21f22916b2
4 changed files with 30 additions and 53 deletions

View file

@ -1,7 +1,7 @@
package org.domaindrivenarchitecture.provs.desktop.application package org.domaindrivenarchitecture.provs.desktop.application
import kotlinx.serialization.SerializationException import kotlinx.serialization.SerializationException
import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktop import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktopCmd
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
import java.io.FileNotFoundException import java.io.FileNotFoundException
import kotlin.system.exitProcess import kotlin.system.exitProcess
@ -20,7 +20,7 @@ fun main(args: Array<String>) {
val prov = createProvInstance(cmd.target, remoteHostSetSudoWithoutPasswordRequired = true) val prov = createProvInstance(cmd.target, remoteHostSetSudoWithoutPasswordRequired = true)
try { try {
provisionDesktop(prov, cmd) provisionDesktopCmd(prov, cmd)
} catch (e: SerializationException) { } catch (e: SerializationException) {
println( println(
"Error: File \"${cmd.configFile?.fileName}\" has an invalid format and or invalid data.\n" "Error: File \"${cmd.configFile?.fileName}\" has an invalid format and or invalid data.\n"

View file

@ -13,13 +13,12 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.provisionKeys
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.currentUserCanSudo import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.currentUserCanSudo
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami
internal fun provisionDesktopCmd(prov: Prov, cmd: DesktopCliCommand) {
fun provisionDesktop(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.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, cmd.submodules)
} }
@ -31,7 +30,7 @@ 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.provisionDesktopImpl( internal fun Prov.provisionDesktop(
desktopType: DesktopType = DesktopType.BASIC, desktopType: DesktopType = DesktopType.BASIC,
ssh: KeyPair? = null, ssh: KeyPair? = null,
gpg: KeyPair? = null, gpg: KeyPair? = null,
@ -40,9 +39,6 @@ fun Prov.provisionDesktopImpl(
submodules: List<String>? submodules: List<String>?
) = task { ) = task {
// TODO: why??
DesktopType.returnIfExists(desktopType.name) // throws exception when desktopType.name is unknown
validatePrecondition() validatePrecondition()
provisionBaseDesktop(gpg, ssh, gitUserName, gitEmail, submodules) provisionBaseDesktop(gpg, ssh, gitUserName, gitEmail, submodules)
@ -63,19 +59,21 @@ fun Prov.validatePrecondition() {
fun Prov.provisionIdeDesktop(submodules: List<String>?) { fun Prov.provisionIdeDesktop(submodules: List<String>?) {
if (submodules != null) { if (submodules != null) {
aptInstall(JAVA)
aptInstall(OPEN_VPM) aptInstall(OPEN_VPM)
aptInstall(OPENCONNECT) aptInstall(OPENCONNECT)
aptInstall(VPNC) aptInstall(VPNC)
// DevEnvs
installDocker() installDocker()
aptInstall(JAVA)
aptInstall(CLOJURE_TOOLS)
installShadowCljs()
installDevOps()
provisionPython()
// IDEs // IDEs
installVSC("python", "clojure") installVSC("python", "clojure")
aptInstall(CLOJURE_TOOLS)
installShadowCljs()
installIntelliJ() installIntelliJ()
installDevOps()
provisionPython()
} }
} }
@ -93,9 +91,7 @@ fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
aptInstall(EMAIL_CLIENT) aptInstall(EMAIL_CLIENT)
installDeltaChat() installDeltaChat()
aptInstall(OFFICE_SUITE) aptInstall(OFFICE_SUITE)
aptInstall(CLIP_TOOLS)
installZimWiki() installZimWiki()
installGopass()
aptInstallFromPpa("nextcloud-devs", "client", "nextcloud-client") aptInstallFromPpa("nextcloud-devs", "client", "nextcloud-client")
optional { optional {
@ -106,7 +102,7 @@ fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
} }
} }
private fun Prov.provisionBaseDesktop( fun Prov.provisionBaseDesktop(
gpg: KeyPair?, gpg: KeyPair?,
ssh: KeyPair?, ssh: KeyPair?,
gitUserName: String?, gitUserName: String?,
@ -122,14 +118,7 @@ private fun Prov.provisionBaseDesktop(
aptInstall(PASSWORD_TOOLS) aptInstall(PASSWORD_TOOLS)
aptInstall(OS_ANALYSIS) aptInstall(OS_ANALYSIS)
aptInstall(BASH_UTILS) aptInstall(BASH_UTILS)
aptInstall(CLIP_TOOLS)
provisionKeys(gpg, ssh)
provisionGit(gitUserName ?: whoami(), gitEmail, gpg?.let { gpgFingerprint(it.publicKey.plain()) })
installVirtualBoxGuestAdditions()
installRedshift()
configureRedshift()
aptPurge( aptPurge(
"remove-power-management xfce4-power-manager " + "remove-power-management xfce4-power-manager " +
"xfce4-power-manager-plugins xfce4-power-manager-data" "xfce4-power-manager-plugins xfce4-power-manager-data"
@ -137,7 +126,14 @@ private fun Prov.provisionBaseDesktop(
aptPurge("abiword gnumeric") aptPurge("abiword gnumeric")
aptPurge("popularity-contest") aptPurge("popularity-contest")
provisionKeys(gpg, ssh)
provisionGit(gitUserName ?: whoami(), gitEmail, gpg?.let { gpgFingerprint(it.publicKey.plain()) })
installGopass()
installRedshift()
configureRedshift()
configureNoSwappiness() configureNoSwappiness()
configureBash() configureBash()
installVirtualBoxGuestAdditions()
} }
} }

View file

@ -46,8 +46,8 @@ internal class ApplicationKtTest {
mockkStatic(::getConfig) mockkStatic(::getConfig)
every { getConfig("testconfig.yaml") } returns testConfig every { getConfig("testconfig.yaml") } returns testConfig
mockkStatic(Prov::provisionDesktopImpl) mockkStatic(Prov::provisionDesktop)
every { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(),any()) } returns ProvResult( every { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(),any()) } returns ProvResult(
true, true,
cmd = "mocked command" cmd = "mocked command"
) )
@ -64,7 +64,7 @@ internal class ApplicationKtTest {
unmockkStatic(::local) unmockkStatic(::local)
unmockkStatic(::remote) unmockkStatic(::remote)
unmockkStatic(::getConfig) unmockkStatic(::getConfig)
unmockkStatic(Prov::provisionDesktopImpl) unmockkStatic(Prov::provisionDesktop)
unmockkStatic(::retrievePassword) unmockkStatic(::retrievePassword)
} }
} }
@ -78,7 +78,7 @@ internal class ApplicationKtTest {
// then // then
verify { remote("host123.xyz", "user123", Secret("sec"), any()) } verify { remote("host123.xyz", "user123", Secret("sec"), any()) }
verify { verify {
any<Prov>().provisionDesktopImpl( any<Prov>().provisionDesktop(
DesktopType.BASIC, DesktopType.BASIC,
null, null,
null, null,
@ -113,7 +113,7 @@ internal class ApplicationKtTest {
"Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs." "Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m idontexist.yaml \u001B[0m and change the content according to your needs."
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", ""))
verify(exactly = 0) { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(), any()) } verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), any()) }
} }
@Test @Test
@ -140,6 +140,6 @@ internal class ApplicationKtTest {
"Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data." "Error: File \"src/test/resources/invalid-desktop-config.yaml\" has an invalid format and or invalid data."
assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", "")) assertEquals(expectedOutput, outContent.toString().replace("\r", "").replace("\n", ""))
verify(exactly = 0) { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(), any()) } verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), any()) }
} }
} }

View file

@ -10,25 +10,6 @@ import org.junit.jupiter.api.assertThrows
internal class DesktopServiceKtTest { internal class DesktopServiceKtTest {
@ContainerTest
fun provisionDesktop_fails_for_unknown_DesktopType() {
// given
val prov = defaultTestContainer()
// when
val exception = assertThrows<RuntimeException> {
prov.provisionDesktopImpl(
DesktopType("iamunkown"),
gitUserName = "testuser",
gitEmail = "testuser@test.org",
submodules = null
)
}
// then
assertEquals("No DesktopType found for value: iamunkown", exception.message)
}
@ExtensiveContainerTest @ExtensiveContainerTest
fun provisionDesktop() { fun provisionDesktop() {
// given // given
@ -36,7 +17,7 @@ internal class DesktopServiceKtTest {
// when // when
// in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time
val res = prov.provisionDesktopImpl( val res = prov.provisionDesktop(
DesktopType.BASIC, DesktopType.BASIC,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
@ -54,7 +35,7 @@ internal class DesktopServiceKtTest {
// when // when
// in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time
val res = prov.provisionDesktopImpl( val res = prov.provisionDesktop(
DesktopType.IDE, DesktopType.IDE,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
@ -74,7 +55,7 @@ internal class DesktopServiceKtTest {
// when // when
// in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time // in order to test DesktopType.OFFICE: fix installing libreoffice for a fresh container as it hangs the first time but succeeds 2nd time
val config = getConfig("src/test/resources/desktop-config-example.json") val config = getConfig("src/test/resources/desktop-config-example.json")
val res = prov.provisionDesktopImpl( val res = prov.provisionDesktop(
DesktopType.BASIC, DesktopType.BASIC,
config.ssh?.keyPair(), config.ssh?.keyPair(),
config.gpg?.keyPair(), config.gpg?.keyPair(),