[skip ci] make makeUserSudoerWithoutPasswordRequired taskWithResult
This commit is contained in:
parent
bf36a6283c
commit
082c0827e3
2 changed files with 5 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue