diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Bash.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Bash.kt index 00e2dd4..98dcaab 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Bash.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Bash.kt @@ -2,7 +2,6 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.ProvResult -import org.domaindrivenarchitecture.provs.framework.core.endingWithFileSeparator import org.domaindrivenarchitecture.provs.framework.core.getResourceAsText import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.addTextToFile import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDir @@ -12,11 +11,11 @@ import java.io.File private val resourcePath = "org/domaindrivenarchitecture/provs/desktop/infrastructure/" -fun Prov.configureBash() = def { +fun Prov.configureBash() = task { configureBashForUser() } -fun Prov.configureBashForUser(): ProvResult = def { +fun Prov.configureBashForUser(): ProvResult = task { val dirname = "~/.bashrc.d" if(!dirExists(dirname)) { createDir(dirname) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt index 6264521..a5019a4 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt @@ -7,7 +7,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL -fun Prov.installDevOps() = def { +fun Prov.installDevOps() = task { installTerraform() installKubectlAndTools() installYq() @@ -18,7 +18,7 @@ fun Prov.installDevOps() = def { fun Prov.installYq( version: String = "4.13.2", sha256sum: String = "d7c89543d1437bf80fee6237eadc608d1b121c21a7cbbe79057d5086d74f8d79" -): ProvResult = def { +): ProvResult = task { val path = "/usr/bin/" val filename = "yq" if (!fileExists(path + filename)) { @@ -35,7 +35,7 @@ fun Prov.installYq( } } -fun Prov.installKubectlAndTools(): ProvResult = def { +fun Prov.installKubectlAndTools(): ProvResult = task { val resourcePath = "org/domaindrivenarchitecture/provs/desktop/infrastructure" task("installKubectl") { @@ -88,7 +88,7 @@ fun Prov.installKubectlAndTools(): ProvResult = def { } } -fun Prov.installTerraform(): ProvResult = def { +fun Prov.installTerraform(): ProvResult = task { val dir = "/usr/lib/tfenv/" if (!dirExists(dir)) { @@ -105,7 +105,7 @@ fun Prov.installTerraform(): ProvResult = def { // -------------------------------------------- AWS credentials file ----------------------------------------------- fun Prov.installAwsCredentials(id: String = "REPLACE_WITH_YOUR_ID", key: String = "REPLACE_WITH_YOUR_KEY"): ProvResult = - def { + task { val dir = "~/.aws" if (!dirExists(dir)) { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Docker.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Docker.kt index 83c0325..f44a6cc 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Docker.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Docker.kt @@ -3,7 +3,7 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall -fun Prov.installDocker() = def { +fun Prov.installDocker() = task { aptInstall("containerd docker.io") if (!chk("getent group docker")) { cmd("sudo groupadd docker") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Fakturama.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Fakturama.kt index a92c3d0..6f92570 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Fakturama.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Fakturama.kt @@ -5,7 +5,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.creat import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL -fun Prov.installFakturama() = def { +fun Prov.installFakturama() = task { createDir("/tmp", sudo = true) downloadFromURL( "https://files.fakturama.info/release/v2.1.1/Installer_Fakturama_linux_x64_2.1.1b.deb", "fakturama.deb", "/tmp") cmd("sudo dpkg -i fakturama.deb", "/tmp") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Gopass.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Gopass.kt index 9d75ca0..5b31e4b 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Gopass.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Gopass.kt @@ -12,13 +12,13 @@ fun Prov.installGopass( version: String = "1.12.7", enforceVersion: Boolean = false, sha256sum: String = "0824d5110ff1e68bff1ba10c1be63acb67cb1ad8e3bccddd6b6fc989608beca8" // checksum for sha256sum version 8.30 (e.g. ubuntu 20.04) -) = def { +) = task { if (isPackageInstalled("gopass") && !enforceVersion) { - return@def ProvResult(true) + return@task ProvResult(true) } if (checkGopassVersion(version)) { - return@def ProvResult(true, out = "Version $version of gopass is already installed.") + return@task ProvResult(true, out = "Version $version of gopass is already installed.") } val path = "tmp" @@ -64,13 +64,13 @@ fun Prov.configureGopass(gopassRootFolder: String? = null) = task { } -fun Prov.gopassMountStore(storeName: String, path: String) = def { +fun Prov.gopassMountStore(storeName: String, path: String) = task { cmd("gopass mounts add $storeName $path") } @Suppress("unused") -fun Prov.gopassInitStore(storeName: String, indexOfRecepientKey: Int = 0) = def { +fun Prov.gopassInitStore(storeName: String, indexOfRecepientKey: Int = 0) = task { cmd("printf \"$indexOfRecepientKey\\n\" | gopass init --store=$storeName") } 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 393f94c..1095c33 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/GopassBridge.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/GopassBridge.kt @@ -10,7 +10,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackag import org.domaindrivenarchitecture.provs.framework.ubuntu.web.base.downloadFromURL -fun Prov.downloadGopassBridge() = def { +fun Prov.downloadGopassBridge() = task { val version = "0.8.0" val filename = "gopass_bridge-${version}-fx.xpi" val downloadDir = "${userHome()}Downloads/" @@ -23,7 +23,7 @@ fun Prov.downloadGopassBridge() = def { // needs manual install with: firefox Downloads/gopass_bridge-0.8.0-fx.xpi } -fun Prov.installGopassBridgeJsonApi() = def { +fun Prov.installGopassBridgeJsonApi() = task { // see https://github.com/gopasspw/gopass-jsonapi val gopassBridgeVersion = "1.11.1" val requiredGopassVersion = "1.12" @@ -69,7 +69,7 @@ fun Prov.installGopassBridgeJsonApi() = def { } } -fun Prov.configureGopassBridgeJsonApi() = def { +fun Prov.configureGopassBridgeJsonApi() = task { if (isPackageInstalled("gopass-jsonapi")) { // configure for firefox and choose default for each: // "Install for all users? [y/N/q]", diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NoSwappiness.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NoSwappiness.kt index 2c0d5f0..94ffb13 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NoSwappiness.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/NoSwappiness.kt @@ -4,7 +4,7 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.addTextToFile import java.io.File -fun Prov.configureNoSwappiness() = def { +fun Prov.configureNoSwappiness() = task { // set swappiness to 0 addTextToFile("vm.swappiness=0", File("/etc/sysctl.conf"), sudo = true) } \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Python.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Python.kt index b1f7756..1e384e1 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Python.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Python.kt @@ -5,7 +5,7 @@ import org.domaindrivenarchitecture.provs.framework.core.ProvResult import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall -fun Prov.installPython() = def { +fun Prov.installPython() = task { installPython3() installVenv() installPybuilder() @@ -13,26 +13,26 @@ fun Prov.installPython() = def { installJupyterlab() } -fun Prov.installPython3(): ProvResult = def { +fun Prov.installPython3(): ProvResult = task { aptInstall("python3.8-venv python3-pip") } -fun Prov.installVenv(): ProvResult = def { +fun Prov.installVenv(): ProvResult = task { val venvHome = "~/.python/meissa" cmd("python3 -m venv " + venvHome) cmd("source " + venvHome + "/bin/activate") cmd("pip3 install pip --upgrade") } -fun Prov.installPybuilder(): ProvResult = def { +fun Prov.installPybuilder(): ProvResult = task { cmd("pip3 install pybuilder ddadevops pypandoc mockito coverage unittest-xml-reporting deprecation python_terraform " + "boto3") } -fun Prov.installRestClient(): ProvResult = def { +fun Prov.installRestClient(): ProvResult = task { cmd("pip3 install requests") } -fun Prov.installJupyterlab(): ProvResult = def { +fun Prov.installJupyterlab(): ProvResult = task { cmd("pip3 install jupyterlab pandas matplotlib") } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Redshift.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Redshift.kt index 2f5e5e2..4f90a48 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Redshift.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Redshift.kt @@ -6,12 +6,12 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.creat import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall -fun Prov.installRedshift() = def { +fun Prov.installRedshift() = task { aptInstall("redshift redshift-gtk") } -fun Prov.configureRedshift() = def { +fun Prov.configureRedshift() = task { aptInstall("redshift redshift-gtk") createDir(".config") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VSCode.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VSCode.kt index 348b77b..8d5827f 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VSCode.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VSCode.kt @@ -6,7 +6,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled -fun Prov.installVSC(vararg options: String) = requireAll { +fun Prov.installVSC(vararg options: String) = task { val clojureExtensions = arrayListOf("betterthantomorrow.calva", "martinklepsch.clojure-joker-linter", "DavidAnson.vscode-markdownlint") val pythonExtensions = arrayListOf("ms-python.python") @@ -29,13 +29,13 @@ fun Prov.installVSC(vararg options: String) = requireAll { } -private fun Prov.prerequisitesVSCinstall() = def { +private fun Prov.prerequisitesVSCinstall() = task { aptInstall("curl gpg unzip apt-transport-https") } @Suppress("unused") // only required for installation of vscode via apt -private fun Prov.installVscWithApt() = requireAll { +private fun Prov.installVscWithApt() = task { val packageName = "code" if (!isPackageInstalled(packageName)) { // see https://code.visualstudio.com/docs/setup/linux @@ -53,14 +53,14 @@ private fun Prov.installVscWithApt() = requireAll { } -private fun Prov.installVSCPackage() = def { +private fun Prov.installVSCPackage() = task { cmd("sudo snap install code --classic") // to install via apt use: // installVscWithApt() } -private fun Prov.installVSCodiumPackage() = def { +private fun Prov.installVSCodiumPackage() = task { cmd("sudo snap install codium --classic") } @@ -84,7 +84,7 @@ private fun Prov.installExtensionsCodium(extensions: List) = optional { } -internal fun Prov.provisionAdditionalTools() = requireAll { +internal fun Prov.provisionAdditionalTools() = task { // Joker val version = "0.18.0" cmd("curl -Lo joker-${version}-linux-amd64.zip https://github.com/candid82/joker/releases/download/v${version}/joker-${version}-linux-amd64.zip") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VirtualBoxGuest.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VirtualBoxGuest.kt index 650a214..63db5c4 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VirtualBoxGuest.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/VirtualBoxGuest.kt @@ -5,14 +5,14 @@ import org.domaindrivenarchitecture.provs.framework.core.ProvResult import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami -fun Prov.installVirtualBoxGuestAdditions() = def { +fun Prov.installVirtualBoxGuestAdditions() = task { // if running in a VirtualBox vm if (!chk("lspci | grep VirtualBox")) { - return@def ProvResult(true, "Not running in a VirtualBox") + return@task ProvResult(true, "Not running in a VirtualBox") } if (chk("VBoxService --version")) { - return@def ProvResult(true, "VBoxService already installed") + return@task ProvResult(true, "VBoxService already installed") } // install guest additions diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Zim.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Zim.kt index 38e81ab..49880f1 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Zim.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/Zim.kt @@ -7,7 +7,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled -fun Prov.installZimWiki() = def { +fun Prov.installZimWiki() = task { if (isPackageInstalled("zim")) { ProvResult(true, out = "zim already installed.") } else { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt index daaa2c9..17bbd3a 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/Prov.kt @@ -78,6 +78,7 @@ open class Prov protected constructor( * defines a task with default success behavior, i.e. returns success if all subtasks finished with success. * Same as requireAll. */ + @Deprecated("Use function task instead", replaceWith = ReplaceWith("task()")) fun def(a: Prov.() -> ProvResult): ProvResult { return handle(ResultMode.ALL) { a() } } @@ -99,6 +100,7 @@ open class Prov protected constructor( /** * defines a task, which returns success if all subtasks finished with success */ + @Suppress("unused") fun requireAll(a: Prov.() -> ProvResult): ProvResult { return handle(ResultMode.ALL) { a() } } @@ -216,7 +218,7 @@ open class Prov protected constructor( * Adds a ProvResult to the overall success evaluation. * Intended for use in methods which do not automatically add results. */ - fun addResultToEval(result: ProvResult) = requireAll { + fun addResultToEval(result: ProvResult) = task { result } @@ -225,7 +227,7 @@ open class Prov protected constructor( * Multi-line commands within the script are not supported. * Empty lines and comments (all text behind # in a line) are supported, i.e. they are ignored. */ - fun sh(script: String, dir: String? = null, sudo: Boolean = false) = def { + fun sh(script: String, dir: String? = null, sudo: Boolean = false) = task { val lines = script.trimIndent().replace("\\\n", "").replace("\r\n", "\n").split("\n") val linesWithoutComments = lines.stream().map { it.split("#")[0] } val linesNonEmpty = linesWithoutComments.filter { it.trim().isNotEmpty() } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDocker.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDocker.kt index 11d6636..e6b6f04 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDocker.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDocker.kt @@ -55,13 +55,13 @@ fun UbuntuProv.runContainerPlatform( containerName: String = "defaultProvContainer", imageName: String = "ubuntu", sudo: Boolean = true -) = def { +) = task { val dockerCmd = dockerCommand(sudo) cmd(dockerCmd + "run -dit --name=$containerName $imageName") } -fun UbuntuProv.containerExecPlatform(containerName: String, cmd: String, sudo: Boolean = true) = def { +fun UbuntuProv.containerExecPlatform(containerName: String, cmd: String, sudo: Boolean = true) = task { val dockerCmd = dockerCommand(sudo) cmd(dockerCmd + "exec $containerName $cmd") } @@ -96,7 +96,7 @@ fun UbuntuProv.dockerImageExistsPlatform(imageName: String, sudo: Boolean): Bool fun UbuntuProv.exitAndRmContainerPlatform( containerName: String, sudo: Boolean -) = requireAll { +) = task { val dockerCmd = dockerCommand(sudo) if (containerRuns(containerName)) { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/platforms/UbuntuProv.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/platforms/UbuntuProv.kt index 9d59e7e..ff3e0e0 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/platforms/UbuntuProv.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/platforms/UbuntuProv.kt @@ -23,7 +23,7 @@ class UbuntuProv internal constructor( } } - override fun cmd(cmd: String, dir: String?, sudo: Boolean): ProvResult = def { + override fun cmd(cmd: String, dir: String?, sudo: Boolean): ProvResult = task { exec(SHELL, "-c", commandWithDirAndSudo(cmd, dir, sudo)) } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/HelloWorld.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/HelloWorld.kt index 864f350..28a5e0d 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/HelloWorld.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/HelloWorld.kt @@ -4,7 +4,7 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.local -fun Prov.helloWorld() = def { +fun Prov.helloWorld() = task { cmd("echo Hello world!") } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/SystemInfos.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/SystemInfos.kt index 47b4456..bac7f76 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/SystemInfos.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/demos/SystemInfos.kt @@ -19,14 +19,14 @@ fun main(vararg args: String) { if (args.size !in 2..3) { println("Wrong number of arguments. Please specify either host and user if connection is done by ssh key or otherwise host, user and password. E.g. 172.0.0.123 username password") } else { - val password = if (args.size == 2) null else Secret(args[3]) + val password = if (args.size == 2) null else Secret(args[2]) remote(args[0], args[1], password = password).printInfos() } } } -fun Prov.printInfos() = def { +fun Prov.printInfos() = task { println("\nUbuntu Version:\n${ubuntuVersion()}") println("\nCurrent directory:\n${currentDir()}") println("\nTime zone:\n${timeZone()}") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/certbot/ProvisionCertbot.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/certbot/ProvisionCertbot.kt index a610ceb..e020c14 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/certbot/ProvisionCertbot.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/certbot/ProvisionCertbot.kt @@ -10,7 +10,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta * Provisions a certbot for the specified serverName and email to obtain and renew letsencrypt certificates * Parameter can be used to specify certbot options e.g. "--nginx" to configure nginx, see https://certbot.eff.org/docs/using.html#certbot-command-line-options */ -fun Prov.provisionCertbot(serverName: String, email: String?, additionalOptions: String? = "") = requireAll { +fun Prov.provisionCertbot(serverName: String, email: String?, additionalOptions: String? = "") = task { aptInstall("snapd") sh(""" sudo snap install core; sudo snap refresh core diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewall.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewall.kt index 33456ce..3c1dd7c 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewall.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewall.kt @@ -5,7 +5,7 @@ import org.domaindrivenarchitecture.provs.framework.core.ProvResult import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall -fun Prov.saveIpTables() = requireAll { +fun Prov.saveIpTables() = task { sh(""" iptables-save > /etc/iptables/rules.v4 ip6tables-save > /etc/iptables/rules.v6 @@ -15,7 +15,8 @@ fun Prov.saveIpTables() = requireAll { } -fun Prov.makeIpTablesPersistent() = requireAll { +@Suppress("unused") +fun Prov.makeIpTablesPersistent() = task { // inspired by https://gist.github.com/alonisser/a2c19f5362c2091ac1e7 // enables iptables-persistent to be installed without manual input sh(""" @@ -28,7 +29,8 @@ fun Prov.makeIpTablesPersistent() = requireAll { } -fun Prov.resetFirewall() = requireAll { +@Suppress("unused") +fun Prov.resetFirewall() = task { sh(""" #!/bin/bash sudo iptables -F @@ -50,7 +52,7 @@ fun Prov.resetFirewall() = requireAll { } -fun Prov.provisionFirewall(addNetworkProtections: Boolean = false) = requireAll { +fun Prov.provisionFirewall(addNetworkProtections: Boolean = false) = task { if (addNetworkProtections) { networkProtections() } @@ -111,7 +113,7 @@ fun Prov.provisionFirewall(addNetworkProtections: Boolean = false) = requireAll } -fun Prov.networkProtections() = def { +fun Prov.networkProtections() = task { sh(""" # Drop ICMP echo-request messages sent to broadcast or multicast addresses echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts @@ -137,7 +139,7 @@ fun Prov.networkProtections() = def { } -fun Prov.ipTablesRecreateDockerRules() = requireAll { +fun Prov.ipTablesRecreateDockerRules() = task { // see https://stackoverflow.com/questions/25917941/docker-how-to-re-create-dockers-additional-iptables-rules cmd("sudo service docker restart") } \ No newline at end of file diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/base/FirewallBackup.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/base/FirewallBackup.kt index 21aace3..a9d5dc0 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/base/FirewallBackup.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/base/FirewallBackup.kt @@ -6,7 +6,7 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter -fun Prov.saveIpTablesToFile() = def { +fun Prov.saveIpTablesToFile() = task { val dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("-yyyy-MM-dd--HH:mm:ss")) val file = "savedrules$dateTime.txt" sh(""" @@ -14,7 +14,7 @@ fun Prov.saveIpTablesToFile() = def { cat $file""") } -fun Prov.restoreIpTablesFromFile(file: String? = null) = def { +fun Prov.restoreIpTablesFromFile(file: String? = null) = task { val fileName = file ?: cmd("ls -r a* | head -1\n").out fileName?.let { cmd("sudo iptables-restore < $file") } ?: ProvResult(false, err = "File to restore not found.") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexus.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexus.kt index fc9ab33..f6edc88 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexus.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexus.kt @@ -18,7 +18,7 @@ import org.domaindrivenarchitecture.provs.framework.extensions.server_software.s * If you would want nexus to be accessible directly from the internet (e.g. for test or demo reasons) * set parameter portAccessibleFromNetwork to true. */ -fun Prov.provisionNexusWithDocker(portAccessibleFromNetwork: Boolean = false) = requireAll { +fun Prov.provisionNexusWithDocker(portAccessibleFromNetwork: Boolean = false) = task { // https://blog.sonatype.com/sonatype-nexus-installation-using-docker // https://medium.com/@AhGh/how-to-setup-sonatype-nexus-3-repository-manager-using-docker-7ff89bc311ce aptInstall("docker.io") @@ -66,10 +66,10 @@ private fun Prov.getDefaultNetworkingInterface(): String? { @Suppress("unused") // to be used externally fun provisionNexusServer(serverName: String, certbotEmail: String) { val userName = "nexus" + 7 - remote(serverName, "root").def { + remote(serverName, "root").task { createUser(userName, copyAuthorizedSshKeysFromCurrentUser = true, sudo = true) } - remote(serverName, userName).requireAll { + remote(serverName, userName).task { provisionNexusWithDocker() if (provisionNginxStandAlone(NginxConf.nginxReverseProxyHttpConfig(serverName)).success) { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginx.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginx.kt index bf9f710..643ecf4 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginx.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginx.kt @@ -12,7 +12,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta internal const val NGINX_CONFIG_FILE = "/etc/nginx/nginx.conf" -fun Prov.provisionNginxStandAlone(config: NginxConf? = null) = requireAll { +fun Prov.provisionNginxStandAlone(config: NginxConf? = null) = task { aptInstall("nginx") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/BasicAuth.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/BasicAuth.kt deleted file mode 100644 index 7b20fb0..0000000 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/BasicAuth.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.domaindrivenarchitecture.provs.framework.extensions.server_software.standalone_server.nginx.base - -import org.domaindrivenarchitecture.provs.framework.core.Prov -import org.domaindrivenarchitecture.provs.framework.core.Secret -import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall - -fun Prov.nginxAddBasicAuth(user: String, password: Secret) = requireAll { - aptInstall("apache2-utils") - val passwordFile = "/etc/nginx/.htpasswd" - cmdNoLog("sudo htpasswd -b -c $passwordFile $user ${password.plain()}") -} - diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/Locations.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/Locations.kt index 3919ce1..55b29b6 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/Locations.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/Locations.kt @@ -1,8 +1,8 @@ package org.domaindrivenarchitecture.provs.framework.extensions.server_software.standalone_server.nginx.base import org.domaindrivenarchitecture.provs.framework.core.Prov -import org.domaindrivenarchitecture.provs.framework.core.ProvResult -import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.* +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs +import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.replaceTextInFile internal const val locationsAvailableDir = "/etc/nginx/locations-available/" @@ -10,35 +10,16 @@ internal const val locationsEnabledDir = "/etc/nginx/locations-enabled/" internal const val locationsFileExtension = ".locations" -fun Prov.createNginxLocationFolders() = requireAll { +fun Prov.createNginxLocationFolders() = task { createDirs(locationsEnabledDir, sudo = true) createDirs(locationsAvailableDir, sudo = true) } -fun Prov.nginxIncludeLocationFolders() = requireAll { +fun Prov.nginxIncludeLocationFolders() = task { replaceTextInFile("/etc/nginx/nginx.conf", "listen 80;\n", """listen 80; include ${locationsAvailableDir}port80*$locationsFileExtension; include ${locationsEnabledDir}port443*$locationsFileExtension; """) } - - -fun Prov.nginxAddLocation(port: String, locationFileName: String, urlPath: String, content: String) = requireAll { - - val locationConf = """location $urlPath {""" + - content + - "\n}" - - if (!dirExists(locationsAvailableDir, sudo = true)) { - createNginxLocationFolders() - } - - createFile("${locationsAvailableDir}port${port}_$locationFileName$locationsFileExtension", locationConf, sudo = true) - if (!fileExists("${locationsEnabledDir}port${port}_$locationFileName$locationsFileExtension", sudo = true)) { - cmd("sudo ln -s ${locationsAvailableDir}port${port}_$locationFileName$locationsFileExtension ${locationsEnabledDir}port${port}_$locationFileName$locationsFileExtension ") - } else { - ProvResult(true) - } -} diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/SelfSignedCertificate.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/SelfSignedCertificate.kt index cec576d..a5e3cd5 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/SelfSignedCertificate.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/base/SelfSignedCertificate.kt @@ -2,7 +2,6 @@ package org.domaindrivenarchitecture.provs.framework.extensions.server_software. import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createDirs -import org.domaindrivenarchitecture.provs.framework.extensions.server_software.standalone_server.nginx.provisionNginxStandAlone internal val certificateName = "selfsigned" @@ -19,18 +18,10 @@ fun Prov.nginxCreateSelfSignedCertificate( organizationalUnit: String = "test", commonName: String = "test", email : String = "test@test.net" -) = def { +) = task { // inspired by https://gist.github.com/adrianorsouza/2bbfe5e197ce1c0b97c8 createDirs(dirSslCert, sudo = true) createDirs(dirSslKey, sudo = true) cmd("cd $dirSslKey && sudo openssl req -x509 -nodes -newkey rsa:2048 -keyout $certificateName.key -out $certificateName.crt -days $sslDays -subj \"/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalUnit/CN=$commonName/emailAddress=$email\"") cmd("sudo mv $dirSslKey/$certificateName.crt $dirSslCert/") } - - -fun Prov.configureNginxWithSelfSignedCertificate() = def { - // todo: should not call provisionNginxStandAlone, which is defined in the package above - provisionNginxStandAlone(NginxConf.nginxReverseProxySslConfig("localhost", - dirSslCert+"/"+ certificateName + ".crt", - dirSslKey + "/" + certificateName + ".key")) -} diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/ProvisionPrometheus.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/ProvisionPrometheus.kt index 28a94ac..ab7784c 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/ProvisionPrometheus.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/ProvisionPrometheus.kt @@ -8,7 +8,8 @@ import org.domaindrivenarchitecture.provs.framework.extensions.server_software.s * If running behind an nginx, pls specify the hostname in parameter nginxHost (e.g. mydomain.com). * To run it without nodeExporter (which provides system data to prometheus), set withNodeExporter to false. */ -fun Prov.provisionPrometheusDocker(nginxHost: String? = null, withNodeExporter: Boolean = true) = def { +@Suppress("unused") +fun Prov.provisionPrometheusDocker(nginxHost: String? = null, withNodeExporter: Boolean = true) = task { configurePrometheusDocker() if (withNodeExporter) { installNodeExporter() diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/NodeExporter.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/NodeExporter.kt index fed0986..d9b256d 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/NodeExporter.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/NodeExporter.kt @@ -12,7 +12,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami internal val defaultInstallationDir = "/usr/local/bin/" -fun Prov.installNodeExporter() = requireAll { +fun Prov.installNodeExporter() = task { // inspired by https://devopscube.com/monitor-linux-servers-prometheus-node-exporter/ and // https://www.howtoforge.com/tutorial/how-to-install-prometheus-and-node-exporter-on-centos-8/#step-install-and-configure-nodeexporter val downloadFileBasename = "node_exporter-1.0.1.linux-amd64" @@ -33,7 +33,7 @@ fun Prov.installNodeExporter() = requireAll { } -fun Prov.runNodeExporter() = def { +fun Prov.runNodeExporter() = task { createFile("/etc/systemd/system/node_exporter.service", nodeExporterServiceConf(whoami()?:"nouserfound"), sudo = true) sh(""" @@ -52,7 +52,7 @@ fun Prov.runNodeExporter() = def { fun Prov.addNodeExporterToPrometheusConf ( prometheusConf: String = "/etc/prometheus/prometheus.yml", sudo: Boolean = true -) = requireAll { +) = task { val prometheusConfNodeExporter = """ scrape_configs: - job_name: 'node_exporter' diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/Prometheus.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/Prometheus.kt index 95496f2..f55b5f6 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/Prometheus.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/prometheus/base/Prometheus.kt @@ -11,13 +11,13 @@ internal val configDir = "/etc/prometheus/" internal val configFile = "prometheus.yml" -fun Prov.configurePrometheusDocker(config: String = prometheusDefaultConfig) = requireAll { +fun Prov.configurePrometheusDocker(config: String = prometheusDefaultConfig) = task { createDirs(configDir, sudo = true) createFile(configDir + configFile, config, sudo = true) } -fun Prov.runPrometheusDocker(nginxHost: String? = null) = requireAll { +fun Prov.runPrometheusDocker(nginxHost: String? = null) = task { aptInstall("docker.io") val containerName = "prometheus" diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt index 3d973f6..4b43fad 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/filesystem/base/Filesystem.kt @@ -23,7 +23,7 @@ fun Prov.createFileFromResource( resourcePath: String = "", posixFilePermission: String? = null, sudo: Boolean = false -): ProvResult = def { +): ProvResult = task { createFile( fullyQualifiedFilename, getResourceAsText(resourcePath.endingWithFileSeparator() + resourceFilename), @@ -43,7 +43,7 @@ fun Prov.createFileFromResourceTemplate( values: Map, posixFilePermission: String? = null, sudo: Boolean = false -): ProvResult = def { +): ProvResult = task { createFile( fullyQualifiedFilename, getResourceAsText(resourcePath.endingWithFileSeparator() + resourceFilename).resolve(values), @@ -62,7 +62,7 @@ fun Prov.copyFileFromLocal( fullyQualifiedLocalFilename: String, posixFilePermission: String? = null, sudo: Boolean = false -): ProvResult = def { +): ProvResult = task { createFile( fullyQualifiedFilename, getLocalFileContent(fullyQualifiedLocalFilename), @@ -117,7 +117,7 @@ fun Prov.createSecretFile( fullyQualifiedFilename: String, secret: Secret, posixFilePermission: String? = null -): ProvResult = def { +): ProvResult = task { posixFilePermission?.let { ensureValidPosixFilePermission(posixFilePermission) cmd("install -m $posixFilePermission /dev/null $fullyQualifiedFilename") @@ -126,7 +126,7 @@ fun Prov.createSecretFile( } -fun Prov.deleteFile(file: String, path: String? = null, sudo: Boolean = false): ProvResult = def { +fun Prov.deleteFile(file: String, path: String? = null, sudo: Boolean = false): ProvResult = task { val fullyQualifiedFilename = (path?.normalizePath() ?: "") + file if (fileExists(fullyQualifiedFilename, sudo = sudo)) { cmd(prefixWithSudo("rm $fullyQualifiedFilename", sudo)) @@ -140,9 +140,9 @@ fun Prov.fileContainsText(file: String, content: String, sudo: Boolean = false): // todo consider grep e.g. for content without newlines // return cmdNoEval(prefixWithSudo("grep -- '${content.escapeSingleQuote()}' $file", sudo)).success val fileContent = fileContent(file, sudo = sudo) - return if (fileContent == null) + return if (fileContent == null) { false - else + } else fileContent.contains(content) } @@ -166,10 +166,10 @@ fun Prov.addTextToFile( doNotAddIfExisting: Boolean = true, sudo: Boolean = false ): ProvResult = - def { + task { val fileContainsText = fileContainsText(file.path, text, sudo = sudo) if (fileContainsText && doNotAddIfExisting) { - return@def ProvResult(true, out = "Text already in file") + return@task ProvResult(true, out = "Text already in file") } cmd( "printf '%s' " + text @@ -178,12 +178,12 @@ fun Prov.addTextToFile( } -fun Prov.replaceTextInFile(file: String, oldText: String, replacement: String) = def { +fun Prov.replaceTextInFile(file: String, oldText: String, replacement: String) = task { replaceTextInFile(file, Regex.fromLiteral(oldText), Regex.escapeReplacement(replacement)) } -fun Prov.replaceTextInFile(file: String, oldText: Regex, replacement: String) = def { +fun Prov.replaceTextInFile(file: String, oldText: Regex, replacement: String) = task { // todo: only use sudo for root or if owner different from current val content = fileContent(file, true) if (content != null) { @@ -195,7 +195,7 @@ fun Prov.replaceTextInFile(file: String, oldText: Regex, replacement: String) = } -fun Prov.insertTextInFile(file: String, textBehindWhichToInsert: Regex, textToInsert: String) = def { +fun Prov.insertTextInFile(file: String, textBehindWhichToInsert: Regex, textToInsert: String) = task { // todo: only use sudo for root or if owner different from current val content = fileContent(file, true) if (content != null) { @@ -231,7 +231,7 @@ fun Prov.createDir( path: String = "~/", failIfExisting: Boolean = false, sudo: Boolean = false -): ProvResult = def { +): ProvResult = task { if (!failIfExisting && dirExists(dir, path, sudo)) { ProvResult(true) } else { @@ -246,7 +246,7 @@ fun Prov.createDirs( path: String = "~/", failIfExisting: Boolean = false, sudo: Boolean = false -): ProvResult = def { +): ProvResult = task { if (!failIfExisting && dirExists(dirs, path, sudo)) { ProvResult(true) } else { diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/ProvisionGit.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/ProvisionGit.kt index 6e13668..bac993c 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/ProvisionGit.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/ProvisionGit.kt @@ -10,7 +10,7 @@ fun Prov.provisionGit( email: String? = null, signingKey: String? = null, diffTool: String? = null -): ProvResult = def { +): ProvResult = task { aptInstall("git") diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/base/Git.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/base/Git.kt index b74ca3d..b96991e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/base/Git.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/git/base/Git.kt @@ -10,11 +10,11 @@ import java.io.File val knownHostsFile = "~/.ssh/known_hosts" -fun Prov.gitClone(repo: String, path: String, pullIfExisting: Boolean = true): ProvResult = def { +fun Prov.gitClone(repo: String, path: String, pullIfExisting: Boolean = true): ProvResult = task { val dir = cmdNoEval("basename $repo .git").out?.trim() if (dir == null) { - return@def ProvResult(false, err = "$repo is not a valid git repository") + return@task ProvResult(false, err = "$repo is not a valid git repository") } val pathToDir = if (path.endsWith("/")) path + dir else path + "/" + dir @@ -30,7 +30,7 @@ fun Prov.gitClone(repo: String, path: String, pullIfExisting: Boolean = true): P } -fun Prov.trustGithub() = def { +fun Prov.trustGithub() = task { // current fingerprints from https://docs.github.com/en/github/authenticating-to-github/githubs-ssh-key-fingerprints val fingerprints = setOf( "SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 github.com", // (RSA) @@ -42,7 +42,7 @@ fun Prov.trustGithub() = def { } -fun Prov.trustGitlab() = def { +fun Prov.trustGitlab() = task { // entries for known_hosts from https://docs.gitlab.com/ee/user/gitlab_com/ val gitlabFingerprints = """ gitlab.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf @@ -59,9 +59,9 @@ fun Prov.trustGitlab() = def { * Note: adding keys automatically is vulnerable to a man-in-the-middle attack and not considered secure. */ // todo: consider making function public and moving to ssh package -private fun Prov.trustHost(host: String, fingerprintsOfKeysToBeAdded: Set?) = def { +private fun Prov.trustHost(host: String, fingerprintsOfKeysToBeAdded: Set?) = task { if (isHostKnown(host)) { - return@def ProvResult(true, out = "Host already known") + return@task ProvResult(true, out = "Host already known") } if (!fileExists(knownHostsFile)) { createDir(".ssh") @@ -74,7 +74,7 @@ private fun Prov.trustHost(host: String, fingerprintsOfKeysToBeAdded: Set> ~/.ssh/known_hosts") } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt index 7e9a464..26ae331 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/user/base/User.kt @@ -27,7 +27,7 @@ fun Prov.createUser( password: Secret? = null, sudo: Boolean = false, copyAuthorizedSshKeysFromCurrentUser: Boolean = false -): ProvResult = requireAll { +): ProvResult = task { if (!userExists(userName)) { cmd("sudo adduser --gecos \"First Last,RoomNumber,WorkPhone,HomePhone\" --disabled-password --home /home/$userName $userName") } @@ -54,7 +54,7 @@ fun Prov.createUser( * Installs and configures git for the user if gitEmail is provided in the config. * Does NOT CREATE the user. */ -fun Prov.configureUser(config: UserConfig) = requireAll { +fun Prov.configureUser(config: UserConfig) = task { provisionKeys( config.gpg?.keyPair(), config.ssh?.keyPair() @@ -70,7 +70,7 @@ fun Prov.configureUser(config: UserConfig) = requireAll { @Suppress("unused") -fun Prov.deleteUser(userName: String, deleteHomeDir: Boolean = false): ProvResult = requireAll { +fun Prov.deleteUser(userName: String, deleteHomeDir: Boolean = false): ProvResult = task { val flagToDeleteHomeDir = if (deleteHomeDir) " -r " else "" if (userExists(userName)) { cmd("sudo userdel $flagToDeleteHomeDir $userName") @@ -89,7 +89,7 @@ fun Prov.makeUserSudoerWithNoSudoPasswordRequired( userName: String, password: Secret? = null, overwriteFile: Boolean = false -): ProvResult = def { +): ProvResult = task { val userSudoFile = "/etc/sudoers.d/$userName" if (!fileExists(userSudoFile) || overwriteFile) { val sudoPrefix = if (password == null) "sudo" else "echo ${password.plain()} | sudo -S" @@ -108,7 +108,7 @@ fun Prov.makeUserSudoerWithNoSudoPasswordRequired( * IMPORTANT: Current user must already by sudoer when calling this function. */ @Suppress("unused") // used externally -fun Prov.makeUserSudoerWithNoSudoPasswordRequired(password: Secret) = def { +fun Prov.makeUserSudoerWithNoSudoPasswordRequired(password: Secret) = task { val currentUser = whoami() if (currentUser != null) { makeUserSudoerWithNoSudoPasswordRequired(currentUser, password, overwriteFile = true) @@ -153,7 +153,7 @@ fun Prov.whoami(): String? { * @hostPassword pw of hostUser on the remote system; * ssh-key authentication will be used if hostPassword is null */ -@Suppress("api") // use externally +@Suppress("unused") // use externally fun createRemoteUser( host: InetAddress, hostUser: String, diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt index afd79f9..c64ab48 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOpsKtTest.kt @@ -13,7 +13,7 @@ internal class DevOpsKtTest { @ExtensiveContainerTest fun installKubectlAndTools() { // given - defaultTestContainer().def { + defaultTestContainer().task { createDirs("/etc/bash_completion.d", sudo = true) createDir(".bashrc.d") } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt index 3ee756e..7a41311 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/ProvTest.kt @@ -15,11 +15,11 @@ import java.io.PrintStream internal class ProvTest { - private fun Prov.def_returnungFalse() = def { + private fun Prov.task_returningFalse() = task { ProvResult(false) } - private fun Prov.def_returningTrue() = def { + private fun Prov.task_returningTrue() = task { ProvResult(true) } @@ -74,178 +74,178 @@ internal class ProvTest { } @Test - fun def_modeOptional_result_true() { + fun task_modeOptional_result_true() { // given - fun Prov.tst_def() = optional { - def_returnungFalse() - def_returningTrue() - def_returnungFalse() + fun Prov.tst_task() = optional { + task_returningFalse() + task_returningTrue() + task_returningFalse() } // when - val res = testLocal().tst_def().success + val res = testLocal().tst_task().success // then assert(res) } @Test - fun def_modeLast_result_true() { + fun task_modeLast_result_true() { // given - fun Prov.tst_def() = requireLast { - def_returnungFalse() - def_returningTrue() + fun Prov.tst_task() = requireLast { + task_returningFalse() + task_returningTrue() } // when - val res = testLocal().tst_def().success + val res = testLocal().tst_task().success // then assert(res) } @Test - fun def_modeLast_result_false() { + fun task_modeLast_result_false() { // given - fun Prov.tst_def() = requireLast { - def_returningTrue() - def_returnungFalse() + fun Prov.tst_task() = requireLast { + task_returningTrue() + task_returningFalse() } // when - val res = testLocal().tst_def().success + val res = testLocal().tst_task().success // then assert(!res) } @Test - fun def_mode_ALL_result_true() { + fun task_mode_ALL_result_true() { // given - fun Prov.tst_def_all_true_mode_ALL() = requireAll { - def_returningTrue() - def_returningTrue() + fun Prov.tst_task_all_true_mode_ALL() = task { + task_returningTrue() + task_returningTrue() } // when - val res = testLocal().tst_def_all_true_mode_ALL().success + val res = testLocal().tst_task_all_true_mode_ALL().success // then assert(res) } // given - fun Prov.tst_def_one_false_mode_ALL() = requireAll { - def_returningTrue() - def_returnungFalse() - def_returningTrue() + fun Prov.tst_task_one_false_mode_ALL() = task { + task_returningTrue() + task_returningFalse() + task_returningTrue() } @Test - fun def_modeALL_resultFalse() { + fun task_modeALL_resultFalse() { // when - val res = testLocal().tst_def_one_false_mode_ALL().success + val res = testLocal().tst_task_one_false_mode_ALL().success // then assert(!res) } // given - fun Prov.tst_def_one_false_mode_ALL_nested() = requireAll { - def_returningTrue() - tst_def_one_false_mode_ALL() - def_returningTrue() + fun Prov.tst_task_one_false_mode_ALL_nested() = task { + task_returningTrue() + tst_task_one_false_mode_ALL() + task_returningTrue() tst_ALL_returningTrue() } // given - fun Prov.tst_ALL_returningTrue() = requireAll { + fun Prov.tst_ALL_returningTrue() = task { ProvResult(true) } @Test - fun def_modeALLnested_resultFalse() { + fun task_modeALLnested_resultFalse() { // when - val res = testLocal().tst_def_one_false_mode_ALL_nested().success + val res = testLocal().tst_task_one_false_mode_ALL_nested().success // then assert(!res) } @Test - fun def_mode_ALL_LAST_NONE_nested() { + fun task_mode_ALL_LAST_NONE_nested() { // given - fun Prov.tst_def_last() = def { - def_returningTrue() - def_returnungFalse() + fun Prov.tst_task_last() = task { + task_returningTrue() + task_returningFalse() } - fun Prov.tst_def_one_false_mode_ALL() = requireAll { - tst_def_last() - def_returningTrue() + fun Prov.tst_task_one_false_mode_ALL() = task { + tst_task_last() + task_returningTrue() } // when - val res = testLocal().tst_def_one_false_mode_ALL().success + val res = testLocal().tst_task_one_false_mode_ALL().success // then assert(!res) } @Test - fun def_mode_FAILEXIT_nested_false() { + fun task_mode_FAILEXIT_nested_false() { // given - fun Prov.tst_def_failexit_inner() = exitOnFailure { - def_returningTrue() - def_returnungFalse() + fun Prov.tst_task_failexit_inner() = exitOnFailure { + task_returningTrue() + task_returningFalse() } - fun Prov.tst_def_failexit_outer() = exitOnFailure { - tst_def_failexit_inner() - def_returningTrue() + fun Prov.tst_task_failexit_outer() = exitOnFailure { + tst_task_failexit_inner() + task_returningTrue() } // when - val res = testLocal().tst_def_failexit_outer().success + val res = testLocal().tst_task_failexit_outer().success // then assert(!res) } @Test - fun def_mode_FAILEXIT_nested_true() { + fun task_mode_FAILEXIT_nested_true() { // given - fun Prov.tst_def_failexit_inner() = exitOnFailure { - def_returningTrue() - def_returningTrue() + fun Prov.tst_task_failexit_inner() = exitOnFailure { + task_returningTrue() + task_returningTrue() } - fun Prov.tst_def_failexit_outer() = exitOnFailure { - tst_def_failexit_inner() - def_returningTrue() + fun Prov.tst_task_failexit_outer() = exitOnFailure { + tst_task_failexit_inner() + task_returningTrue() } // when - val res = testLocal().tst_def_failexit_outer().success + val res = testLocal().tst_task_failexit_outer().success // then assert(res) } @Test - fun def_mode_multiple_nested() { + fun task_mode_multiple_nested() { // given - fun Prov.tst_nested() = def { - requireAll { - def_returningTrue() - def { - def_returnungFalse() - def_returningTrue() + fun Prov.tst_nested() = task { + task { + task_returningTrue() + task { + task_returningFalse() + task_returningTrue() } - def_returnungFalse() - def_returningTrue() + task_returningFalse() + task_returningTrue() optional { - def_returnungFalse() + task_returningFalse() } } } @@ -428,7 +428,7 @@ internal class ProvTest { addResultToEval(ProvResult(true)) } - fun Prov.outer() = requireAll { + fun Prov.outer() = task { inner() ProvResult(true) } @@ -485,7 +485,7 @@ internal class ProvTest { addResultToEval(ProvResult(false)) } - fun Prov.outer() = requireAll { + fun Prov.outer() = task { inner() ProvResult(true) } @@ -505,19 +505,19 @@ internal class ProvTest { val containerName = "provs_test" testLocal().provideContainer(containerName, "ubuntu") - fun Prov.inner() = def { + fun Prov.inner() = task { cmd("echo in container") } // then - fun Prov.outer() = def { + fun Prov.outer() = task { taskInContainer(containerName) { inner() cmd("echo testfile > testfile.txt") } } - val res = testLocal().def { outer() } + val res = testLocal().task { outer() } // then assertEquals(true, res.success) @@ -530,12 +530,12 @@ internal class ProvTest { val host = "192.168.56.135" val remoteUser = "az" - fun Prov.inner() = def { + fun Prov.inner() = task { cmd("echo 'in testfile' > testfile.txt") } // then - val res = remote(host, remoteUser).def { + val res = remote(host, remoteUser).task { inner() // executed on the remote host taskInContainer("prov_default") { inner() // executed in the container on the remote host diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt index 15736b7..185f588 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/core/docker/platforms/UbuntuHostDockerKtTest.kt @@ -18,7 +18,7 @@ internal class UbuntuHostDockerKtTest { fun runAndCheckAndExitContainer() { // when val containerName = "testContainer" - val result = testLocal().requireAll { + val result = testLocal().task { runContainer(containerName) addResultToEval(ProvResult(containerRuns(containerName))) diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewallKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewallKtTest.kt index 708912b..2c770a0 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewallKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/firewall/ProvisionFirewallKtTest.kt @@ -35,7 +35,7 @@ internal class ProvisionFirewallKtTest { ) // when - val res = a.requireAll { + val res = a.task { aptInstall("iptables") provisionFirewall() } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexusKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexusKtTest.kt index 75876cd..79538ac 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexusKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nexus/ProvisionNexusKtTest.kt @@ -15,7 +15,7 @@ internal class ProvisionNexusKtTest { val a = defaultTestContainer() // when - val res = a.requireAll { + val res = a.task { provisionNexusWithDocker() } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginxKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginxKtTest.kt index 8aa8d66..b5068ae 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginxKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/server_software/standalone_server/nginx/ProvisionNginxKtTest.kt @@ -34,7 +34,7 @@ internal class ProvisionNginxKtTest { a.aptInstall("curl") // when - val res = a.requireAll { + val res = a.task { provisionNginxStandAlone(NginxConf(config)) cmd("curl localhost") } @@ -51,7 +51,7 @@ internal class ProvisionNginxKtTest { val a = defaultTestContainer() // when - val res = a.requireAll { + val res = a.task { provisionNginxStandAlone() } @@ -65,7 +65,7 @@ internal class ProvisionNginxKtTest { fun provisionNginxStandAlone_sslConfig() { // given val a = defaultTestContainer() - a.def { + a.task { val file = "/etc/ssl/openssl.cnf" if (fileExists(file)) { replaceTextInFile(file, "RANDFILE", "#RANDFILE") @@ -74,7 +74,7 @@ internal class ProvisionNginxKtTest { } // when - val res = a.def { + val res = a.task { nginxCreateSelfSignedCertificate() provisionNginxStandAlone( diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/FakturamaKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/FakturamaKtTest.kt index a03ed88..1cfe016 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/FakturamaKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/FakturamaKtTest.kt @@ -12,7 +12,7 @@ internal class FakturamaKtTest { // given val a = defaultTestContainer() // when - val res = a.def { installFakturama() } + val res = a.task { installFakturama() } // then assertTrue(res.success) } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassBridgeKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassBridgeKtTest.kt index 5a1f3be..631d94d 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassBridgeKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassBridgeKtTest.kt @@ -47,7 +47,7 @@ internal class GopassBridgeKtTest { // given local().exitAndRmContainer("provs_test") val a = defaultTestContainer() - val preparationResult = a.def { + val preparationResult = a.task { aptInstallCurl() configureGpgKeys( KeyPair(Secret(publicGPGSnakeoilKey()), Secret(privateGPGSnakeoilKey())), @@ -65,7 +65,7 @@ internal class GopassBridgeKtTest { assertTrue(preparationResult.success) // when - val res = a.def { + val res = a.task { installGopassBridgeJsonApi() configureGopassBridgeJsonApi() } @@ -81,7 +81,7 @@ internal class GopassBridgeKtTest { fun test_install_GopassBridgeJsonApi_with_incompatible_gopass_jsonapi_version_installed() { // given val a = defaultTestContainer(ContainerStartMode.CREATE_NEW_KILL_EXISTING) - val preparationResult = a.def { + val preparationResult = a.task { aptInstallCurl() configureGpgKeys( @@ -100,7 +100,7 @@ internal class GopassBridgeKtTest { assertTrue(preparationResult.success) // when - val res = a.def { + val res = a.task { installGopassBridgeJsonApi() configureGopassBridgeJsonApi() } @@ -116,7 +116,7 @@ internal class GopassBridgeKtTest { fun test_install_GopassBridgeJsonApi_with_incompatible_gopass_version_installed() { // given val a = defaultTestContainer(ContainerStartMode.CREATE_NEW_KILL_EXISTING) - val preparationResult = a.def { + val preparationResult = a.task { aptInstallCurl() configureGpgKeys( KeyPair(Secret(publicGPGSnakeoilKey()), Secret(privateGPGSnakeoilKey())), @@ -134,7 +134,7 @@ internal class GopassBridgeKtTest { assertTrue(preparationResult.success) // when - val res = a.def { + val res = a.task { installGopassBridgeJsonApi() configureGopassBridgeJsonApi() } @@ -143,7 +143,7 @@ internal class GopassBridgeKtTest { assertFalse(res.success) } - private fun Prov.aptInstallCurl() = def { + private fun Prov.aptInstallCurl() = task { cmd("apt-get update", sudo = true) aptInstall("curl") } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassKtTest.kt index 49852a4..8927c19 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/framework/extensions/workplace/base/GopassKtTest.kt @@ -79,7 +79,7 @@ internal class GopassKtTest { val a = remote(host, user) // when - val res = a.def { + val res = a.task { configureGpgKeys( KeyPair( pubKey,