Skip to content

Commit 826cca3

Browse files
committed
Rename Agent Metadata to Agent Manifest
1 parent 3cb3b74 commit 826cca3

File tree

10 files changed

+96
-86
lines changed

10 files changed

+96
-86
lines changed

agent/agent.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type Options struct {
8181
}
8282

8383
type Client interface {
84-
Metadata(ctx context.Context) (agentsdk.Metadata, error)
84+
Manifest(ctx context.Context) (agentsdk.Manifest, error)
8585
Listen(ctx context.Context) (net.Conn, error)
8686
ReportStats(ctx context.Context, log slog.Logger, statsChan <-chan *agentsdk.Stats, setInterval func(time.Duration)) (io.Closer, error)
8787
PostLifecycle(ctx context.Context, state agentsdk.PostLifecycleRequest) error
@@ -274,7 +274,7 @@ func (a *agent) run(ctx context.Context) error {
274274
}
275275
a.sessionToken.Store(&sessionToken)
276276

277-
metadata, err := a.client.Metadata(ctx)
277+
metadata, err := a.client.Manifest(ctx)
278278
if err != nil {
279279
return xerrors.Errorf("fetch metadata: %w", err)
280280
}
@@ -804,7 +804,7 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
804804
if rawMetadata == nil {
805805
return nil, xerrors.Errorf("no metadata was provided")
806806
}
807-
metadata, valid := rawMetadata.(agentsdk.Metadata)
807+
metadata, valid := rawMetadata.(agentsdk.Manifest)
808808
if !valid {
809809
return nil, xerrors.Errorf("metadata is the wrong type: %T", metadata)
810810
}
@@ -940,7 +940,7 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
940940
session.DisablePTYEmulation()
941941

942942
if !isQuietLogin(session.RawCommand()) {
943-
metadata, ok := a.metadata.Load().(agentsdk.Metadata)
943+
metadata, ok := a.metadata.Load().(agentsdk.Manifest)
944944
if ok {
945945
err = showMOTD(session, metadata.MOTDFile)
946946
if err != nil {
@@ -1330,7 +1330,7 @@ func (a *agent) Close() error {
13301330
a.setLifecycle(ctx, codersdk.WorkspaceAgentLifecycleShuttingDown)
13311331

13321332
lifecycleState := codersdk.WorkspaceAgentLifecycleOff
1333-
if metadata, ok := a.metadata.Load().(agentsdk.Metadata); ok && metadata.ShutdownScript != "" {
1333+
if metadata, ok := a.metadata.Load().(agentsdk.Manifest); ok && metadata.ShutdownScript != "" {
13341334
scriptDone := make(chan error, 1)
13351335
scriptStart := time.Now()
13361336
go func() {

agent/agent_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestAgent_Stats_SSH(t *testing.T) {
6060
defer cancel()
6161

6262
//nolint:dogsled
63-
conn, _, stats, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
63+
conn, _, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
6464

6565
sshClient, err := conn.SSHClient(ctx)
6666
require.NoError(t, err)
@@ -93,7 +93,7 @@ func TestAgent_Stats_ReconnectingPTY(t *testing.T) {
9393
defer cancel()
9494

9595
//nolint:dogsled
96-
conn, _, stats, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
96+
conn, _, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
9797

9898
ptyConn, err := conn.ReconnectingPTY(ctx, uuid.New(), 128, 128, "/bin/bash")
9999
require.NoError(t, err)
@@ -123,7 +123,7 @@ func TestAgent_Stats_Magic(t *testing.T) {
123123
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
124124
defer cancel()
125125
//nolint:dogsled
126-
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
126+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
127127
sshClient, err := conn.SSHClient(ctx)
128128
require.NoError(t, err)
129129
defer sshClient.Close()
@@ -150,7 +150,7 @@ func TestAgent_Stats_Magic(t *testing.T) {
150150
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
151151
defer cancel()
152152
//nolint:dogsled
153-
conn, _, stats, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
153+
conn, _, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
154154
sshClient, err := conn.SSHClient(ctx)
155155
require.NoError(t, err)
156156
defer sshClient.Close()
@@ -185,7 +185,7 @@ func TestAgent_Stats_Magic(t *testing.T) {
185185

186186
func TestAgent_SessionExec(t *testing.T) {
187187
t.Parallel()
188-
session := setupSSHSession(t, agentsdk.Metadata{})
188+
session := setupSSHSession(t, agentsdk.Manifest{})
189189

190190
command := "echo test"
191191
if runtime.GOOS == "windows" {
@@ -198,7 +198,7 @@ func TestAgent_SessionExec(t *testing.T) {
198198

199199
func TestAgent_GitSSH(t *testing.T) {
200200
t.Parallel()
201-
session := setupSSHSession(t, agentsdk.Metadata{})
201+
session := setupSSHSession(t, agentsdk.Manifest{})
202202
command := "sh -c 'echo $GIT_SSH_COMMAND'"
203203
if runtime.GOOS == "windows" {
204204
command = "cmd.exe /c echo %GIT_SSH_COMMAND%"
@@ -218,7 +218,7 @@ func TestAgent_SessionTTYShell(t *testing.T) {
218218
// it seems like it could be either.
219219
t.Skip("ConPTY appears to be inconsistent on Windows.")
220220
}
221-
session := setupSSHSession(t, agentsdk.Metadata{})
221+
session := setupSSHSession(t, agentsdk.Manifest{})
222222
command := "sh"
223223
if runtime.GOOS == "windows" {
224224
command = "cmd.exe"
@@ -241,7 +241,7 @@ func TestAgent_SessionTTYShell(t *testing.T) {
241241

242242
func TestAgent_SessionTTYExitCode(t *testing.T) {
243243
t.Parallel()
244-
session := setupSSHSession(t, agentsdk.Metadata{})
244+
session := setupSSHSession(t, agentsdk.Manifest{})
245245
command := "areallynotrealcommand"
246246
err := session.RequestPty("xterm", 128, 128, ssh.TerminalModes{})
247247
require.NoError(t, err)
@@ -280,7 +280,7 @@ func TestAgent_Session_TTY_MOTD(t *testing.T) {
280280
// Set HOME so we can ensure no ~/.hushlogin is present.
281281
t.Setenv("HOME", tmpdir)
282282

283-
session := setupSSHSession(t, agentsdk.Metadata{
283+
session := setupSSHSession(t, agentsdk.Manifest{
284284
MOTDFile: name,
285285
})
286286
err = session.RequestPty("xterm", 128, 128, ssh.TerminalModes{})
@@ -326,7 +326,7 @@ func TestAgent_Session_TTY_Hushlogin(t *testing.T) {
326326
// Set HOME so we can ensure ~/.hushlogin is present.
327327
t.Setenv("HOME", tmpdir)
328328

329-
session := setupSSHSession(t, agentsdk.Metadata{
329+
session := setupSSHSession(t, agentsdk.Manifest{
330330
MOTDFile: name,
331331
})
332332
err = session.RequestPty("xterm", 128, 128, ssh.TerminalModes{})
@@ -607,7 +607,7 @@ func TestAgent_SFTP(t *testing.T) {
607607
home = "/" + strings.ReplaceAll(home, "\\", "/")
608608
}
609609
//nolint:dogsled
610-
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
610+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
611611
sshClient, err := conn.SSHClient(ctx)
612612
require.NoError(t, err)
613613
defer sshClient.Close()
@@ -639,7 +639,7 @@ func TestAgent_SCP(t *testing.T) {
639639
defer cancel()
640640

641641
//nolint:dogsled
642-
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
642+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
643643
sshClient, err := conn.SSHClient(ctx)
644644
require.NoError(t, err)
645645
defer sshClient.Close()
@@ -658,7 +658,7 @@ func TestAgent_EnvironmentVariables(t *testing.T) {
658658
t.Parallel()
659659
key := "EXAMPLE"
660660
value := "value"
661-
session := setupSSHSession(t, agentsdk.Metadata{
661+
session := setupSSHSession(t, agentsdk.Manifest{
662662
EnvironmentVariables: map[string]string{
663663
key: value,
664664
},
@@ -675,7 +675,7 @@ func TestAgent_EnvironmentVariables(t *testing.T) {
675675
func TestAgent_EnvironmentVariableExpansion(t *testing.T) {
676676
t.Parallel()
677677
key := "EXAMPLE"
678-
session := setupSSHSession(t, agentsdk.Metadata{
678+
session := setupSSHSession(t, agentsdk.Manifest{
679679
EnvironmentVariables: map[string]string{
680680
key: "$SOMETHINGNOTSET",
681681
},
@@ -702,7 +702,7 @@ func TestAgent_CoderEnvVars(t *testing.T) {
702702
t.Run(key, func(t *testing.T) {
703703
t.Parallel()
704704

705-
session := setupSSHSession(t, agentsdk.Metadata{})
705+
session := setupSSHSession(t, agentsdk.Manifest{})
706706
command := "sh -c 'echo $" + key + "'"
707707
if runtime.GOOS == "windows" {
708708
command = "cmd.exe /c echo %" + key + "%"
@@ -725,7 +725,7 @@ func TestAgent_SSHConnectionEnvVars(t *testing.T) {
725725
t.Run(key, func(t *testing.T) {
726726
t.Parallel()
727727

728-
session := setupSSHSession(t, agentsdk.Metadata{})
728+
session := setupSSHSession(t, agentsdk.Manifest{})
729729
command := "sh -c 'echo $" + key + "'"
730730
if runtime.GOOS == "windows" {
731731
command = "cmd.exe /c echo %" + key + "%"
@@ -744,7 +744,7 @@ func TestAgent_StartupScript(t *testing.T) {
744744
}
745745
content := "output"
746746
//nolint:dogsled
747-
_, _, _, fs, _ := setupAgent(t, agentsdk.Metadata{
747+
_, _, _, fs, _ := setupAgent(t, agentsdk.Manifest{
748748
StartupScript: "echo " + content,
749749
}, 0)
750750
var gotContent string
@@ -778,7 +778,7 @@ func TestAgent_Lifecycle(t *testing.T) {
778778
t.Run("StartTimeout", func(t *testing.T) {
779779
t.Parallel()
780780

781-
_, client, _, _, _ := setupAgent(t, agentsdk.Metadata{
781+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
782782
StartupScript: "sleep 5",
783783
StartupScriptTimeout: time.Nanosecond,
784784
}, 0)
@@ -807,7 +807,7 @@ func TestAgent_Lifecycle(t *testing.T) {
807807
t.Run("StartError", func(t *testing.T) {
808808
t.Parallel()
809809

810-
_, client, _, _, _ := setupAgent(t, agentsdk.Metadata{
810+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
811811
StartupScript: "false",
812812
StartupScriptTimeout: 30 * time.Second,
813813
}, 0)
@@ -836,7 +836,7 @@ func TestAgent_Lifecycle(t *testing.T) {
836836
t.Run("Ready", func(t *testing.T) {
837837
t.Parallel()
838838

839-
_, client, _, _, _ := setupAgent(t, agentsdk.Metadata{
839+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
840840
StartupScript: "true",
841841
StartupScriptTimeout: 30 * time.Second,
842842
}, 0)
@@ -865,7 +865,7 @@ func TestAgent_Lifecycle(t *testing.T) {
865865
t.Run("ShuttingDown", func(t *testing.T) {
866866
t.Parallel()
867867

868-
_, client, _, _, closer := setupAgent(t, agentsdk.Metadata{
868+
_, client, _, _, closer := setupAgent(t, agentsdk.Manifest{
869869
ShutdownScript: "sleep 5",
870870
StartupScriptTimeout: 30 * time.Second,
871871
}, 0)
@@ -903,7 +903,7 @@ func TestAgent_Lifecycle(t *testing.T) {
903903
t.Run("ShutdownTimeout", func(t *testing.T) {
904904
t.Parallel()
905905

906-
_, client, _, _, closer := setupAgent(t, agentsdk.Metadata{
906+
_, client, _, _, closer := setupAgent(t, agentsdk.Manifest{
907907
ShutdownScript: "sleep 5",
908908
ShutdownScriptTimeout: time.Nanosecond,
909909
}, 0)
@@ -950,7 +950,7 @@ func TestAgent_Lifecycle(t *testing.T) {
950950
t.Run("ShutdownError", func(t *testing.T) {
951951
t.Parallel()
952952

953-
_, client, _, _, closer := setupAgent(t, agentsdk.Metadata{
953+
_, client, _, _, closer := setupAgent(t, agentsdk.Manifest{
954954
ShutdownScript: "false",
955955
ShutdownScriptTimeout: 30 * time.Second,
956956
}, 0)
@@ -1001,7 +1001,7 @@ func TestAgent_Lifecycle(t *testing.T) {
10011001
client := &client{
10021002
t: t,
10031003
agentID: uuid.New(),
1004-
metadata: agentsdk.Metadata{
1004+
manifest: agentsdk.Manifest{
10051005
DERPMap: tailnettest.RunDERPAndSTUN(t),
10061006
StartupScript: "echo 1",
10071007
ShutdownScript: "echo " + expected,
@@ -1054,7 +1054,7 @@ func TestAgent_Startup(t *testing.T) {
10541054
t.Run("EmptyDirectory", func(t *testing.T) {
10551055
t.Parallel()
10561056

1057-
_, client, _, _, _ := setupAgent(t, agentsdk.Metadata{
1057+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
10581058
StartupScript: "true",
10591059
StartupScriptTimeout: 30 * time.Second,
10601060
Directory: "",
@@ -1068,7 +1068,7 @@ func TestAgent_Startup(t *testing.T) {
10681068
t.Run("HomeDirectory", func(t *testing.T) {
10691069
t.Parallel()
10701070

1071-
_, client, _, _, _ := setupAgent(t, agentsdk.Metadata{
1071+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
10721072
StartupScript: "true",
10731073
StartupScriptTimeout: 30 * time.Second,
10741074
Directory: "~",
@@ -1084,7 +1084,7 @@ func TestAgent_Startup(t *testing.T) {
10841084
t.Run("HomeEnvironmentVariable", func(t *testing.T) {
10851085
t.Parallel()
10861086

1087-
_, client, _, _, _ := setupAgent(t, agentsdk.Metadata{
1087+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
10881088
StartupScript: "true",
10891089
StartupScriptTimeout: 30 * time.Second,
10901090
Directory: "$HOME",
@@ -1111,7 +1111,7 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
11111111
defer cancel()
11121112

11131113
//nolint:dogsled
1114-
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
1114+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
11151115
id := uuid.New()
11161116
netConn, err := conn.ReconnectingPTY(ctx, id, 100, 100, "/bin/bash")
11171117
require.NoError(t, err)
@@ -1213,7 +1213,7 @@ func TestAgent_Dial(t *testing.T) {
12131213
}()
12141214

12151215
//nolint:dogsled
1216-
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
1216+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
12171217
require.True(t, conn.AwaitReachable(context.Background()))
12181218
conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String())
12191219
require.NoError(t, err)
@@ -1235,7 +1235,7 @@ func TestAgent_Speedtest(t *testing.T) {
12351235
defer cancel()
12361236
derpMap := tailnettest.RunDERPAndSTUN(t)
12371237
//nolint:dogsled
1238-
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{
1238+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{
12391239
DERPMap: derpMap,
12401240
}, 0)
12411241
defer conn.Close()
@@ -1257,7 +1257,7 @@ func TestAgent_Reconnect(t *testing.T) {
12571257
client := &client{
12581258
t: t,
12591259
agentID: agentID,
1260-
metadata: agentsdk.Metadata{
1260+
manifest: agentsdk.Manifest{
12611261
DERPMap: derpMap,
12621262
},
12631263
statsChan: statsCh,
@@ -1292,7 +1292,7 @@ func TestAgent_WriteVSCodeConfigs(t *testing.T) {
12921292
client := &client{
12931293
t: t,
12941294
agentID: uuid.New(),
1295-
metadata: agentsdk.Metadata{
1295+
manifest: agentsdk.Manifest{
12961296
GitAuthConfigs: 1,
12971297
DERPMap: &tailcfg.DERPMap{},
12981298
},
@@ -1321,7 +1321,7 @@ func TestAgent_WriteVSCodeConfigs(t *testing.T) {
13211321

13221322
func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exec.Cmd {
13231323
//nolint:dogsled
1324-
agentConn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
1324+
agentConn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
13251325
listener, err := net.Listen("tcp", "127.0.0.1:0")
13261326
require.NoError(t, err)
13271327
waitGroup := sync.WaitGroup{}
@@ -1364,7 +1364,7 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
13641364
return exec.Command("ssh", args...)
13651365
}
13661366

1367-
func setupSSHSession(t *testing.T, options agentsdk.Metadata) *ssh.Session {
1367+
func setupSSHSession(t *testing.T, options agentsdk.Manifest) *ssh.Session {
13681368
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
13691369
defer cancel()
13701370
//nolint:dogsled
@@ -1388,7 +1388,7 @@ func (c closeFunc) Close() error {
13881388
return c()
13891389
}
13901390

1391-
func setupAgent(t *testing.T, metadata agentsdk.Metadata, ptyTimeout time.Duration) (
1391+
func setupAgent(t *testing.T, metadata agentsdk.Manifest, ptyTimeout time.Duration) (
13921392
*codersdk.WorkspaceAgentConn,
13931393
*client,
13941394
<-chan *agentsdk.Stats,
@@ -1408,7 +1408,7 @@ func setupAgent(t *testing.T, metadata agentsdk.Metadata, ptyTimeout time.Durati
14081408
c := &client{
14091409
t: t,
14101410
agentID: agentID,
1411-
metadata: metadata,
1411+
manifest: metadata,
14121412
statsChan: statsCh,
14131413
coordinator: coordinator,
14141414
}
@@ -1491,7 +1491,7 @@ func assertWritePayload(t *testing.T, w io.Writer, payload []byte) {
14911491
type client struct {
14921492
t *testing.T
14931493
agentID uuid.UUID
1494-
metadata agentsdk.Metadata
1494+
manifest agentsdk.Manifest
14951495
statsChan chan *agentsdk.Stats
14961496
coordinator tailnet.Coordinator
14971497
lastWorkspaceAgent func()
@@ -1501,8 +1501,8 @@ type client struct {
15011501
startup agentsdk.PostStartupRequest
15021502
}
15031503

1504-
func (c *client) Metadata(_ context.Context) (agentsdk.Metadata, error) {
1505-
return c.metadata, nil
1504+
func (c *client) Manifest(_ context.Context) (agentsdk.Manifest, error) {
1505+
return c.manifest, nil
15061506
}
15071507

15081508
func (c *client) Listen(_ context.Context) (net.Conn, error) {

coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func New(options *Options) *API {
590590
r.Post("/google-instance-identity", api.postWorkspaceAuthGoogleInstanceIdentity)
591591
r.Route("/me", func(r chi.Router) {
592592
r.Use(httpmw.ExtractWorkspaceAgent(options.Database))
593-
r.Get("/metadata", api.workspaceAgentMetadata)
593+
r.Get("/manifest", api.workspaceAgentManifest)
594594
r.Post("/startup", api.postWorkspaceAgentStartup)
595595
r.Post("/app-health", api.postWorkspaceAppHealth)
596596
r.Get("/gitauth", api.workspaceAgentsGitAuth)

0 commit comments

Comments
 (0)