[skip ci] add local check for sudo

This commit is contained in:
az 2023-02-01 09:41:06 +01:00
parent c7ea95fbd4
commit b25729e910

View file

@ -29,9 +29,9 @@ fun createProvInstance(
val remoteTarget = targetCommand.remoteTarget() val remoteTarget = targetCommand.remoteTarget()
if (targetCommand.isValidLocalhost()) { if (targetCommand.isValidLocalhost()) {
return local() return createLocalProvInstance()
} else if (targetCommand.isValidRemote() && remoteTarget != null) { } else if (targetCommand.isValidRemote() && remoteTarget != null) {
return createProvInstanceRemote( return createRemoteProvInstance(
remoteTarget.host, remoteTarget.host,
remoteTarget.user, remoteTarget.user,
remoteTarget.password == null, remoteTarget.password == null,
@ -47,7 +47,18 @@ fun createProvInstance(
} }
} }
private fun createProvInstanceRemote(
private fun createLocalProvInstance(): Prov {
val prov = local()
if (!prov.currentUserCanSudo()) {
val password = PromptSecretSource("Please enter password to configure sudo without password in the future.").secret()
prov.makeUserSudoerWithNoSudoPasswordRequired(password)
}
return prov
}
private fun createRemoteProvInstance(
host: String, host: String,
remoteUser: String, remoteUser: String,
sshWithKey: Boolean, sshWithKey: Boolean,