github.com/viant/toolbox@v0.34.5/ssh/session_replay.go (about) 1 package ssh 2 3 import ( 4 "errors" 5 "strings" 6 ) 7 8 const commandNotFound = "Command not found" 9 10 type replayMultiCommandSession struct { 11 shellPrompt string 12 system string 13 replay *ReplayCommands 14 } 15 16 func (s *replayMultiCommandSession) Run(command string, listener Listener, timeoutMs int, terminators ...string) (string, error) { 17 if !strings.HasSuffix(command, "\n") { 18 command = command + "\n" 19 } 20 21 replay, ok := s.replay.Commands[command] 22 if !ok { 23 return commandNotFound, nil 24 } 25 if replay.Error != "" { 26 return "", errors.New(replay.Error) 27 } 28 return s.replay.Next(command), nil 29 } 30 31 func (s *replayMultiCommandSession) Reconnect() error { 32 return errors.New("unsupported") 33 } 34 35 func (s *replayMultiCommandSession) ShellPrompt() string { 36 return s.shellPrompt 37 } 38 39 func (s *replayMultiCommandSession) System() string { 40 return s.system 41 } 42 43 func (s *replayMultiCommandSession) Close() { 44 45 } 46 47 func NewReplayMultiCommandSession(shellPrompt, system string, commands *ReplayCommands) MultiCommandSession { 48 return &replayMultiCommandSession{ 49 shellPrompt: shellPrompt, 50 system: system, 51 replay: commands, 52 } 53 }