[skip ci] remove parameter remoteHostSetSudoWithoutPasswordRequired

This commit is contained in:
az 2023-02-26 19:15:23 +01:00
parent f672624928
commit 10a750fbf9
2 changed files with 14 additions and 21 deletions

View file

@ -17,7 +17,7 @@ fun main(args: Array<String>) {
exitProcess(1) exitProcess(1)
} }
val prov = createProvInstance(cmd.target, remoteHostSetSudoWithoutPasswordRequired = true) val prov = createProvInstance(cmd.target)
try { try {
provisionDesktopCommand(prov, cmd) provisionDesktopCommand(prov, cmd)

View file

@ -20,10 +20,7 @@ import kotlin.system.exitProcess
* If the target is remote and if parameter remoteHostSetSudoWithoutPasswordRequired is set to true, * If the target is remote and if parameter remoteHostSetSudoWithoutPasswordRequired is set to true,
* it will enable sudo without password on the remote machine (in case this was not yet enabled). * it will enable sudo without password on the remote machine (in case this was not yet enabled).
*/ */
fun createProvInstance( fun createProvInstance(targetCommand: TargetCliCommand): Prov {
targetCommand: TargetCliCommand,
remoteHostSetSudoWithoutPasswordRequired: Boolean = false
): Prov {
if (targetCommand.isValid()) { if (targetCommand.isValid()) {
val password: Secret? = targetCommand.remoteTarget()?.password val password: Secret? = targetCommand.remoteTarget()?.password
@ -35,8 +32,7 @@ fun createProvInstance(
remoteTarget.host, remoteTarget.host,
remoteTarget.user, remoteTarget.user,
remoteTarget.password == null, remoteTarget.password == null,
password, password
remoteHostSetSudoWithoutPasswordRequired
) )
} else { } else {
throw IllegalArgumentException("Error: neither a valid localHost nor a valid remoteHost was specified! Use option -h for help.") throw IllegalArgumentException("Error: neither a valid localHost nor a valid remoteHost was specified! Use option -h for help.")
@ -50,8 +46,10 @@ fun createProvInstance(
private fun createLocalProvInstance(): Prov { private fun createLocalProvInstance(): Prov {
val prov = local() val prov = local()
if (!prov.currentUserCanSudoWithoutPassword()) { if (!prov.currentUserCanSudoWithoutPassword()) {
val password = PromptSecretSource("Please enter password to configure sudo without password in the future." + val password = PromptSecretSource(
"\nWarning: This will permanently allow your user to use sudo privileges without a password.").secret() "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.makeUserSudoerWithNoSudoPasswordRequired(password) prov.makeUserSudoerWithNoSudoPasswordRequired(password)
} }
return prov return prov
@ -62,8 +60,7 @@ private fun createRemoteProvInstance(
host: String, host: String,
remoteUser: String, remoteUser: String,
sshWithKey: Boolean, sshWithKey: Boolean,
password: Secret?, password: Secret?
remoteHostSetSudoWithoutPasswordRequired: Boolean
): Prov { ): Prov {
val prov = val prov =
if (sshWithKey) { if (sshWithKey) {
@ -76,7 +73,6 @@ private fun createRemoteProvInstance(
} }
if (!prov.currentUserCanSudoWithoutPassword()) { if (!prov.currentUserCanSudoWithoutPassword()) {
if (remoteHostSetSudoWithoutPasswordRequired) {
require( require(
password != null, password != null,
{ "User ${prov.whoami()} not able to sudo on remote machine without password and no password available for the user." }) { "User ${prov.whoami()} not able to sudo on remote machine without password and no password available for the user." })
@ -84,9 +80,6 @@ private fun createRemoteProvInstance(
// a new session is required after making the user a sudoer without password // a new session is required after making the user a sudoer without password
return remote(host, remoteUser, password) return remote(host, remoteUser, password)
} else {
throw IllegalStateException("User ${prov.whoami()} not able to sudo on remote machine without password and option not set to enable user to sudo without password.")
}
} }
return prov return prov
} }