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
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 java.io.FileNotFoundException
import kotlin.system.exitProcess
@ -20,7 +20,7 @@ fun main(args: Array<String>) {
val prov = createProvInstance(cmd.target, remoteHostSetSudoWithoutPasswordRequired = true)
try {
provisionDesktop(prov, cmd)
provisionDesktopCmd(prov, cmd)
} catch (e: SerializationException) {
println(
"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.whoami
fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
internal fun provisionDesktopCmd(prov: Prov, cmd: DesktopCliCommand) {
// retrieve config
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
*/
fun Prov.provisionDesktopImpl(
internal fun Prov.provisionDesktop(
desktopType: DesktopType = DesktopType.BASIC,
ssh: KeyPair? = null,
gpg: KeyPair? = null,
@ -40,9 +39,6 @@ fun Prov.provisionDesktopImpl(
submodules: List<String>?
) = task {
// TODO: why??
DesktopType.returnIfExists(desktopType.name) // throws exception when desktopType.name is unknown
validatePrecondition()
provisionBaseDesktop(gpg, ssh, gitUserName, gitEmail, submodules)
@ -63,19 +59,21 @@ fun Prov.validatePrecondition() {
fun Prov.provisionIdeDesktop(submodules: List<String>?) {
if (submodules != null) {
aptInstall(JAVA)
aptInstall(OPEN_VPM)
aptInstall(OPENCONNECT)
aptInstall(VPNC)
// DevEnvs
installDocker()
aptInstall(JAVA)
aptInstall(CLOJURE_TOOLS)
installShadowCljs()
installDevOps()
provisionPython()
// IDEs
installVSC("python", "clojure")
aptInstall(CLOJURE_TOOLS)
installShadowCljs()
installIntelliJ()
installDevOps()
provisionPython()
}
}
@ -93,9 +91,7 @@ fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
aptInstall(EMAIL_CLIENT)
installDeltaChat()
aptInstall(OFFICE_SUITE)
aptInstall(CLIP_TOOLS)
installZimWiki()
installGopass()
aptInstallFromPpa("nextcloud-devs", "client", "nextcloud-client")
optional {
@ -106,7 +102,7 @@ fun Prov.provisionOfficeDesktop(submodules: List<String>?) {
}
}
private fun Prov.provisionBaseDesktop(
fun Prov.provisionBaseDesktop(
gpg: KeyPair?,
ssh: KeyPair?,
gitUserName: String?,
@ -122,14 +118,7 @@ private fun Prov.provisionBaseDesktop(
aptInstall(PASSWORD_TOOLS)
aptInstall(OS_ANALYSIS)
aptInstall(BASH_UTILS)
provisionKeys(gpg, ssh)
provisionGit(gitUserName ?: whoami(), gitEmail, gpg?.let { gpgFingerprint(it.publicKey.plain()) })
installVirtualBoxGuestAdditions()
installRedshift()
configureRedshift()
aptInstall(CLIP_TOOLS)
aptPurge(
"remove-power-management xfce4-power-manager " +
"xfce4-power-manager-plugins xfce4-power-manager-data"
@ -137,7 +126,14 @@ private fun Prov.provisionBaseDesktop(
aptPurge("abiword gnumeric")
aptPurge("popularity-contest")
provisionKeys(gpg, ssh)
provisionGit(gitUserName ?: whoami(), gitEmail, gpg?.let { gpgFingerprint(it.publicKey.plain()) })
installGopass()
installRedshift()
configureRedshift()
configureNoSwappiness()
configureBash()
installVirtualBoxGuestAdditions()
}
}

View file

@ -46,8 +46,8 @@ internal class ApplicationKtTest {
mockkStatic(::getConfig)
every { getConfig("testconfig.yaml") } returns testConfig
mockkStatic(Prov::provisionDesktopImpl)
every { any<Prov>().provisionDesktopImpl(any(), any(), any(), any(), any(),any()) } returns ProvResult(
mockkStatic(Prov::provisionDesktop)
every { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(),any()) } returns ProvResult(
true,
cmd = "mocked command"
)
@ -64,7 +64,7 @@ internal class ApplicationKtTest {
unmockkStatic(::local)
unmockkStatic(::remote)
unmockkStatic(::getConfig)
unmockkStatic(Prov::provisionDesktopImpl)
unmockkStatic(Prov::provisionDesktop)
unmockkStatic(::retrievePassword)
}
}
@ -78,7 +78,7 @@ internal class ApplicationKtTest {
// then
verify { remote("host123.xyz", "user123", Secret("sec"), any()) }
verify {
any<Prov>().provisionDesktopImpl(
any<Prov>().provisionDesktop(
DesktopType.BASIC,
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."
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
@ -140,6 +140,6 @@ internal class ApplicationKtTest {
"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", ""))
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 {
@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
fun provisionDesktop() {
// given
@ -36,7 +17,7 @@ internal class DesktopServiceKtTest {
// when
// 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,
gitUserName = "testuser",
gitEmail = "testuser@test.org",
@ -54,7 +35,7 @@ internal class DesktopServiceKtTest {
// when
// 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,
gitUserName = "testuser",
gitEmail = "testuser@test.org",
@ -74,7 +55,7 @@ internal class DesktopServiceKtTest {
// when
// 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 res = prov.provisionDesktopImpl(
val res = prov.provisionDesktop(
DesktopType.BASIC,
config.ssh?.keyPair(),
config.gpg?.keyPair(),