v0.8.15 removed Windows support

This commit is contained in:
az 2021-08-17 20:29:43 +02:00
parent 12b0be4520
commit ca529b79d5
15 changed files with 39 additions and 172 deletions

View file

@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization'
group = 'org.domaindrivenarchitecture.provs' group = 'org.domaindrivenarchitecture.provs'
version = '0.8.15-SNAPSHOT' version = '0.8.15'
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -2,7 +2,6 @@ package org.domaindrivenarchitecture.provs.core
import org.domaindrivenarchitecture.provs.core.platforms.SHELL import org.domaindrivenarchitecture.provs.core.platforms.SHELL
import org.domaindrivenarchitecture.provs.core.platforms.UbuntuProv import org.domaindrivenarchitecture.provs.core.platforms.UbuntuProv
import org.domaindrivenarchitecture.provs.core.platforms.WinProv
import org.domaindrivenarchitecture.provs.core.processors.LocalProcessor import org.domaindrivenarchitecture.provs.core.processors.LocalProcessor
import org.domaindrivenarchitecture.provs.core.processors.Processor import org.domaindrivenarchitecture.provs.core.processors.Processor
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
@ -10,7 +9,7 @@ import org.slf4j.LoggerFactory
enum class ProgressType { NONE, DOTS, BASIC, FULL_LOG } enum class ProgressType { NONE, DOTS, BASIC, FULL_LOG }
enum class ResultMode { NONE, LAST, ALL, FAILEXIT } enum class ResultMode { NONE, LAST, ALL, FAILEXIT }
enum class OS { WINDOWS, LINUX } enum class OS { LINUX }
/** /**
@ -35,27 +34,24 @@ open class Prov protected constructor(
private lateinit var defaultProvInstance: Prov private lateinit var defaultProvInstance: Prov
fun defaultInstance(platform: String? = null): Prov { fun defaultInstance(): Prov {
return if (Factory::defaultProvInstance.isInitialized) { return if (Factory::defaultProvInstance.isInitialized) {
defaultProvInstance defaultProvInstance
} else { } else {
defaultProvInstance = newInstance(platform = platform, name = "default instance") defaultProvInstance = newInstance(name = "default instance", platform = OS.LINUX)
defaultProvInstance defaultProvInstance
} }
} }
fun newInstance( fun newInstance(
processor: Processor = LocalProcessor(), processor: Processor = LocalProcessor(),
platform: String? = null,
name: String? = null, name: String? = null,
progressType: ProgressType = ProgressType.BASIC progressType: ProgressType = ProgressType.BASIC,
platform: OS = OS.LINUX
): Prov { ): Prov {
val os = platform ?: System.getProperty("os.name")
return when { return when {
os.toUpperCase().contains(OS.LINUX.name) -> UbuntuProv(processor, name, progressType) (platform == OS.LINUX) -> UbuntuProv(processor, name, progressType)
os.toUpperCase().contains(OS.WINDOWS.name) -> WinProv(processor, name, progressType)
else -> throw Exception("OS not supported") else -> throw Exception("OS not supported")
} }
} }
@ -143,6 +139,8 @@ open class Prov protected constructor(
} }
private val NOT_IMPLEMENTED = "Not implemented"
/** /**
* Executes a command by using the shell. * Executes a command by using the shell.
* Be aware: Executing shell commands that incorporate unsanitized input from an untrusted source * Be aware: Executing shell commands that incorporate unsanitized input from an untrusted source
@ -150,7 +148,7 @@ open class Prov protected constructor(
* Thus, the use of this method is strongly discouraged in cases where the command string is constructed from external input. * Thus, the use of this method is strongly discouraged in cases where the command string is constructed from external input.
*/ */
open fun cmd(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult { open fun cmd(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult {
throw Exception("Not implemented") throw Exception(NOT_IMPLEMENTED)
} }
@ -159,7 +157,7 @@ open class Prov protected constructor(
* Attention: only result is NOT logged the executed command still is. * Attention: only result is NOT logged the executed command still is.
*/ */
open fun cmdNoLog(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult { open fun cmdNoLog(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult {
throw Exception("Not implemented") throw Exception(NOT_IMPLEMENTED)
} }
@ -168,7 +166,7 @@ open class Prov protected constructor(
* Can be used e.g. for checks which might succeed or fail but where failure should not influence overall success * Can be used e.g. for checks which might succeed or fail but where failure should not influence overall success
*/ */
open fun cmdNoEval(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult { open fun cmdNoEval(cmd: String, dir: String? = null, sudo: Boolean = false): ProvResult {
throw Exception("Not implemented") throw Exception(NOT_IMPLEMENTED)
} }

View file

@ -69,14 +69,14 @@ fun local(): Prov {
/** /**
* Returns Prov instance for remote host with remote user with provided password. * Returns Prov instance for remote host with remote user with provided password.
* If password is null, connection is done by ssh-key. * If password is null, connection is done by ssh-key.
* Platform (Linux, Windows) must be provided if different from local platform. * Platform (Linux, etc) must be provided if different from local platform.
*/ */
@Api // used by other libraries resp. KotlinScript @Api // used by other libraries resp. KotlinScript
fun remote(host: String, remoteUser: String, password: Secret? = null, platform: String? = null): Prov { fun remote(host: String, remoteUser: String, password: Secret? = null, platform: OS = OS.LINUX): Prov {
require(host.isNotEmpty(), { "Host must not be empty." }) require(host.isNotEmpty(), { "Host must not be empty." })
require(remoteUser.isNotEmpty(), { "Remote user must not be empty." }) require(remoteUser.isNotEmpty(), { "Remote user must not be empty." })
return Prov.newInstance(RemoteProcessor(InetAddress.getByName(host), remoteUser, password), platform) return Prov.newInstance(RemoteProcessor(InetAddress.getByName(host), remoteUser, password), platform = platform)
} }

View file

@ -17,7 +17,7 @@ open class LocalProcessor : Processor {
@Suppress("JAVA_CLASS_ON_COMPANION") @Suppress("JAVA_CLASS_ON_COMPANION")
private val log = LoggerFactory.getLogger(javaClass.enclosingClass) private val log = LoggerFactory.getLogger(javaClass.enclosingClass)
var charset: Charset = if (getOsName().contains("Windows")) Charset.forName("Windows-1252") else Charset.defaultCharset() var charset: Charset = Charset.defaultCharset()
init { init {
log.info("os.name: " + getOsName()) log.info("os.name: " + getOsName())
log.info("user.home: " + System.getProperty("user.home")) log.info("user.home: " + System.getProperty("user.home"))

View file

@ -129,7 +129,7 @@ fun provisionRemote(args: Array<String>) {
val pwFromSecret = Password(pwSecret.plain()) val pwFromSecret = Password(pwSecret.plain())
val config = readWorkplaceConfigFromFile() ?: WorkplaceConfig() val config = readWorkplaceConfigFromFile() ?: WorkplaceConfig()
Prov.newInstance(RemoteProcessor(host, userName, pwFromSecret), OS.LINUX.name).provisionWorkplace( Prov.newInstance(RemoteProcessor(host, userName, pwFromSecret)).provisionWorkplace(
config.type, config.type,
config.ssh?.keyPair(), config.ssh?.keyPair(),
config.gpg?.keyPair(), config.gpg?.keyPair(),

View file

@ -7,8 +7,6 @@ import org.domaindrivenarchitecture.provs.test.testLocal
import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.PrintStream import java.io.PrintStream
@ -25,8 +23,7 @@ internal class ProvTest {
@Test @Test
@EnabledOnOs(OS.LINUX) fun cmd() {
fun cmd_onLinux() {
// when // when
val res = Prov.newInstance(name = "testing").cmd("echo --testing--").success val res = Prov.newInstance(name = "testing").cmd("echo --testing--").success
@ -35,9 +32,8 @@ internal class ProvTest {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
@ContainerTest @ContainerTest
fun sh_onLinux() { fun sh() {
// given // given
val script = """ val script = """
# test some script commands # test some script commands
@ -55,10 +51,9 @@ internal class ProvTest {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
@ContainerTest @ContainerTest
@NonCi @NonCi
fun sh_onLinux_with_dir_and_sudo() { fun sh_with_dir_and_sudo() {
// given // given
val script = """ val script = """
# test some script commands # test some script commands
@ -76,36 +71,6 @@ internal class ProvTest {
assert(res) assert(res)
} }
@Test
@EnabledOnOs(OS.WINDOWS)
fun cmd_onWindows() {
// when
val res = Prov.newInstance(name = "testing").cmd("echo --testing--").success
// then
assert(res)
}
@Test
@EnabledOnOs(OS.WINDOWS)
fun sh_onWindows() {
// given
val script = """
# test some script commands
ping -n 1 nu.nl
echo something
ping -n 1 github.com
"""
// when
val res = Prov.newInstance(name = "testing").sh(script).success
// then
assert(res)
}
@Test @Test
fun def_modeOptional_result_true() { fun def_modeOptional_result_true() {
// given // given
@ -332,32 +297,19 @@ internal class ProvTest {
println(outContent.toString()) println(outContent.toString())
val expectedOutput = if (OS.WINDOWS.isCurrentOs) "\n" + val expectedOutput =
"============================================== SUMMARY (test Instance) ============================================== \n" + "============================================== SUMMARY (test instance) ============================================== \n" +
"> Success -- methodThatProvidesSomeOutput (requireLast) \n" + "> \u001B[92mSuccess\u001B[0m -- methodThatProvidesSomeOutput (requireLast) \n" +
"---> FAILED -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" + "---> \u001B[91mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" +
"---> Success -- sh \n" + "---> \u001B[92mSuccess\u001B[0m -- sh \n" +
"------> Success -- cmd [cmd.exe, /c, echo -Start test-]\n" + "------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo -Start test-]\n" +
"------> Success -- cmd [cmd.exe, /c, echo Some output]\n" + "------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo Some output]\n" +
"---> Success -- sh \n" + "---> \u001B[92mSuccess\u001B[0m -- sh \n" +
"------> Success -- cmd [cmd.exe, /c, echo -End test-]\n" + "------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo -End test-]\n" +
"============================================ SUMMARY END ============================================ \n" "----------------------------------------------------------------------------------------------------- \n" +
else if (OS.LINUX.isCurrentOs()) { "Overall > \u001B[92mSuccess\u001B[0m\n" +
"============================================== SUMMARY (test instance) ============================================== \n" + "============================================ SUMMARY END ============================================ \n" +
"> \u001B[92mSuccess\u001B[0m -- methodThatProvidesSomeOutput (requireLast) \n" + "\n"
"---> \u001B[91mFAILED\u001B[0m -- checkPrereq_evaluateToFailure (requireLast) -- Error: This is a test error.\n" +
"---> \u001B[92mSuccess\u001B[0m -- sh \n" +
"------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo -Start test-]\n" +
"------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo Some output]\n" +
"---> \u001B[92mSuccess\u001B[0m -- sh \n" +
"------> \u001B[92mSuccess\u001B[0m -- cmd [/bin/bash, -c, echo -End test-]\n" +
"----------------------------------------------------------------------------------------------------- \n" +
"Overall > \u001B[92mSuccess\u001B[0m\n" +
"============================================ SUMMARY END ============================================ \n" +
"\n"
} else {
"OS " + System.getProperty("os.name") + " not yet supported"
}
assertEquals(expectedOutput, outContent.toString().replace("\r", "")) assertEquals(expectedOutput, outContent.toString().replace("\r", ""))
} }
@ -428,7 +380,6 @@ internal class ProvTest {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
@NonCi @NonCi
fun inContainer_locally() { fun inContainer_locally() {
// given // given
@ -454,7 +405,6 @@ internal class ProvTest {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
@Disabled // run manually after updating host and remoteUser @Disabled // run manually after updating host and remoteUser
fun inContainer_remotely() { fun inContainer_remotely() {
// given // given

View file

@ -14,7 +14,6 @@ import org.junit.jupiter.api.condition.OS
internal class UbuntuHostDockerKtTest { internal class UbuntuHostDockerKtTest {
@Test @Test
@EnabledOnOs(OS.LINUX)
@NonCi @NonCi
fun runAndCheckAndExitContainer() { fun runAndCheckAndExitContainer() {
// when // when

View file

@ -7,15 +7,12 @@ import org.domaindrivenarchitecture.provs.core.docker.dockerProvideImage
import org.domaindrivenarchitecture.provs.core.docker.dockerimages.DockerImage import org.domaindrivenarchitecture.provs.core.docker.dockerimages.DockerImage
import org.domaindrivenarchitecture.provs.core.processors.ContainerStartMode import org.domaindrivenarchitecture.provs.core.processors.ContainerStartMode
import org.domaindrivenarchitecture.provs.core.processors.ContainerUbuntuHostProcessor import org.domaindrivenarchitecture.provs.core.processors.ContainerUbuntuHostProcessor
import org.domaindrivenarchitecture.provs.test.defaultTestContainerName
import org.domaindrivenarchitecture.provs.test.tags.NonCi import org.domaindrivenarchitecture.provs.test.tags.NonCi
import org.domaindrivenarchitecture.provs.test.testDockerWithSudo import org.domaindrivenarchitecture.provs.test.testDockerWithSudo
import org.domaindrivenarchitecture.provs.test.testLocal import org.domaindrivenarchitecture.provs.test.testLocal
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS
internal class UbuntuProvTests { internal class UbuntuProvTests {
@ -28,7 +25,6 @@ internal class UbuntuProvTests {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
fun that_ping_works() { fun that_ping_works() {
// when // when
val res = testLocal().outerPing() val res = testLocal().outerPing()
@ -38,7 +34,6 @@ internal class UbuntuProvTests {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
fun that_cmd_works() { fun that_cmd_works() {
// given // given
val a = testLocal() val a = testLocal()
@ -55,7 +50,6 @@ internal class UbuntuProvTests {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
@NonCi @NonCi
fun that_cmd_works_with_sudo() { fun that_cmd_works_with_sudo() {
// given // given
@ -70,7 +64,6 @@ internal class UbuntuProvTests {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
fun that_nested_shells_work() { fun that_nested_shells_work() {
// given // given
val a = testLocal() val a = testLocal()
@ -87,7 +80,6 @@ internal class UbuntuProvTests {
} }
@Test @Test
@EnabledOnOs(OS.LINUX)
fun that_xec_works() { fun that_xec_works() {
// given // given
val a = testLocal() val a = testLocal()

View file

@ -1,45 +0,0 @@
package org.domaindrivenarchitecture.provs.core.platformTest
import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.test.testLocal
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS
internal class WinProvTests {
private fun Prov.ping(url: String) = def {
cmd("ping $url")
}
private fun Prov.outerPing() = def { ping("nu.nl") }
@Test
@EnabledOnOs(OS.WINDOWS)
fun def_definesPing_function() {
// when
val res = testLocal().outerPing()
// then
assert(res.success)
}
@Test
@EnabledOnOs(OS.WINDOWS)
fun cmd_executesCommand() {
// given
val a = testLocal()
// when
val res1 = a.cmd("echo %cd%")
val dir = res1.out?.trim()
val res2 = a.cmd("echo abc", dir)
// then
assert(res1.success)
assert(res1.success)
assertEquals( "abc", res2.out?.trim())
}
}

View file

@ -8,7 +8,6 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS import org.junit.jupiter.api.condition.OS
@EnabledOnOs(OS.LINUX)
internal class ContainerProcessorTest { internal class ContainerProcessorTest {
@Test @Test

View file

@ -5,15 +5,12 @@ import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.domaindrivenarchitecture.provs.test.testDockerWithSudo import org.domaindrivenarchitecture.provs.test.testDockerWithSudo
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS.LINUX
val DEFAULT_START_MODE_TEST_CONTAINER = ContainerStartMode.USE_RUNNING_ELSE_CREATE val DEFAULT_START_MODE_TEST_CONTAINER = ContainerStartMode.USE_RUNNING_ELSE_CREATE
class ContainerUbuntuHostProcessorTest { class ContainerUbuntuHostProcessorTest {
@Test @Test
@EnabledOnOs(LINUX)
@ContainerTest @ContainerTest
fun test_execution() { fun test_execution() {
// given // given

View file

@ -7,15 +7,12 @@ import org.domaindrivenarchitecture.provs.core.escapeSingleQuoteForShell
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledOnOs
import org.junit.jupiter.api.condition.OS
internal class LocalProcessorTest { internal class LocalProcessorTest {
@Test @Test
@EnabledOnOs(OS.LINUX) fun cmd_with_printf() {
fun cmd_with_printf_on_Linux() {
// given // given
val prov = Prov.newInstance() val prov = Prov.newInstance()
val text = "abc123!§\\\$%%&/\"\\äöü'" val text = "abc123!§\\\$%%&/\"\\äöü'"
@ -30,8 +27,7 @@ internal class LocalProcessorTest {
@Test @Test
@EnabledOnOs(OS.LINUX) fun cmd_with_nested_shell_and_printf() {
fun cmd_with_nested_shell_and_printf_on_Linux() {
// given // given
val prov = Prov.newInstance() val prov = Prov.newInstance()
val text = "abc123!§\\$%%&/\"\\äöü'" val text = "abc123!§\\$%%&/\"\\äöü'"
@ -46,29 +42,11 @@ internal class LocalProcessorTest {
@Test @Test
@EnabledOnOs(OS.WINDOWS) fun cmdNoLog() {
fun cmd_with_echo_on_Windows() {
// given
val prov = Prov.newInstance()
val text = "abc123!\"#"
// when
val res = prov.cmd("echo $text")
// then
assert(res.success)
assertEquals( text + "\r\n", res.out)
}
@Test
@EnabledOnOs(OS.LINUX)
fun cmdNoLog_linux() {
// given // given
val prov = Prov.newInstance() val prov = Prov.newInstance()
val text = "abc123!#" val text = "abc123!#"
val osSpecificText = if (OS.WINDOWS.isCurrentOs) text else "'$text'" val osSpecificText = "'$text'"
// when // when
val res = prov.cmdNoLog("echo $osSpecificText") val res = prov.cmdNoLog("echo $osSpecificText")

View file

@ -31,7 +31,8 @@ internal class ProvisionFirewallKtTest {
dockerImage.imageName(), dockerImage.imageName(),
ContainerStartMode.USE_RUNNING_ELSE_CREATE, // already started in previous statement ContainerStartMode.USE_RUNNING_ELSE_CREATE, // already started in previous statement
ContainerEndMode.EXIT_AND_REMOVE ContainerEndMode.EXIT_AND_REMOVE
)) )
)
// when // when
val res = a.requireAll { val res = a.requireAll {

View file

@ -9,7 +9,6 @@ import org.junit.jupiter.api.condition.OS
internal class ProvisionKeysTest { internal class ProvisionKeysTest {
@Test @Test
@EnabledOnOs(OS.LINUX)
fun provisionKeysCurrentUser() { fun provisionKeysCurrentUser() {
// given // given
val a = defaultTestContainer() val a = defaultTestContainer()

View file

@ -12,7 +12,6 @@ import org.junit.jupiter.api.condition.OS
internal class ProvisionUserKtTest { internal class ProvisionUserKtTest {
@Test @Test
@EnabledOnOs(OS.LINUX)
fun configureUser() { fun configureUser() {
// given // given
val a = defaultTestContainer() val a = defaultTestContainer()