[skip ci] simplify and rename retrievePassword

This commit is contained in:
az 2023-02-26 19:39:54 +01:00
parent 082c0827e3
commit 8bb2e6e950
3 changed files with 11 additions and 17 deletions

View file

@ -85,12 +85,6 @@ private fun createRemoteProvInstance(
} }
internal fun retrievePassword(cliCommand: TargetCliCommand): Secret? { internal fun getPasswordToConfigureSudoWithoutPassword(): Secret {
var password: Secret? = null return PromptSecretSource("password to configure sudo without password.").secret()
if (cliCommand.isValidRemote() && cliCommand.passwordInteractive) { }
password =
PromptSecretSource("Password for user $cliCommand.userName!! on $cliCommand.remoteHost!!").secret()
}
return password
}

View file

@ -4,7 +4,7 @@ import io.mockk.*
import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.Prov
import org.domaindrivenarchitecture.provs.framework.core.Secret import org.domaindrivenarchitecture.provs.framework.core.Secret
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword import org.domaindrivenarchitecture.provs.framework.core.cli.getPasswordToConfigureSudoWithoutPassword
import org.domaindrivenarchitecture.provs.framework.core.local import org.domaindrivenarchitecture.provs.framework.core.local
import org.domaindrivenarchitecture.provs.framework.core.processors.PrintOnlyProcessor import org.domaindrivenarchitecture.provs.framework.core.processors.PrintOnlyProcessor
import org.domaindrivenarchitecture.provs.framework.core.remote import org.domaindrivenarchitecture.provs.framework.core.remote
@ -23,8 +23,8 @@ internal class CliTargetCommandKtTest {
mockkStatic(::remote) mockkStatic(::remote)
every { remote(any(), any(), any(), any()) } returns Prov.newInstance(PrintOnlyProcessor()) every { remote(any(), any(), any(), any()) } returns Prov.newInstance(PrintOnlyProcessor())
mockkStatic(::retrievePassword) mockkStatic(::getPasswordToConfigureSudoWithoutPassword)
every { retrievePassword(any()) } returns Secret("sec") every { getPasswordToConfigureSudoWithoutPassword() } returns Secret("sec")
} }
@AfterAll @AfterAll
@ -33,7 +33,7 @@ internal class CliTargetCommandKtTest {
unmockkObject(Prov) unmockkObject(Prov)
unmockkStatic(::local) unmockkStatic(::local)
unmockkStatic(::remote) unmockkStatic(::remote)
unmockkStatic(::retrievePassword) unmockkStatic(::getPasswordToConfigureSudoWithoutPassword)
} }
} }

View file

@ -7,7 +7,7 @@ import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
import org.domaindrivenarchitecture.provs.desktop.domain.* import org.domaindrivenarchitecture.provs.desktop.domain.*
import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig import org.domaindrivenarchitecture.provs.desktop.infrastructure.getConfig
import org.domaindrivenarchitecture.provs.framework.core.* import org.domaindrivenarchitecture.provs.framework.core.*
import org.domaindrivenarchitecture.provs.framework.core.cli.retrievePassword import org.domaindrivenarchitecture.provs.framework.core.cli.getPasswordToConfigureSudoWithoutPassword
import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor
import org.domaindrivenarchitecture.provs.test.setRootLoggingLevel import org.domaindrivenarchitecture.provs.test.setRootLoggingLevel
import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.AfterAll
@ -52,8 +52,8 @@ internal class ApplicationKtTest {
cmd = "mocked command" cmd = "mocked command"
) )
mockkStatic(::retrievePassword) mockkStatic(::getPasswordToConfigureSudoWithoutPassword)
every { retrievePassword(any()) } returns Secret("sec") every { getPasswordToConfigureSudoWithoutPassword() } returns Secret("sec")
} }
@Suppress("unused") // false positive @Suppress("unused") // false positive
@ -65,7 +65,7 @@ internal class ApplicationKtTest {
unmockkStatic(::remote) unmockkStatic(::remote)
unmockkStatic(::getConfig) unmockkStatic(::getConfig)
unmockkStatic(Prov::provisionDesktop) unmockkStatic(Prov::provisionDesktop)
unmockkStatic(::retrievePassword) unmockkStatic(::getPasswordToConfigureSudoWithoutPassword)
} }
} }