From b25729e91037f1153d9e6001378fbd420fdc3660 Mon Sep 17 00:00:00 2001 From: az Date: Wed, 1 Feb 2023 09:41:06 +0100 Subject: [PATCH] [skip ci] add local check for sudo --- .../provs/framework/core/cli/CliUtils.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 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 6b3b74a..7df1a52 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 @@ -29,9 +29,9 @@ fun createProvInstance( val remoteTarget = targetCommand.remoteTarget() if (targetCommand.isValidLocalhost()) { - return local() + return createLocalProvInstance() } else if (targetCommand.isValidRemote() && remoteTarget != null) { - return createProvInstanceRemote( + return createRemoteProvInstance( remoteTarget.host, remoteTarget.user, 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, remoteUser: String, sshWithKey: Boolean,