|
| 1 | +package vscodeipc |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "io" |
| 6 | + "net/http" |
| 7 | + |
| 8 | + "github.com/go-chi/chi/v5" |
| 9 | + "github.com/google/uuid" |
| 10 | + "golang.org/x/xerrors" |
| 11 | + |
| 12 | + "github.com/coder/coder/codersdk" |
| 13 | +) |
| 14 | + |
| 15 | +// It's a lil http server that listens for messages from the VS Code extension. |
| 16 | +// It can listen on macOS and Windows, and explicitly blocks any web requests. |
| 17 | + |
| 18 | +type Dial struct { |
| 19 | + // |
| 20 | +} |
| 21 | + |
| 22 | +type PortForward struct { |
| 23 | +} |
| 24 | + |
| 25 | +type Exec struct { |
| 26 | +} |
| 27 | + |
| 28 | +type ExecRequest struct { |
| 29 | + Command string |
| 30 | +} |
| 31 | + |
| 32 | +type PortForwardRequest struct { |
| 33 | + Port string |
| 34 | +} |
| 35 | + |
| 36 | +type NetworkStats struct { |
| 37 | + P2P bool |
| 38 | + Latency float64 |
| 39 | + PreferredDERP int |
| 40 | + DERPLatency map[string]float64 |
| 41 | +} |
| 42 | + |
| 43 | +func New(ctx context.Context, client *codersdk.Client, agentID uuid.UUID, options *codersdk.DialWorkspaceAgentOptions) (http.Handler, io.Closer, error) { |
| 44 | + r := chi.NewRouter() |
| 45 | + agentConn, err := client.DialWorkspaceAgent(ctx, agentID, &codersdk.DialWorkspaceAgentOptions{}) |
| 46 | + if err != nil { |
| 47 | + return nil, nil, err |
| 48 | + } |
| 49 | + reachable := agentConn.AwaitReachable(ctx) |
| 50 | + if !reachable { |
| 51 | + return nil, nil, xerrors.New("we weren't reachable") |
| 52 | + } |
| 53 | + r.Get("/network", func(w http.ResponseWriter, r *http.Request) { |
| 54 | + // This returns tracked network information! |
| 55 | + }) |
| 56 | + r.Get("/port/{port}", func(w http.ResponseWriter, r *http.Request) { |
| 57 | + // This transforms into a port forward! |
| 58 | + }) |
| 59 | + r.Post("/exec", func(w http.ResponseWriter, r *http.Request) { |
| 60 | + // This |
| 61 | + }) |
| 62 | + r.Post("/stop", func(w http.ResponseWriter, r *http.Request) { |
| 63 | + |
| 64 | + }) |
| 65 | + return r, agentConn, nil |
| 66 | +} |
0 commit comments