mirror of
https://github.com/corda/corda.git
synced 2024-12-24 07:06:44 +00:00
This reverts commit f7bf1b41
This commit is contained in:
parent
f273d894ef
commit
5edd732615
@ -239,7 +239,8 @@ open class StringToMethodCallParser<in T : Any> @JvmOverloads constructor(
|
||||
/** Returns a string-to-string map of commands to a string describing available parameter types. */
|
||||
val availableCommands: Map<String, String>
|
||||
get() {
|
||||
return methodMap.entries().map { (name, args) ->
|
||||
return methodMap.entries().map { entry ->
|
||||
val (name, args) = entry // TODO: Kotlin 1.1
|
||||
val argStr = if (args.parameterCount == 0) "" else {
|
||||
val paramNames = methodParamNames[name]!!
|
||||
val typeNames = args.parameters.map { it.type.simpleName }
|
||||
|
@ -1,15 +0,0 @@
|
||||
package net.corda.client.jackson.internal
|
||||
|
||||
import com.fasterxml.jackson.databind.Module
|
||||
|
||||
/**
|
||||
* Should be implemented by CorDapps who wish to declare custom serializers.
|
||||
* Classes of this type will be autodiscovered and registered.
|
||||
*/
|
||||
interface CustomShellSerializationFactory {
|
||||
|
||||
/**
|
||||
* The returned [Module] will be registered automatically with the interactive shell.
|
||||
*/
|
||||
fun createJacksonModule(): Module
|
||||
}
|
@ -1,23 +1,17 @@
|
||||
package net.corda.tools.shell
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationContext
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule
|
||||
import com.google.common.io.Files
|
||||
import com.jcraft.jsch.ChannelExec
|
||||
import com.jcraft.jsch.JSch
|
||||
import com.nhaarman.mockito_kotlin.any
|
||||
import com.nhaarman.mockito_kotlin.doAnswer
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import net.corda.client.jackson.internal.CustomShellSerializationFactory
|
||||
import net.corda.client.rpc.RPCException
|
||||
import net.corda.core.flows.FlowLogic
|
||||
import net.corda.core.flows.StartableByRPC
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.messaging.ClientRpcSslOptions
|
||||
import net.corda.core.messaging.CordaRPCOps
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.utilities.ProgressTracker
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.node.services.Permissions
|
||||
@ -33,8 +27,6 @@ import net.corda.testing.driver.driver
|
||||
import net.corda.testing.driver.internal.NodeHandleInternal
|
||||
import net.corda.testing.internal.useSslRpcOverrides
|
||||
import net.corda.testing.node.User
|
||||
import net.corda.tools.shell.InteractiveShell.createYamlInputMapper
|
||||
import net.corda.tools.shell.InteractiveShell.runFlowByNameFragment
|
||||
import net.corda.tools.shell.utlities.ANSIProgressRenderer
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQSecurityException
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@ -278,9 +270,9 @@ class InteractiveShellIntegrationTest {
|
||||
val ansiProgressRenderer = mock<ANSIProgressRenderer> {
|
||||
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
|
||||
}
|
||||
runFlowByNameFragment(
|
||||
InteractiveShell.runFlowByNameFragment(
|
||||
"NoOpFlow",
|
||||
"", output, node.rpc, ansiProgressRenderer, createYamlInputMapper(node.rpc, null))
|
||||
"", output, node.rpc, ansiProgressRenderer)
|
||||
}
|
||||
assertThat(successful).isTrue()
|
||||
}
|
||||
@ -310,9 +302,9 @@ class InteractiveShellIntegrationTest {
|
||||
val ansiProgressRenderer = mock<ANSIProgressRenderer> {
|
||||
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
|
||||
}
|
||||
runFlowByNameFragment(
|
||||
InteractiveShell.runFlowByNameFragment(
|
||||
"NoOpFlowA",
|
||||
"", output, node.rpc, ansiProgressRenderer, createYamlInputMapper(node.rpc, null))
|
||||
"", output, node.rpc, ansiProgressRenderer)
|
||||
}
|
||||
assertThat(successful).isTrue()
|
||||
}
|
||||
@ -342,9 +334,9 @@ class InteractiveShellIntegrationTest {
|
||||
val ansiProgressRenderer = mock<ANSIProgressRenderer> {
|
||||
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
|
||||
}
|
||||
runFlowByNameFragment(
|
||||
InteractiveShell.runFlowByNameFragment(
|
||||
"NoOpFlo",
|
||||
"", output, node.rpc, ansiProgressRenderer, createYamlInputMapper(node.rpc, null))
|
||||
"", output, node.rpc, ansiProgressRenderer)
|
||||
}
|
||||
assertThat(successful).isTrue()
|
||||
}
|
||||
@ -374,41 +366,9 @@ class InteractiveShellIntegrationTest {
|
||||
val ansiProgressRenderer = mock<ANSIProgressRenderer> {
|
||||
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
|
||||
}
|
||||
runFlowByNameFragment(
|
||||
InteractiveShell.runFlowByNameFragment(
|
||||
"Burble",
|
||||
"", output, node.rpc, ansiProgressRenderer, createYamlInputMapper(node.rpc, null))
|
||||
}
|
||||
assertThat(successful).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `shell should start flow with custom json deserializer`() {
|
||||
val user = User("u", "p", setOf(all()))
|
||||
var successful = false
|
||||
driver(DriverParameters(notarySpecs = emptyList())) {
|
||||
val nodeFuture = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), startInSameProcess = true)
|
||||
val node = nodeFuture.getOrThrow()
|
||||
|
||||
val conf = ShellConfiguration(commandsDirectory = Files.createTempDir().toPath(),
|
||||
user = user.username, password = user.password,
|
||||
hostAndPort = node.rpcAddress)
|
||||
InteractiveShell.startShell(conf)
|
||||
|
||||
// setup and configure some mocks required by InteractiveShell.runFlowByNameFragment()
|
||||
val output = mock<RenderPrintWriter> {
|
||||
on { println(any<String>()) } doAnswer {
|
||||
val line = it.arguments[0]
|
||||
println("$line")
|
||||
if ((line is String) && (line.startsWith("Flow completed with result: ${FirstAndLastName("John", "Doe")}")))
|
||||
successful = true
|
||||
}
|
||||
}
|
||||
val ansiProgressRenderer = mock<ANSIProgressRenderer> {
|
||||
on { render(any(), any()) } doAnswer { InteractiveShell.latch.countDown() }
|
||||
}
|
||||
runFlowByNameFragment(
|
||||
"DeserializeFlow",
|
||||
"firstAndLastName: John Doe", output, node.rpc, ansiProgressRenderer, createYamlInputMapper(node.rpc, this::class.java.classLoader))
|
||||
"", output, node.rpc, ansiProgressRenderer)
|
||||
}
|
||||
assertThat(successful).isTrue()
|
||||
}
|
||||
@ -440,36 +400,3 @@ class BurbleFlow : FlowLogic<Unit>() {
|
||||
println("NO OP! (Burble)")
|
||||
}
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
data class FirstAndLastName(val firstName: String, val lastName: String)
|
||||
|
||||
@Suppress("UNUSED")
|
||||
@StartableByRPC
|
||||
class DeserializeFlow(private val firstAndLastName: FirstAndLastName) : FlowLogic<FirstAndLastName>() {
|
||||
override val progressTracker = ProgressTracker()
|
||||
override fun call(): FirstAndLastName {
|
||||
return firstAndLastName
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNUSED")
|
||||
class MyCustomJackson : CustomShellSerializationFactory {
|
||||
override fun createJacksonModule() = object : SimpleModule() {
|
||||
|
||||
override fun setupModule(context: SetupContext) {
|
||||
super.setupModule(context)
|
||||
context.setMixInAnnotations(FirstAndLastName::class.java, FirstLastNameMixin::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@JsonDeserialize(using = FirstLastNameDeserializer::class)
|
||||
private interface FirstLastNameMixin
|
||||
|
||||
object FirstLastNameDeserializer : FromStringDeserializer<FirstAndLastName>(FirstAndLastName::class.java) {
|
||||
override fun _deserialize(value: String, ctxt: DeserializationContext?): FirstAndLastName {
|
||||
val (firstName, lastName) = value.split(" ")
|
||||
return FirstAndLastName(firstName, lastName)
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import org.crsh.auth.AuthInfo
|
||||
import org.crsh.auth.AuthenticationPlugin
|
||||
import org.crsh.plugin.CRaSHPlugin
|
||||
|
||||
class CordaAuthenticationPlugin(private val rpcOps: (username: String, credential: String) -> CordaRPCOps, private val classLoader: ClassLoader?) : CRaSHPlugin<AuthenticationPlugin<String>>(), AuthenticationPlugin<String> {
|
||||
class CordaAuthenticationPlugin(private val rpcOps: (username: String, credential: String) -> CordaRPCOps) : CRaSHPlugin<AuthenticationPlugin<String>>(), AuthenticationPlugin<String> {
|
||||
|
||||
companion object {
|
||||
private val logger = loggerFor<CordaAuthenticationPlugin>()
|
||||
@ -24,7 +24,7 @@ class CordaAuthenticationPlugin(private val rpcOps: (username: String, credentia
|
||||
}
|
||||
try {
|
||||
val ops = rpcOps(username, credential)
|
||||
return CordaSSHAuthInfo(true, ops, classLoader, isSsh = true)
|
||||
return CordaSSHAuthInfo(true, ops, isSsh = true)
|
||||
} catch (e: ActiveMQSecurityException) {
|
||||
logger.warn(e.message)
|
||||
} catch (e: Exception) {
|
||||
|
@ -6,10 +6,10 @@ import net.corda.tools.shell.InteractiveShell.createYamlInputMapper
|
||||
import net.corda.tools.shell.utlities.ANSIProgressRenderer
|
||||
import org.crsh.auth.AuthInfo
|
||||
|
||||
class CordaSSHAuthInfo(val successful: Boolean, val rpcOps: CordaRPCOps, val classLoader: ClassLoader?, val ansiProgressRenderer: ANSIProgressRenderer? = null, val isSsh: Boolean = false) : AuthInfo {
|
||||
class CordaSSHAuthInfo(val successful: Boolean, val rpcOps: CordaRPCOps, val ansiProgressRenderer: ANSIProgressRenderer? = null, val isSsh: Boolean = false) : AuthInfo {
|
||||
override fun isSuccessful(): Boolean = successful
|
||||
|
||||
val yamlInputMapper: ObjectMapper by lazy {
|
||||
createYamlInputMapper(rpcOps, classLoader)
|
||||
createYamlInputMapper(rpcOps)
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import com.fasterxml.jackson.databind.SerializationFeature
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
|
||||
import io.github.classgraph.ClassGraph
|
||||
import net.corda.client.jackson.JacksonSupport
|
||||
import net.corda.client.jackson.StringToMethodCallParser
|
||||
import net.corda.client.rpc.CordaRPCClient
|
||||
@ -25,7 +24,6 @@ import net.corda.core.internal.*
|
||||
import net.corda.core.internal.concurrent.doneFuture
|
||||
import net.corda.core.internal.concurrent.openFuture
|
||||
import net.corda.core.messaging.*
|
||||
import net.corda.client.jackson.internal.CustomShellSerializationFactory
|
||||
import net.corda.tools.shell.utlities.ANSIProgressRenderer
|
||||
import net.corda.tools.shell.utlities.StdoutANSIProgressRenderer
|
||||
import org.crsh.command.InvocationContext
|
||||
@ -185,7 +183,7 @@ object InteractiveShell {
|
||||
// Don't use the Java language plugin (we may not have tools.jar available at runtime), this
|
||||
// will cause any commands using JIT Java compilation to be suppressed. In CRaSH upstream that
|
||||
// is only the 'jmx' command.
|
||||
return super.getPlugins().filterNot { it is JavaLanguage } + CordaAuthenticationPlugin(rpcOps, InteractiveShell.classLoader)
|
||||
return super.getPlugins().filterNot { it is JavaLanguage } + CordaAuthenticationPlugin(rpcOps)
|
||||
}
|
||||
}
|
||||
val attributes = emptyMap<String, Any>()
|
||||
@ -194,8 +192,7 @@ object InteractiveShell {
|
||||
this.config = config
|
||||
start(context)
|
||||
ops = makeRPCOps(rpcOps, localUserName, localUserPassword)
|
||||
return context.getPlugin(ShellFactory::class.java)
|
||||
.create(null, CordaSSHAuthInfo(false, ops, InteractiveShell.classLoader, StdoutANSIProgressRenderer))
|
||||
return context.getPlugin(ShellFactory::class.java).create(null, CordaSSHAuthInfo(false, ops, StdoutANSIProgressRenderer))
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,7 +212,7 @@ object InteractiveShell {
|
||||
return outputFormat
|
||||
}
|
||||
|
||||
fun createYamlInputMapper(rpcOps: CordaRPCOps, classLoader: ClassLoader?): ObjectMapper {
|
||||
fun createYamlInputMapper(rpcOps: CordaRPCOps): ObjectMapper {
|
||||
// Return a standard Corda Jackson object mapper, configured to use YAML by default and with extra
|
||||
// serializers.
|
||||
return JacksonSupport.createDefaultMapper(rpcOps, YAMLFactory(), true).apply {
|
||||
@ -223,15 +220,6 @@ object InteractiveShell {
|
||||
addDeserializer(InputStream::class.java, InputStreamDeserializer)
|
||||
addDeserializer(UniqueIdentifier::class.java, UniqueIdentifierDeserializer)
|
||||
}
|
||||
if(classLoader != null){
|
||||
// Scan for CustomShellSerializationFactory on the classloader and register them as modules.
|
||||
val customModules = ClassGraph().addClassLoader(classLoader).enableClassInfo().pooledScan().use { scan ->
|
||||
scan.getClassesImplementing(CustomShellSerializationFactory::class.java.name)
|
||||
.map { it.loadClass().newInstance() as CustomShellSerializationFactory }
|
||||
}
|
||||
log.info("Found the following custom shell serialization modules: ${customModules.map { it.javaClass.name }}")
|
||||
customModules.forEach { registerModule(it.createJacksonModule()) }
|
||||
}
|
||||
registerModule(rpcModule)
|
||||
}
|
||||
}
|
||||
@ -274,7 +262,7 @@ object InteractiveShell {
|
||||
output: RenderPrintWriter,
|
||||
rpcOps: CordaRPCOps,
|
||||
ansiProgressRenderer: ANSIProgressRenderer,
|
||||
inputObjectMapper: ObjectMapper) {
|
||||
inputObjectMapper: ObjectMapper = createYamlInputMapper(rpcOps)) {
|
||||
val matches = try {
|
||||
rpcOps.registeredFlows().filter { nameFragment in it }
|
||||
} catch (e: PermissionException) {
|
||||
@ -371,7 +359,7 @@ object InteractiveShell {
|
||||
fun killFlowById(id: String,
|
||||
output: RenderPrintWriter,
|
||||
rpcOps: CordaRPCOps,
|
||||
inputObjectMapper: ObjectMapper) {
|
||||
inputObjectMapper: ObjectMapper = createYamlInputMapper(rpcOps)) {
|
||||
try {
|
||||
val runId = try {
|
||||
inputObjectMapper.readValue(id, StateMachineRunId::class.java)
|
||||
|
Loading…
Reference in New Issue
Block a user