From 4cc1ce756a26045810341f110b8cebd09c61aff0 Mon Sep 17 00:00:00 2001 From: az Date: Sun, 21 Aug 2022 13:06:49 +0200 Subject: [PATCH 1/7] resolve unsafe operator --- .../provs/server/domain/k3s/K3sService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index 4221094..46c44df 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -66,7 +66,7 @@ private fun Prov.provisionGrafanaSanitized( submodules: List?, grafanaConfigResolved: GrafanaAgentConfigResolved?) = task { - if (submodules!!.contains(ServerSubmodule.GRAFANA.name.lowercase())) { + if (submodules != null && submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) { if (grafanaConfigResolved == null) { println("ERROR: Could not find grafana config.") exitProcess(7) From 2525e0f2bb25d27659a6a862d8bddd26829c87ae Mon Sep 17 00:00:00 2001 From: az Date: Sun, 21 Aug 2022 13:23:04 +0200 Subject: [PATCH 2/7] refactor DesktopType --- .../desktop/application/CliArgumentsParser.kt | 2 +- .../provs/desktop/domain/DesktopType.kt | 12 +++-- .../provs/desktop/domain/DesktopTypeTest.kt | 51 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopTypeTest.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 4277c59..b2a3605 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/application/CliArgumentsParser.kt @@ -24,7 +24,7 @@ open class CliArgumentsParser(name: String) : CliTargetParser(name) { val module = modules.first { it.parsed } return DesktopCliCommand( - DesktopType.returnIfExists(module.name.uppercase()), + DesktopType.valueOf(module.name.uppercase()), TargetCliCommand( target, passwordInteractive diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt index 2f1b72c..13edb9c 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopType.kt @@ -4,9 +4,8 @@ package org.domaindrivenarchitecture.provs.desktop.domain /** * Provides desktop types. For each type a different set of software and packages is installed, see README.md. */ -open class DesktopType(val name: String) { - - // A regular class is used rather than enum class in order to allow extending DesktopType by subclassing. +// Uses a regular class instead of an enum class in order to allow subclasses which can add new DesktopTypes +open class DesktopType protected constructor(val name: String) { companion object { @@ -17,7 +16,11 @@ open class DesktopType(val name: String) { @JvmStatic protected val values = listOf(BASIC, OFFICE, IDE) - fun returnIfExists(value: String, valueList: List = values): DesktopType { + @JvmStatic + fun valueOf(value: String): DesktopType = valueOf(value, values) + + @JvmStatic + protected fun valueOf(value: String, valueList: List): DesktopType { for (type in valueList) { if (value.uppercase().equals(type.name)) { return type @@ -31,4 +34,3 @@ open class DesktopType(val name: String) { return name } } - diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopTypeTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopTypeTest.kt new file mode 100644 index 0000000..715ede7 --- /dev/null +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/domain/DesktopTypeTest.kt @@ -0,0 +1,51 @@ +package org.domaindrivenarchitecture.provs.desktop.domain + +import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType.Companion.BASIC +import org.domaindrivenarchitecture.provs.desktop.domain.DesktopType.Companion.IDE +import org.domaindrivenarchitecture.provs.desktop.domain.SubDesktopType.Companion.SUBTYPE +import org.junit.jupiter.api.Test + +import org.junit.jupiter.api.Assertions.* + +// tests subclassing of DesktopType +internal open class SubDesktopType protected constructor(name: String) : DesktopType(name) { + + companion object { + + // defines a new DesktopType + val SUBTYPE = SubDesktopType("SUBTYPE") + + private val values = DesktopType.values + SUBTYPE + + fun valueOf(value: String): DesktopType { + return valueOf(value, values) + } + } +} + +internal class DesktopTypeTest { + + @Test + fun test_valueOf() { + assertEquals(BASIC, DesktopType.valueOf("basic")) + assertEquals(BASIC, DesktopType.valueOf("Basic")) + assertEquals(IDE, DesktopType.valueOf("IDE")) + + val exception = assertThrows(RuntimeException::class.java) { + DesktopType.valueOf("subtype") + } + assertEquals("No DesktopType found for value: subtype", exception.message) + } + + @Test + fun test_valueOf_in_subclass() { + assertEquals(SUBTYPE, SubDesktopType.valueOf("subtype")) + assertEquals(BASIC, SubDesktopType.valueOf("basic")) + assertNotEquals(SUBTYPE, DesktopType.valueOf("basic")) + + val exception = assertThrows(RuntimeException::class.java) { + DesktopType.valueOf("subtype2") + } + assertEquals("No DesktopType found for value: subtype2", exception.message) + } +} From 411003f04ab95d4aa0abcdeddbd08c962ee2ea56 Mon Sep 17 00:00:00 2001 From: az Date: Sun, 21 Aug 2022 14:00:00 +0200 Subject: [PATCH 3/7] [skip ci] update README.md --- README.md | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a60697b..578a18f 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,12 @@ ## Purpose -provs provides cli-based tooling for provisioning desktop or server resp. perform system checks. -* provs-desktop minimal - provides a minimal setup (e.g. swappiness / randomutils) e.g. for setup on a VirtualBox -* provs-desktop office - provides enhancements like zim / gopass / fakturama -* provs-desktop ide - provides development environments for java / kotlin / python / clojure / terraform -* provs-server k3s - provides a production ready & k3s setup with dualstack option -* provs-syspec - verifies a system according to the provided system spec config file - -In general provs combines -* being able to use the power of shell commands -* a clear and detailed result summary of the built-in execution handling (incl. failure handling and reporting) -* the convenience and robustness of a modern programming language +provs provides cli-based tools for +* provisioning a desktop (various kinds) +* provisioning a k3s server +* performing system checks + +Tasks can be run locally or remotely. ## Status @@ -26,11 +21,24 @@ under development - we are working hard on setting up our environments using pro * A **Java Virtual machine** (JVM) is required. * Install `jarwrapper` (e.g. `sudo apt install jarwrapper`) -* Download the latest `provs-desktop.jar` from: https://gitlab.com/domaindrivenarchitecture/provs/-/releases -* Make the jar-file executable by `chmod +x provs-desktop.jar` -* For server functionality (e.g. k3s) download the latest `provs-server.jar` from: https://gitlab.com/domaindrivenarchitecture/provs/-/releases +* Then either download the binaries or build them yourself + +#### Download the binaries + +* Download the latest `provs-desktop.jar`,`provs-server.jar` and/or `provs-syspec.jar` from: https://gitlab.com/domaindrivenarchitecture/provs/-/releases + * Preferably into `/usr/local/bin` or any other folder where executables can be found by the system +* Make the jar-file executable e.g. by `chmod +x provs-desktop.jar` + +#### Build the binaries + +Instead of downloading the binaries you can build them yourself + +* Clone this repository +* In the repository's root folder execute: `./gradlew install`. This will install the binaries in `/usr/local/bin` + +### Provision a desktop -### provs-desktop +After having installed `provs-desktop.jar` (see prerequisites) execute: `provs-desktop.jar []` @@ -49,7 +57,7 @@ under development - we are working hard on setting up our environments using pro * `-p` for interactive password question -#### Provision a desktop +#### Example ```bash provs-desktop.jar basic local @@ -57,9 +65,9 @@ provs-desktop.jar basic local provs-desktop.jar office myuser@myhost.com -p ``` -In the last case you'll be prompted for the password of the remote user due to option `-p`. +In the second case you'll be prompted for the password of the remote user due to option `-p`. -### Provision k3s +### Provision a k3s Server ```bash provs-server.jar k3s local @@ -94,14 +102,14 @@ provs-server.jar k3s myuser@myhost.com -o grafana -### Performing a system check +### Perform a system check The default config-file for the system check is `syspec-config.yaml`, you can specify a different file with option `-c `. ```bash provs-syspec.jar local -# or remote: -provs-syspec.jar myuser@myhost.com +# or remote with a custom config filename +provs-syspec.jar myuser@myhost.com -c my-syspec-config.yaml ``` ## Get help From 17a814a11a891dc32701583735f78f096cfc7356 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 24 Aug 2022 13:21:43 +0200 Subject: [PATCH 4/7] Move reprovision cmd line option to new branch --- .../provs/server/application/CliArgumentsParser.kt | 12 ++---------- .../provs/server/domain/k3s/K3sCliCommand.kt | 3 +-- .../provs/server/domain/k3s/K3sService.kt | 10 ++-------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt index 0b2d4a3..f6e5b3e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/application/CliArgumentsParser.kt @@ -34,8 +34,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) { ), module.configFileName, module.applicationFileName, - module.submodules, - module.reprovision + module.submodules ) else -> return ServerCliCommand( ServerType.valueOf(module.name.uppercase()), @@ -53,7 +52,6 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) { var configFileName: ConfigFileName? = null var applicationFileName: ApplicationFileName? = null var submodules: List? = null - var reprovision: Boolean = false } class K3s : ServerSubcommand("k3s", "the k3s module") { @@ -75,17 +73,11 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) { "o", "provisions only parts ", ) - val cliReprovision by option( - ArgType.Boolean, - "reprovision", - "r", - "redo provisioning, deletes old config first" - ) + override fun execute() { super.configFileName = cliConfigFileName?.let { ConfigFileName(it) } super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) } super.submodules = if (only != null) listOf(only!!.name.lowercase()) else null - super.reprovision = cliReprovision == true super.parsed = true } } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt index 1cca7f6..fda6571 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sCliCommand.kt @@ -10,8 +10,7 @@ class K3sCliCommand( target: TargetCliCommand, configFileName: ConfigFileName?, val applicationFileName: ApplicationFileName?, - val submodules: List? = null, - val reprovision: Reprovision = false + val submodules: List? = null ) : ServerCliCommand( serverType, target, configFileName diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index 46c44df..c730dd3 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -11,17 +11,11 @@ fun Prov.provisionK3s(cli: K3sCliCommand) = task { val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret() - if (cli.submodules == null && !cli.reprovision) { + if (cli.submodules == null) { // full k3s val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName) provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName) - } - else if (cli.reprovision) { - deprovisionK3sInfra() - val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName) - provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName) - } - else { + } else { // submodules only provisionGrafanaSanitized(cli.submodules, grafanaConfigResolved) } From 83f86db0d110cb0cffd0edb6f44808d626857609 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 25 Aug 2022 16:12:30 +0200 Subject: [PATCH 5/7] [skip-ci] Update README and gopass versions A few clarifications in the readme. Also updated versions of gopassJsonAPI and gopassBridge. Clarified variable name. --- README.md | 7 +++++-- .../provs/desktop/infrastructure/GopassBridge.kt | 16 ++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 578a18f..55d1a73 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,9 @@ After having installed `provs-desktop.jar` (see prerequisites) execute: **target** can be: * `local` -* `user123:mypassword@myhost.com` - general format is: - +* remote, e.g. `user123:mypassword@myhost.com` - general format is: - + * be sure to have openssh-server installed + * add your preferred public key to known_hosts on the target machine * if password is omitted, then ssh-keys will be used for authentication * if password is omitted but option `-p` is provided, then the password will be prompted interactively @@ -75,7 +77,8 @@ provs-server.jar k3s local provs-server.jar k3s myuser@myhost.com # using ssh-authentication - alternatively use option -p for password authentication ``` -For the remote server please configure a config file (default file name: server-config.yaml) +For the remote server please configure a config file (default file name: server-config.yaml). +It has to be in the same folder where you execute the provs-server.jar command. ```yaml fqdn: "myhostname.com" node: diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/GopassBridge.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/GopassBridge.kt index 1095c33..edabfb9 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/GopassBridge.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/GopassBridge.kt @@ -11,7 +11,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFrom fun Prov.downloadGopassBridge() = task { - val version = "0.8.0" + val version = "0.9.0" val filename = "gopass_bridge-${version}-fx.xpi" val downloadDir = "${userHome()}Downloads/" @@ -25,10 +25,10 @@ fun Prov.downloadGopassBridge() = task { fun Prov.installGopassBridgeJsonApi() = task { // see https://github.com/gopasspw/gopass-jsonapi - val gopassBridgeVersion = "1.11.1" - val requiredGopassVersion = "1.12" - val filename = "gopass-jsonapi_${gopassBridgeVersion}_linux_amd64.deb" - val downloadUrl = "-L https://github.com/gopasspw/gopass-jsonapi/releases/download/v$gopassBridgeVersion/$filename" + val gopassJsonApiVersion = "1.14.3" + val requiredGopassVersion = "1.14.4" + val filename = "gopass-jsonapi_${gopassJsonApiVersion}_linux_amd64.deb" + val downloadUrl = "-L https://github.com/gopasspw/gopass-jsonapi/releases/download/v$gopassJsonApiVersion/$filename" val downloadDir = "${userHome()}Downloads" val installedJsonApiVersion = gopassJsonApiVersion()?.trim() @@ -55,13 +55,13 @@ fun Prov.installGopassBridgeJsonApi() = task { ) } } else { - if (installedJsonApiVersion.startsWith("gopass-jsonapi version " + gopassBridgeVersion)) { - addResultToEval(ProvResult(true, out = "Version $gopassBridgeVersion of gopass-jsonapi is already installed")) + if (installedJsonApiVersion.startsWith("gopass-jsonapi version " + gopassJsonApiVersion)) { + addResultToEval(ProvResult(true, out = "Version $gopassJsonApiVersion of gopass-jsonapi is already installed")) } else { addResultToEval( ProvResult( false, - err = "gopass-jsonapi (version $gopassBridgeVersion) cannot be installed as version $installedJsonApiVersion is already installed." + + err = "gopass-jsonapi (version $gopassJsonApiVersion) cannot be installed as version $installedJsonApiVersion is already installed." + " Upgrading gopass-jsonapi is currently not supported by provs." ) ) From 232b59b862d8caf93850449283bbdc142020d552 Mon Sep 17 00:00:00 2001 From: az Date: Thu, 25 Aug 2022 17:46:12 +0200 Subject: [PATCH 6/7] release-0.15.3 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0358d86..ebf5c72 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: "kotlinx-serialization" group = "org.domaindrivenarchitecture.provs" -version = "0.15.3-SNAPSHOT" +version = "release-0.15.3" repositories { mavenCentral() From 806a1108bdedb194a8489e7578790ca6120c4d01 Mon Sep 17 00:00:00 2001 From: az Date: Thu, 25 Aug 2022 17:48:49 +0200 Subject: [PATCH 7/7] 0.15.4-SNAPSHOT --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ebf5c72..c12808c 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: "kotlinx-serialization" group = "org.domaindrivenarchitecture.provs" -version = "release-0.15.3" +version = "0.15.4-SNAPSHOT" repositories { mavenCentral()