Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Cleanups #177

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Cleanups
  • Loading branch information
cmoog committed Nov 4, 2020
commit 8b0b0185104edd88fee184fbbfe13a52ab009fa3
2 changes: 1 addition & 1 deletion coder-sdk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type configSetupMode struct {
func (c Client) SiteSetupModeEnabled(ctx context.Context) (bool, error) {
var conf configSetupMode
if err := c.requestBody(ctx, http.MethodGet, "/api/config/setup-mode", nil, &conf); err != nil {
return false, nil
return false, err
}
return conf.SetupMode, nil
}
Expand Down
22 changes: 16 additions & 6 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"time"

"cdr.dev/wsep"
"golang.org/x/xerrors"
"nhooyr.io/websocket"
"nhooyr.io/websocket/wsjson"
Expand Down Expand Up @@ -142,8 +143,17 @@ func (c Client) EditEnvironment(ctx context.Context, envID string, req UpdateEnv

// DialWsep dials an environments command execution interface
// See https://github.com/cdr/wsep for details.
func (c Client) DialWsep(ctx context.Context, env *Environment) (*websocket.Conn, error) {
return c.dialWebsocket(ctx, "/proxy/environments/"+env.ID+"/wsep")
func (c Client) DialWsep(ctx context.Context, envID string) (*websocket.Conn, error) {
return c.dialWebsocket(ctx, "/proxy/environments/"+envID+"/wsep")
}

// DialExecutor gives a remote execution interface for performing commands inside an environment.
func (c Client) DialExecutor(ctx context.Context, envID string) (wsep.Execer, error) {
ws, err := c.DialWsep(ctx, envID)
if err != nil {
return nil, err
}
return wsep.RemoteExecer(ws), nil
}

// DialIDEStatus opens a websocket connection for cpu load metrics on the environment.
Expand Down Expand Up @@ -234,17 +244,17 @@ type buildLogMsg struct {
}

// WaitForEnvironmentReady will watch the build log and return when done.
func (c Client) WaitForEnvironmentReady(ctx context.Context, env *Environment) error {
conn, err := c.DialEnvironmentBuildLog(ctx, env.ID)
func (c Client) WaitForEnvironmentReady(ctx context.Context, envID string) error {
conn, err := c.DialEnvironmentBuildLog(ctx, envID)
if err != nil {
return xerrors.Errorf("%s: dial build log: %w", env.Name, err)
return xerrors.Errorf("%s: dial build log: %w", envID, err)
}

for {
msg := buildLogMsg{}
err := wsjson.Read(ctx, conn, &msg)
if err != nil {
return xerrors.Errorf("%s: reading build log msg: %w", env.Name, err)
return xerrors.Errorf("%s: reading build log msg: %w", envID, err)
}

if msg.Type == BuildLogTypeDone {
Expand Down