From f219e70d8308f4d2d256169660aabbb02d9ae300 Mon Sep 17 00:00:00 2001 From: Clemens Geibel Date: Fri, 10 Jun 2022 11:10:02 +0200 Subject: [PATCH] Added 'only' option and ms-teams --- .../desktop/application/CliArgumentsParser.kt | 8 ++++++++ .../provs/desktop/domain/DesktopService.kt | 17 ++++++++++++++++- .../provs/desktop/domain/DesktopSubmodule.kt | 5 +++++ .../provs/desktop/infrastructure/Citrix.kt | 14 ++++++++++++++ .../provs/desktop/infrastructure/MsTeams.kt | 13 +++++++++++++ .../application/CliArgumentsParserTest.kt | 9 +++++++++ .../desktop/infrastructure/MsTeamsTest.kt | 19 +++++++++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopSubmodule.kt create mode 100644 src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Citrix.kt create mode 100644 src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeams.kt create mode 100644 src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeamsTest.kt diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt index 703bef4..b2a3605 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt @@ -6,6 +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.DesktopType @@ -44,10 +45,17 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) { "c", "the filename containing the yaml config", ) + val only by option( + ArgType.Choice(), + "only", + "o", + "provisions only parts ", + ) override fun execute() { configFileName = cliConfigFileName?.let { ConfigFileName(it) } parsed = true + submodules = if (only != null) listOf(only!!.name.lowercase()) else null } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt index 568f1cb..45e0257 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopService.kt @@ -15,9 +15,15 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami fun provisionDesktop(prov: Prov, cmd: DesktopCliCommand) { + val submodules = cmd.submodules // retrieve config val conf = if (cmd.configFile != null) getConfig(cmd.configFile.fileName) else DesktopConfig() - prov.provisionWorkplace(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail) + + if (submodules == null) { + prov.provisionWorkplace(cmd.type, conf.ssh?.keyPair(), conf.gpg?.keyPair(), conf.gitUserName, conf.gitEmail) + } else { + prov.provisionDesktopSubmodules(submodules) + } } @@ -111,3 +117,12 @@ fun Prov.provisionWorkplace( } ProvResult(true) } + +private fun Prov.provisionDesktopSubmodules( + submodules: List, +) = task { + + if (submodules.contains(DesktopSubmodule.TEAMS.name.lowercase())) { + installMsTeams() + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopSubmodule.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopSubmodule.kt new file mode 100644 index 0000000..8e51de9 --- /dev/null +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopSubmodule.kt @@ -0,0 +1,5 @@ +package org.domaindrivenarchitecture.provs.desktop.domain + +enum class DesktopSubmodule { + TEAMS +} \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Citrix.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Citrix.kt new file mode 100644 index 0000000..cde0f27 --- /dev/null +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Citrix.kt @@ -0,0 +1,14 @@ +package org.domaindrivenarchitecture.provs.desktop.infrastructure + +import org.domaindrivenarchitecture.provs.framework.core.Prov +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDir +import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL + +/** + * ATTENTION: Download URL might be only valid for a limited time and thus might not be working. + */ +fun Prov.installCitrixWorkspaceApp() = task { + downloadFromURL("https://downloads.citrix.com/20976/linuxx64-22.5.0.16.tar.gz?__gda__=exp=1654847726~acl=/*~hmac=be248338ecd7c7de50950ff7825fc0a80577fef7d3610988c64391cff8eaca16", "xitrix.tar.gz", "/tmp") + createDir("xitrix", "/tmp") + cmd("tar -xf xitrix.tar.gz -C /tmp/xitrix") +} diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeams.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeams.kt new file mode 100644 index 0000000..d8fdc45 --- /dev/null +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeams.kt @@ -0,0 +1,13 @@ +package org.domaindrivenarchitecture.provs.desktop.infrastructure + +import org.domaindrivenarchitecture.provs.framework.core.Prov +import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall + +fun Prov.installMsTeams() = task { + aptInstall("curl") + cmd("curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -") + cmd("sudo sh -c 'echo \"deb [arch=amd64] https://packages.microsoft.com/repos/ms-teams stable main\" > /etc/apt/sources.list.d/teams.list'") + //cmd("sudo apt update") + aptInstall("teams") + //cmd("sudo apt install teams") +} \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParserTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParserTest.kt index 35e4a32..ef69e0d 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParserTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParserTest.kt @@ -14,4 +14,13 @@ internal class CliArgumentsParserTest { assertEquals(null, cli.configFile) assertEquals(true, cli.target.isValidLocalhost()) } + + @Test + fun parse_cliCommand_with_only_submodule_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")) + } } \ No newline at end of file diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeamsTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeamsTest.kt new file mode 100644 index 0000000..4911955 --- /dev/null +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/MsTeamsTest.kt @@ -0,0 +1,19 @@ +package org.domaindrivenarchitecture.provs.desktop.infrastructure + +import org.domaindrivenarchitecture.provs.test.defaultTestContainer +import org.domaindrivenarchitecture.provs.test.tags.ContainerTest +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +class MsTeamsTest { + + @ContainerTest + fun installMsTeams() { + // given + val a = defaultTestContainer() + // when + val res = a.task { installMsTeams() } + // then + assertTrue(res.success) + } +} \ No newline at end of file