From 082c0827e3f1495c0a1fe6ba6a0e7c11d1bd6326 Mon Sep 17 00:00:00 2001 From: az Date: Sun, 26 Feb 2023 19:32:44 +0100 Subject: [PATCH] [skip ci] make makeUserSudoerWithoutPasswordRequired taskWithResult --- .../provs/framework/core/cli/CliUtils.kt | 6 +++--- .../provs/framework/ubuntu/user/base/User.kt | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt index f3be177..f229ac9 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/core/cli/CliUtils.kt @@ -7,7 +7,7 @@ import org.domaindrivenarchitecture.provs.framework.core.local import org.domaindrivenarchitecture.provs.framework.core.remote import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.secretSources.PromptSecretSource import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.currentUserCanSudoWithoutPassword -import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.makeUserSudoerWithoutPasswordRequired +import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.makeCurrentUserSudoerWithoutPasswordRequired import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami import kotlin.system.exitProcess @@ -50,7 +50,7 @@ private fun createLocalProvInstance(): Prov { "Please enter password to configure sudo without password in the future." + "\nWarning: This will permanently allow your user to use sudo privileges without a password." ).secret() - prov.makeUserSudoerWithoutPasswordRequired(password) + prov.makeCurrentUserSudoerWithoutPasswordRequired(password) } return prov } @@ -76,7 +76,7 @@ private fun createRemoteProvInstance( require( password != null, { "User ${prov.whoami()} not able to sudo on remote machine without password and no password available for the user." }) - prov.makeUserSudoerWithoutPasswordRequired(password) + prov.makeCurrentUserSudoerWithoutPasswordRequired(password) // a new session is required after making the user a sudoer without password return remote(host, remoteUser, password) 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 cd5978b..1405542 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 @@ -89,7 +89,7 @@ fun Prov.makeUserSudoerWithoutPasswordRequired( userName: String, password: Secret? = null, overwriteFile: Boolean = false -): ProvResult = task { +): ProvResult = taskWithResult { val userSudoFile = "/etc/sudoers.d/$userName" if (!checkFile(userSudoFile) || overwriteFile) { val sudoPrefix = if (password == null) "sudo" else "echo ${password.plain()} | sudo -S" @@ -107,8 +107,7 @@ fun Prov.makeUserSudoerWithoutPasswordRequired( * Makes the current (executing) user be able to sudo without password. * IMPORTANT: Current user must already by sudoer when calling this function. */ -@Suppress("unused") // used externally -fun Prov.makeUserSudoerWithoutPasswordRequired(password: Secret) = task { +fun Prov.makeCurrentUserSudoerWithoutPasswordRequired(password: Secret) = taskWithResult { val currentUser = whoami() if (currentUser != null) { makeUserSudoerWithoutPasswordRequired(currentUser, password, overwriteFile = true)