| 1 |
package core |
| 2 |
|
| 3 |
import "io" |
| 4 |
|
| 5 |
// ShellTransport provides an abstraction for getting shell access to a host; |
| 6 |
// e.g. via SSH or just local shell. In the future, tsh (Teleport) might be |
| 7 |
// supported as well, and maybe something else. |
| 8 |
type ShellTransport interface { |
| 9 |
// Connect attempts to connect to the shell. It just spawns a goroutine and |
| 10 |
// returns immediately, and later on the result (or maybe requests for |
| 11 |
// additional data such as passphrases) will be delivered to the provided |
| 12 |
// channel. |
| 13 |
Connect(resCh chan<- ShellConnUpdate) |
| 14 |
} |
| 15 |
|
| 16 |
// ShellConn provides an abstraction of a shell connection; can be implemented |
| 17 |
// by local shell, or SSH, or maybe something else. |
| 18 |
type ShellConn interface { |
| 19 |
Stdin() io.Writer |
| 20 |
Stdout() io.Reader |
| 21 |
Stderr() io.Reader |
| 22 |
|
| 23 |
// Close should be called when the connection is not needed anymore. |
| 24 |
Close() |
| 25 |
} |
| 26 |
|
| 27 |
// ShellConnUpdate contains the update from ssh connection. Exactly one |
| 28 |
// field must be non-nil. |
| 29 |
type ShellConnUpdate struct { |
| 30 |
// Info contains some debugging info about the connection, typically sent |
| 31 |
// before trying to connect. |
| 32 |
DebugInfo *ShellConnDebugInfo |
| 33 |
|
| 34 |
// DataRequest contains request for additional data from the user. |
| 35 |
DataRequest *ShellConnDataRequest |
| 36 |
|
| 37 |
// Result contains the final connection result. After receiving an update |
| 38 |
// with non-nil Result, there will be no more messages to this channel. |
| 39 |
Result *ShellConnResult |
| 40 |
} |
| 41 |
|
| 42 |
// ShellConnDebugInfo contains some debugging human-readable info about the |
| 43 |
// connection. |
| 44 |
type ShellConnDebugInfo struct { |
| 45 |
// Message contains some arbitrary human-readable details about the connection. |
| 46 |
Message string |
| 47 |
} |
| 48 |
|
| 49 |
// ShellConnResult contains the connection result. If the connection is |
| 50 |
// successful, Conn is non-nil; otherwise, Err is non-nil. |
| 51 |
type ShellConnResult struct { |
| 52 |
Conn ShellConn |
| 53 |
Err error |
| 54 |
} |
| 55 |
|
| 56 |
// ShellConnDataRequest contains request for additional data from the user |
| 57 |
// which might be needed during connection, e.g. the passphrase to decrypt |
| 58 |
// ssh private key. |
| 59 |
type ShellConnDataRequest struct { |
| 60 |
// Title is a human-readable title to show on the data request dialog. |
| 61 |
// If empty, will be "Data request". |
| 62 |
Title string |
| 63 |
|
| 64 |
// Message is a human-readable message to show to the user when asking for data. |
| 65 |
Message string |
| 66 |
|
| 67 |
// DataKind specifies what kind of data we're requesting from the user. |
| 68 |
DataKind ShellConnDataKind |
| 69 |
|
| 70 |
// ResponseCh is where the user response should be sent. |
| 71 |
ResponseCh chan<- string |
| 72 |
} |
| 73 |
|
| 74 |
type ShellConnDataKind int |
| 75 |
|
| 76 |
const ( |
| 77 |
ShellConnDataKindPassword ShellConnDataKind = iota |
| 78 |
) |