Skip to content

Commit 24dc2c2

Browse files
author
lgmugnier
authored
(CWC-670) Add check for shell instantiation (#43)
* Add check for shell instantiation We want to catch the situation where the shell isn't instantiated and throw that as a keysplitting error. * update version file
1 parent dbab95b commit 24dc2c2

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.732.17
1+
3.0.732.18

agent/keysplitting/contracts/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,5 @@ const (
131131
ChannelClosed KeysplittingErrorType = "ChannelClosed"
132132
OutdatedHPointer KeysplittingErrorType = "OutdatedHPointer"
133133
BZECertExpiredInitialIdToken KeysplittingErrorType = "BZECertExpiredInitialIdToken"
134+
HandlerNotReady KeysplittingErrorType = "HandlerNotReady"
134135
)

agent/session/plugins/interactivecommands/interactivecommands.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@ func (p *InteractiveCommandsPlugin) forwardMessage(log log.T, streamDataMessage
193193
Payload: []byte(payload.Payload), // a string for Output or a json {cols: x, rows: y} for Size
194194
PayloadType: uint32(payloadtype), // either Output or Size
195195
}
196-
return p.shell.InputStreamMessageHandler(log, agentMessage)
196+
197+
if p.shell.Ready() {
198+
return p.shell.InputStreamMessageHandler(log, agentMessage)
199+
} else {
200+
message := "Shell not yet ready for incoming messages"
201+
return p.ksHelper.BuildError(message, kysplContracts.HandlerNotReady)
202+
}
197203
} else {
198204
message := fmt.Sprintf("[Keysplitting] Keysplitting Handshake is required to communicate with shell")
199205
return p.ksHelper.BuildError(message, kysplContracts.ChannelClosed)

agent/session/shell/shell.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ type logger struct {
7272
type IShellPlugin interface {
7373
Execute(config agentContracts.Configuration, cancelFlag task.CancelFlag, output iohandler.IOHandler, dataChannel datachannel.IDataChannel, shellProps mgsContracts.ShellProperties)
7474
InputStreamMessageHandler(log log.T, streamDataMessage mgsContracts.AgentMessage) error
75+
Ready() bool
76+
}
77+
78+
func (p *ShellPlugin) Ready() bool {
79+
return !(p.stdin == nil || p.stdout == nil)
7580
}
7681

7782
// NewPlugin returns a new instance of the Shell Plugin

0 commit comments

Comments
 (0)