release-0.11.10 - rename workplace to desktop

merge-requests/1/merge release-0.11.10
ansgarz 2 years ago
parent bcd43a95be
commit bf3a8db4c0

@ -18,7 +18,7 @@ apply plugin: "kotlinx-serialization"
group = "org.domaindrivenarchitecture.provs" group = "org.domaindrivenarchitecture.provs"
version = "0.11.10-SNAPSHOT" version = "release-0.11.10"
repositories { repositories {
mavenCentral() mavenCentral()

@ -7,7 +7,7 @@ import java.io.FileNotFoundException
import kotlin.system.exitProcess import kotlin.system.exitProcess
/** /**
* Provisions a desktop workplace locally or on a remote machine. Use option -h for help. * Provisions desktop software (office and/or ide depending on type) locally or on a remote machine. Use option -h for help.
*/ */
fun main(args: Array<String>) { fun main(args: Array<String>) {
@ -28,7 +28,7 @@ fun main(args: Array<String>) {
} catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
println( println(
"Error: File\u001b[31m ${cmd.configFile?.fileName} \u001b[0m was not found.\n" + "Error: File\u001b[31m ${cmd.configFile?.fileName} \u001b[0m was not found.\n" +
"Pls copy file \u001B[31m WorkplaceConfigExample.yaml \u001B[0m to file \u001B[31m ${cmd.configFile?.fileName} \u001B[0m " + "Pls copy file \u001B[31m desktop-config-example.yaml \u001B[0m to file \u001B[31m ${cmd.configFile?.fileName} \u001B[0m " +
"and change the content according to your needs.\n" "and change the content according to your needs.\n"
) )
} }

@ -20,7 +20,7 @@ fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
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) { if (submodules == null) {
prov.provisionWorkplace(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail) prov.provisionDesktop(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail)
} else { } else {
prov.provisionDesktopSubmodules(submodules) prov.provisionDesktopSubmodules(submodules)
} }
@ -28,14 +28,14 @@ fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) {
/** /**
* Provisions software and configurations for a personal workplace. * Provisions software and configurations for a personal desktop.
* Offers the possibility to choose between different types. * Offers the possibility to choose between different types.
* Type OFFICE installs office-related software like Thunderbird, LibreOffice, and much more. * Type OFFICE installs office-related software like Thunderbird, LibreOffice, and much more.
* Type IDE provides additional software for a development environment, such as Visual Studio Code, IntelliJ, etc. * Type IDE provides additional software for a development environment, such as Visual Studio Code, IntelliJ, etc.
* *
* Prerequisites: user must be able to sudo without entering the password * Prerequisites: user must be able to sudo without entering the password
*/ */
fun Prov.provisionWorkplace( fun Prov.provisionDesktop(
desktopType: DesktopType = DesktopType.BASIC, desktopType: DesktopType = DesktopType.BASIC,
ssh: KeyPair? = null, ssh: KeyPair? = null,
gpg: KeyPair? = null, gpg: KeyPair? = null,
@ -44,7 +44,7 @@ fun Prov.provisionWorkplace(
) = task { ) = task {
if (!currentUserCanSudo()) { if (!currentUserCanSudo()) {
throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionWorkplace") throw Exception("Current user ${whoami()} cannot execute sudo without entering a password! This is necessary to execute provisionDesktop")
} }
aptInstall(KEY_MANAGEMENT) aptInstall(KEY_MANAGEMENT)

@ -8,7 +8,7 @@ import java.io.FileWriter
/** /**
* Returns WorkplaceConfig; data for config is read from specified file. * Returns DesktopConfig; data for config is read from specified file.
* Throws exceptions FileNotFoundException, SerializationException if file is not found resp. cannot be parsed. * Throws exceptions FileNotFoundException, SerializationException if file is not found resp. cannot be parsed.
*/ */
internal fun getConfig(filename: String = "desktop-config.yaml"): DesktopConfig = readFromFile(filename).yamlToType() internal fun getConfig(filename: String = "desktop-config.yaml"): DesktopConfig = readFromFile(filename).yamlToType()

@ -7,7 +7,7 @@ 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.DesktopConfig import org.domaindrivenarchitecture.provs.desktop.domain.DesktopConfig
import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType
import org.domaindrivenarchitecture.provs.desktop.domain.provisionWorkplace import org.domaindrivenarchitecture.provs.desktop.domain.provisionDesktop
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.core.* import org.domaindrivenarchitecture.provs.framework.core.*
import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword
@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.PrintStream import java.io.PrintStream
internal class CliWorkplaceKtTest { internal class ApplicationKtTest {
companion object { companion object {
@ -31,6 +31,7 @@ internal class CliWorkplaceKtTest {
ConfigFileName("bla") ConfigFileName("bla")
) )
@Suppress("unused") // false positive
@BeforeAll @BeforeAll
@JvmStatic @JvmStatic
internal fun beforeAll() { internal fun beforeAll() {
@ -48,8 +49,8 @@ internal class CliWorkplaceKtTest {
mockkStatic(::getConfig) mockkStatic(::getConfig)
every { getConfig("testconfig.yaml") } returns testConfig every { getConfig("testconfig.yaml") } returns testConfig
mockkStatic(Prov::provisionWorkplace) mockkStatic(Prov::provisionDesktop)
every { any<Prov>().provisionWorkplace(any(), any(), any(), any(), any(), ) } returns ProvResult( every { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) } returns ProvResult(
true, true,
cmd = "mocked command" cmd = "mocked command"
) )
@ -58,6 +59,7 @@ internal class CliWorkplaceKtTest {
every { retrievePassword(any()) } returns Secret("sec") every { retrievePassword(any()) } returns Secret("sec")
} }
@Suppress("unused") // false positive
@AfterAll @AfterAll
@JvmStatic @JvmStatic
internal fun afterAll() { internal fun afterAll() {
@ -65,13 +67,13 @@ internal class CliWorkplaceKtTest {
unmockkStatic(::local) unmockkStatic(::local)
unmockkStatic(::remote) unmockkStatic(::remote)
unmockkStatic(::getConfig) unmockkStatic(::getConfig)
unmockkStatic(Prov::provisionWorkplace) unmockkStatic(Prov::provisionDesktop)
unmockkStatic(::retrievePassword) unmockkStatic(::retrievePassword)
} }
} }
@Test @Test
fun provision_workplace_remotely() { fun provision_desktop_remotely() {
// when // when
main(arrayOf("basic", "user123:sec@host123.xyz", "-c", "testconfig.yaml")) main(arrayOf("basic", "user123:sec@host123.xyz", "-c", "testconfig.yaml"))
@ -79,7 +81,7 @@ internal class CliWorkplaceKtTest {
// then // then
verify { remote("host123.xyz", "user123", Secret("sec"), any()) } verify { remote("host123.xyz", "user123", Secret("sec"), any()) }
verify { verify {
any<Prov>().provisionWorkplace( any<Prov>().provisionDesktop(
DesktopType.BASIC, DesktopType.BASIC,
null, null,
null, null,
@ -110,10 +112,10 @@ internal class CliWorkplaceKtTest {
System.setErr(originalErr) System.setErr(originalErr)
val expectedOutput = val expectedOutput =
"Error: File\u001B[31m idontexist.yaml \u001B[0m was not found.Pls copy file \u001B[31m WorkplaceConfigExample.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>().provisionWorkplace(any(), any(), any(), any(), any(), ) } verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) }
} }
@Test @Test
@ -130,16 +132,16 @@ internal class CliWorkplaceKtTest {
System.setErr(PrintStream(errContent)) System.setErr(PrintStream(errContent))
// when // when
main(arrayOf("basic", "someuser@remotehost", "-c", "src/test/resources/InvalidWorkplaceConfig.yaml")) main(arrayOf("basic", "someuser@remotehost", "-c", "src/test/resources/invalid-desktop-config.yaml"))
// then // then
System.setOut(originalOut) System.setOut(originalOut)
System.setErr(originalErr) System.setErr(originalErr)
val expectedOutput = val expectedOutput =
"Error: File \"src/test/resources/InvalidWorkplaceConfig.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>().provisionWorkplace(any(), any(), any(), any(), any(), ) } verify(exactly = 0) { any<Prov>().provisionDesktop(any(), any(), any(), any(), any(), ) }
} }
} }

@ -5,16 +5,16 @@ import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
internal class ProvisionWorkplaceKtTest { internal class DesktopServiceKtTest {
@ExtensiveContainerTest @ExtensiveContainerTest
fun provisionWorkplace() { fun provisionDesktop() {
// given // given
val a = defaultTestContainer() val prov = defaultTestContainer()
// when // when
// in order to test WorkplaceType.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 = a.provisionWorkplace( val res = prov.provisionDesktop(
DesktopType.BASIC, DesktopType.BASIC,
gitUserName = "testuser", gitUserName = "testuser",
gitEmail = "testuser@test.org", gitEmail = "testuser@test.org",
@ -26,14 +26,14 @@ internal class ProvisionWorkplaceKtTest {
@ExtensiveContainerTest @ExtensiveContainerTest
fun provisionWorkplaceFromConfigFile() { fun provisionDesktopFromConfigFile() {
// given // given
val a = defaultTestContainer() val prov = defaultTestContainer()
// when // when
// in order to test WorkplaceType.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/WorkplaceConfigExample.json") val config = getConfig("src/test/resources/desktop-config-example.json")
val res = a.provisionWorkplace( val res = prov.provisionDesktop(
DesktopType.BASIC, DesktopType.BASIC,
config.ssh?.keyPair(), config.ssh?.keyPair(),
config.gpg?.keyPair(), config.gpg?.keyPair(),

@ -14,7 +14,7 @@ internal class K3SDesktopConfigRepositoryKtTest {
@Test @Test
fun getConfig_successful() { fun getConfig_successful() {
// when // when
val config = getConfig("src/test/resources/TestWorkplaceConfig.yaml") val config = getConfig("src/test/resources/test-desktop-config.yaml")
// then // then
assertEquals("username", config.gitUserName) assertEquals("username", config.gitUserName)
@ -32,7 +32,7 @@ internal class K3SDesktopConfigRepositoryKtTest {
@Test @Test
fun getConfig_fails_due_to_invalidProperty() { fun getConfig_fails_due_to_invalidProperty() {
val exception = assertThrows<InvalidPropertyValueException> { val exception = assertThrows<InvalidPropertyValueException> {
getConfig("src/test/resources/InvalidWorkplaceConfig.yaml") getConfig("src/test/resources/invalid-desktop-config.yaml")
} }
assertEquals("Value for 'sourceType' is invalid: Value 'xxx' is not a valid option, permitted choices are: FILE, GOPASS, PASS, PLAIN, PROMPT", exception.message) assertEquals("Value for 'sourceType' is invalid: Value 'xxx' is not a valid option, permitted choices are: FILE, GOPASS, PASS, PLAIN, PROMPT", exception.message)
} }

@ -115,7 +115,7 @@ internal class WebKtTest {
} }
@Test @Test
fun isIp4_recognizes_Ip_correctly() { fun isIp4_recognizes_ip_correctly() {
// when // when
val res1 = isIp4("123.123.123.123") val res1 = isIp4("123.123.123.123")
val res2 = isIp4("123.abc.123.123") val res2 = isIp4("123.abc.123.123")
@ -128,7 +128,7 @@ internal class WebKtTest {
} }
@Test @Test
fun isIp6_recognizes_Ip_correctly() { fun isIp6_recognizes_ip_correctly() {
// when // when
val res1 = isIp6("2001:db8:3333:4444:5555:6666:7777:8888") val res1 = isIp6("2001:db8:3333:4444:5555:6666:7777:8888")
val res2 = isIp6("2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF") val res2 = isIp6("2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF")

@ -28,7 +28,7 @@ internal class GrafanaAgentRepositoryKtTest {
@Test @Test
fun findK8sGrafanaConfig_returns_null_if_no_grafan_data_available() { fun findK8sGrafanaConfig_returns_null_if_no_grafan_data_available() {
// when // when
val config = findK8sGrafanaConfig(ConfigFileName("src/test/resources/k3sServerConfig.yaml")) val config = findK8sGrafanaConfig(ConfigFileName("src/test/resources/k3s-server-config.yaml"))
// then // then
assertEquals(null, config) assertEquals(null, config)

@ -17,7 +17,7 @@ internal class K3sConfigRepositoryTest {
@Test @Test
fun getConfig_successful() { fun getConfig_successful() {
// when // when
val config = getK3sConfig(ConfigFileName("src/test/resources/k3sServerConfig.yaml")) val config = getK3sConfig(ConfigFileName("src/test/resources/k3s-server-config.yaml"))
// then // then
assertEquals( assertEquals(
@ -38,7 +38,7 @@ internal class K3sConfigRepositoryTest {
@Test @Test
fun getConfig_fails_due_to_missing_property() { fun getConfig_fails_due_to_missing_property() {
val exception = assertThrows<SerializationException> { val exception = assertThrows<SerializationException> {
getK3sConfig(ConfigFileName("src/test/resources/InvalidWorkplaceConfig.yaml")) getK3sConfig(ConfigFileName("src/test/resources/invalid-desktop-config.yaml"))
} }
assertEquals("Fields [fqdn, node] are required for type with serial name 'org.domaindrivenarchitecture.provs.server.domain.k3s.K3sConfig', but they were missing", exception.message) assertEquals("Fields [fqdn, node] are required for type with serial name 'org.domaindrivenarchitecture.provs.server.domain.k3s.K3sConfig', but they were missing", exception.message)
} }

Loading…
Cancel
Save