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)