acquireShellSession waits for the session and picks a shell tool. On failure it marks the task as failed and returns nil.
(ctx ModuleContext, sessionID string, taskID uint32, moduleName string)
| 87 | // acquireShellSession waits for the session and picks a shell tool. |
| 88 | // On failure it marks the task as failed and returns nil. |
| 89 | func acquireShellSession(ctx ModuleContext, sessionID string, taskID uint32, moduleName string) (*sessions.Session, string) { |
| 90 | sess := ctx.WaitForSession(sessionID, DefaultSessionTimeout) |
| 91 | if sess == nil { |
| 92 | log.Warnf("[bridge] session %s not found for %s", sessionID, moduleName) |
| 93 | ctx.Tasks.Fail(sessionID, taskID, "session not found") |
| 94 | return nil, "" |
| 95 | } |
| 96 | // Re-attempt session listener now that the session exists. |
| 97 | // The initial call in handleSpiteRecv may have failed if the session |
| 98 | // was not yet created (e.g. after proxy restart). |
| 99 | ctx.Tasks.StartSessionListener(sessionID) |
| 100 | toolName := sessions.PickShellTool(sess) |
| 101 | if toolName == "" { |
| 102 | log.Warnf("[bridge] no shell tool found in session %s for %s", sessionID, moduleName) |
| 103 | ctx.Tasks.Fail(sessionID, taskID, "no shell tool") |
| 104 | return nil, "" |
| 105 | } |
| 106 | return sess, toolName |
| 107 | } |
| 108 | |
| 109 | // enqueueAndAwait builds a PendingAction, enqueues it, binds it to the task, |
| 110 | // and waits for the result. Returns nil if any step fails. |
no test coverage detected