(ctx context.Context, version *apiversion.APIVersion, role string)
| 354 | } |
| 355 | |
| 356 | func (c *Client) connectRPCVersion(ctx context.Context, version *apiversion.APIVersion, role string) (drpc.Conn, error) { |
| 357 | rpcURL, err := c.SDK.URL.Parse("/api/v2/workspaceagents/me/rpc") |
| 358 | if err != nil { |
| 359 | return nil, xerrors.Errorf("parse url: %w", err) |
| 360 | } |
| 361 | q := rpcURL.Query() |
| 362 | q.Add("version", version.String()) |
| 363 | if role != "" { |
| 364 | q.Add("role", role) |
| 365 | } |
| 366 | rpcURL.RawQuery = q.Encode() |
| 367 | |
| 368 | httpClient := &http.Client{ |
| 369 | Transport: c.SDK.HTTPClient.Transport, |
| 370 | } |
| 371 | // nolint:bodyclose |
| 372 | conn, res, err := websocket.Dial(ctx, rpcURL.String(), &websocket.DialOptions{ |
| 373 | HTTPClient: httpClient, |
| 374 | HTTPHeader: http.Header{ |
| 375 | codersdk.SessionTokenHeader: []string{c.SDK.SessionToken()}, |
| 376 | }, |
| 377 | }) |
| 378 | if err != nil { |
| 379 | if res == nil { |
| 380 | return nil, err |
| 381 | } |
| 382 | return nil, codersdk.ReadBodyAsError(res) |
| 383 | } |
| 384 | |
| 385 | // Set the read limit to 4 MiB -- about the limit for protobufs. This needs to be larger than |
| 386 | // the default because some of our protocols can include large messages like startup scripts. |
| 387 | conn.SetReadLimit(1 << 22) |
| 388 | netConn := websocket.NetConn(ctx, conn, websocket.MessageBinary) |
| 389 | |
| 390 | config := yamux.DefaultConfig() |
| 391 | config.LogOutput = nil |
| 392 | config.Logger = slog.Stdlib(ctx, c.SDK.Logger(), slog.LevelInfo) |
| 393 | session, err := yamux.Client(netConn, config) |
| 394 | if err != nil { |
| 395 | return nil, xerrors.Errorf("multiplex client: %w", err) |
| 396 | } |
| 397 | return drpcsdk.MultiplexedConn(session), nil |
| 398 | } |
| 399 | |
| 400 | type PostAppHealthsRequest struct { |
| 401 | // Healths is a map of the workspace app name and the health of the app. |
no test coverage detected