Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit6df7494

Browse files
authored
Add coder-sdk executor interface (#177)
1 parent82282b1 commit6df7494

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

‎coder-sdk/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type configSetupMode struct {
100100
func (cClient)SiteSetupModeEnabled(ctx context.Context) (bool,error) {
101101
varconfconfigSetupMode
102102
iferr:=c.requestBody(ctx,http.MethodGet,"/api/config/setup-mode",nil,&conf);err!=nil {
103-
returnfalse,nil
103+
returnfalse,err
104104
}
105105
returnconf.SetupMode,nil
106106
}

‎coder-sdk/env.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"time"
77

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

143144
// DialWsep dials an environments command execution interface
144145
// See https://github.com/cdr/wsep for details.
145-
func (cClient)DialWsep(ctx context.Context,env*Environment) (*websocket.Conn,error) {
146-
returnc.dialWebsocket(ctx,"/proxy/environments/"+env.ID+"/wsep")
146+
func (cClient)DialWsep(ctx context.Context,envIDstring) (*websocket.Conn,error) {
147+
returnc.dialWebsocket(ctx,"/proxy/environments/"+envID+"/wsep")
148+
}
149+
150+
// DialExecutor gives a remote execution interface for performing commands inside an environment.
151+
func (cClient)DialExecutor(ctx context.Context,envIDstring) (wsep.Execer,error) {
152+
ws,err:=c.DialWsep(ctx,envID)
153+
iferr!=nil {
154+
returnnil,err
155+
}
156+
returnwsep.RemoteExecer(ws),nil
147157
}
148158

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

236246
// WaitForEnvironmentReady will watch the build log and return when done.
237-
func (cClient)WaitForEnvironmentReady(ctx context.Context,env*Environment)error {
238-
conn,err:=c.DialEnvironmentBuildLog(ctx,env.ID)
247+
func (cClient)WaitForEnvironmentReady(ctx context.Context,envIDstring)error {
248+
conn,err:=c.DialEnvironmentBuildLog(ctx,envID)
239249
iferr!=nil {
240-
returnxerrors.Errorf("%s: dial build log: %w",env.Name,err)
250+
returnxerrors.Errorf("%s: dial build log: %w",envID,err)
241251
}
242252

243253
for {
244254
msg:=buildLogMsg{}
245255
err:=wsjson.Read(ctx,conn,&msg)
246256
iferr!=nil {
247-
returnxerrors.Errorf("%s: reading build log msg: %w",env.Name,err)
257+
returnxerrors.Errorf("%s: reading build log msg: %w",envID,err)
248258
}
249259

250260
ifmsg.Type==BuildLogTypeDone {

‎internal/cmd/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func runCommand(ctx context.Context, envName, command string, args []string) err
140140
ctx,cancel:=context.WithCancel(ctx)
141141
defercancel()
142142

143-
conn,err:=client.DialWsep(ctx,env)
143+
conn,err:=client.DialWsep(ctx,env.ID)
144144
iferr!=nil {
145145
returnxerrors.Errorf("dial websocket: %w",err)
146146
}

‎internal/sync/singlefile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// SingleFile copies the given file into the remote dir or remote path of the given coder.Environment.
1919
funcSingleFile(ctx context.Context,local,remoteDirstring,env*coder.Environment,client*coder.Client)error {
20-
conn,err:=client.DialWsep(ctx,env)
20+
conn,err:=client.DialWsep(ctx,env.ID)
2121
iferr!=nil {
2222
returnxerrors.Errorf("dial remote execer: %w",err)
2323
}

‎internal/sync/sync.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (s Sync) syncPaths(delete bool, local, remote string) error {
8989
}
9090

9191
func (sSync)remoteCmd(ctx context.Context,progstring,args...string)error {
92-
conn,err:=s.Client.DialWsep(ctx,&s.Env)
92+
conn,err:=s.Client.DialWsep(ctx,s.Env.ID)
9393
iferr!=nil {
9494
returnxerrors.Errorf("dial websocket: %w",err)
9595
}
@@ -270,7 +270,7 @@ func (s Sync) Version() (string, error) {
270270
ctx,cancel:=context.WithTimeout(context.Background(),10*time.Second)
271271
defercancel()
272272

273-
conn,err:=s.Client.DialWsep(ctx,&s.Env)
273+
conn,err:=s.Client.DialWsep(ctx,s.Env.ID)
274274
iferr!=nil {
275275
return"",err
276276
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp