From 1072867dfac0df993cbd3e44bcc11a5cac7465fd Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 22 Sep 2020 12:16:46 -0400 Subject: Enabling Code Formatter Code Formatter was turned off due to java 11 migation Issue-ID: CCSDK-2852 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I3d02ed3cc7a93d7551fe25356512cfe8db1517d8 --- .../ssh/BluePrintSshLibConfiguration.kt | 1 + .../blueprintsprocessor/ssh/BluePrintSshLibData.kt | 2 ++ .../ssh/service/BasicAuthSshClientService.kt | 21 ++++++++++------- .../service/BluePrintSshLibPropertyServiceTest.kt | 19 ++++++++------- .../ssh/service/BlueprintSshClientServiceTest.kt | 27 ++++++++++++---------- .../ssh/service/echoShell/EchoShellFactory.kt | 9 ++++---- 6 files changed, 47 insertions(+), 32 deletions(-) (limited to 'ms/blueprintsprocessor/modules/commons/ssh-lib') diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt index 382c9b7d7..dc10722cc 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibConfiguration.kt @@ -43,6 +43,7 @@ fun BluePrintDependencyService.sshClientService(jsonNode: JsonNode): BlueprintSs class SshLibConstants { companion object { + const val SERVICE_BLUEPRINT_SSH_LIB_PROPERTY = "blueprint-ssh-lib-property-service" const val PROPERTY_SSH_CLIENT_PREFIX = "blueprintsprocessor.sshclient." const val TYPE_BASIC_AUTH = "basic-auth" diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt index cc323adb3..295021f21 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/BluePrintSshLibData.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.ssh open class SshClientProperties { + lateinit var type: String lateinit var host: String var port: Int = 22 @@ -27,6 +28,7 @@ open class SshClientProperties { } open class BasicAuthSshClientProperties : SshClientProperties() { + lateinit var password: String lateinit var username: String } diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt index a3c730039..6ee73c238 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BasicAuthSshClientService.kt @@ -31,13 +31,13 @@ import java.io.ByteArrayOutputStream import java.io.IOException import java.io.PipedInputStream import java.io.PipedOutputStream +import java.util.ArrayList import java.util.Collections import java.util.EnumSet import java.util.Scanner -import java.util.ArrayList open class BasicAuthSshClientService(private val basicAuthSshClientProperties: BasicAuthSshClientProperties) : - BlueprintSshClientService { + BlueprintSshClientService { private val log = LoggerFactory.getLogger(BasicAuthSshClientService::class.java)!! private val newLine = "\n".toByteArray() @@ -54,8 +54,9 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B log.debug("SSH Client Service started successfully") clientSession = sshClient.connect( - basicAuthSshClientProperties.username, basicAuthSshClientProperties.host, - basicAuthSshClientProperties.port).verify(basicAuthSshClientProperties.connectionTimeOut).session + basicAuthSshClientProperties.username, basicAuthSshClientProperties.host, + basicAuthSshClientProperties.port + ).verify(basicAuthSshClientProperties.connectionTimeOut).session clientSession.addPasswordIdentity(basicAuthSshClientProperties.password) clientSession.auth().verify(basicAuthSshClientProperties.connectionTimeOut) @@ -79,7 +80,7 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B } } - override suspend fun executeCommandsNB(commands: List , timeOut: Long): List { + override suspend fun executeCommandsNB(commands: List, timeOut: Long): List { val response = ArrayList() try { var stopLoop = false @@ -126,7 +127,8 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B private fun waitForPrompt(timeOut: Long): String { val waitMask = channel!!.waitFor( - Collections.unmodifiableSet(EnumSet.of(ClientChannelEvent.CLOSED)), timeOut) + Collections.unmodifiableSet(EnumSet.of(ClientChannelEvent.CLOSED)), timeOut + ) if (channel!!.out.toString().indexOfAny(arrayListOf("$", ">", "#")) <= 0 && waitMask.contains(ClientChannelEvent.TIMEOUT)) { throw BluePrintProcessorException("Timeout: Failed to retrieve commands result in $timeOut ms") } @@ -157,8 +159,11 @@ open class BasicAuthSshClientService(private val basicAuthSshClientProperties: B Scanner(output).use { scanner -> while (scanner.hasNextLine()) { val temp = scanner.nextLine() - if (temp.isNotBlank() && (temp.trim { it <= ' ' }.startsWith("%") || - temp.trim { it <= ' ' }.startsWith("syntax error"))) { + if (temp.isNotBlank() && ( + temp.trim { it <= ' ' }.startsWith("%") || + temp.trim { it <= ' ' }.startsWith("syntax error") + ) + ) { return true } } diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt index f4c39c936..43a997ae9 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BluePrintSshLibPropertyServiceTest.kt @@ -31,17 +31,20 @@ import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @ContextConfiguration( - classes = [BluePrintSshLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class] + classes = [ + BluePrintSshLibConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + ] ) @TestPropertySource( properties = - ["blueprintsprocessor.sshclient.sample.type=basic-auth", - "blueprintsprocessor.sshclient.sample.host=127.0.0.1", - "blueprintsprocessor.sshclient.sample.port=22", - "blueprintsprocessor.sshclient.sample.password=1234", - "blueprintsprocessor.sshclient.sample.username=dummy" - ] + [ + "blueprintsprocessor.sshclient.sample.type=basic-auth", + "blueprintsprocessor.sshclient.sample.host=127.0.0.1", + "blueprintsprocessor.sshclient.sample.port=22", + "blueprintsprocessor.sshclient.sample.password=1234", + "blueprintsprocessor.sshclient.sample.username=dummy" + ] ) class BluePrintSshLibPropertyServiceTest { diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt index 3785a21b2..1cf0de52b 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/BlueprintSshClientServiceTest.kt @@ -27,6 +27,7 @@ import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider import org.apache.sshd.server.session.ServerSession import org.apache.sshd.server.shell.ProcessShellCommandFactory +import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BluePrintSshLibConfiguration @@ -36,27 +37,29 @@ import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner import java.nio.file.Paths -import org.junit.runner.RunWith -import kotlin.test.BeforeTest import kotlin.test.AfterTest +import kotlin.test.BeforeTest import kotlin.test.Test -import kotlin.test.assertTrue -import kotlin.test.assertNotNull import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertTrue @RunWith(SpringRunner::class) @ContextConfiguration( - classes = [BluePrintSshLibConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class] + classes = [ + BluePrintSshLibConfiguration::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + ] ) @TestPropertySource( properties = - ["blueprintsprocessor.sshclient.sample.type=basic-auth", - "blueprintsprocessor.sshclient.sample.host=localhost", - "blueprintsprocessor.sshclient.sample.port=52815", - "blueprintsprocessor.sshclient.sample.username=root", - "blueprintsprocessor.sshclient.sample.password=dummyps" - ] + [ + "blueprintsprocessor.sshclient.sample.type=basic-auth", + "blueprintsprocessor.sshclient.sample.host=localhost", + "blueprintsprocessor.sshclient.sample.port=52815", + "blueprintsprocessor.sshclient.sample.username=root", + "blueprintsprocessor.sshclient.sample.password=dummyps" + ] ) class BlueprintSshClientServiceTest { diff --git a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/echoShell/EchoShellFactory.kt b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/echoShell/EchoShellFactory.kt index 9d308202f..6e9d1968f 100644 --- a/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/echoShell/EchoShellFactory.kt +++ b/ms/blueprintsprocessor/modules/commons/ssh-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/ssh/service/echoShell/EchoShellFactory.kt @@ -18,14 +18,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.ssh.service.echoShell import org.apache.sshd.common.Factory import org.apache.sshd.server.Environment -import org.apache.sshd.server.command.Command import org.apache.sshd.server.ExitCallback -import java.io.InputStream -import java.io.OutputStream -import java.io.IOException +import org.apache.sshd.server.command.Command import java.io.BufferedReader +import java.io.IOException +import java.io.InputStream import java.io.InputStreamReader import java.io.InterruptedIOException +import java.io.OutputStream class EchoShellFactory : Factory { @@ -34,6 +34,7 @@ class EchoShellFactory : Factory { } companion object { + val INSTANCE = EchoShellFactory() } } -- cgit 1.2.3-korg