Skip to content

Commit 0a4e54c

Browse files
robstolarzclaude
andcommitted
feat: add --org flag to depot sandbox exec/pty/exec-pipe (DEP-4184)
The Go API's RemoteExec/OpenPtySession requires x-depot-org header for multi-org users. Without it, auth fails with Unauthorized. Adds --org as a persistent flag on the sandbox parent command and threads it through to auth headers in all three subcommands. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 522bfb6 commit 0a4e54c

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

pkg/cmd/sandbox/exec-pipe.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func newSandboxExecPipe() *cobra.Command {
3737
return fmt.Errorf("failed to resolve token: %w", err)
3838
}
3939

40+
orgID, err := cmd.Flags().GetString("org")
41+
cobra.CheckErr(err)
42+
4043
sandboxID, err := cmd.Flags().GetString("sandbox-id")
4144
cobra.CheckErr(err)
4245

@@ -60,6 +63,9 @@ func newSandboxExecPipe() *cobra.Command {
6063
client := api.NewComputeClient()
6164
stream := client.ExecPipe(ctx)
6265
stream.RequestHeader().Set("Authorization", "Bearer "+token)
66+
if orgID != "" {
67+
stream.RequestHeader().Set("x-depot-org", orgID)
68+
}
6369

6470
// Send init message with the command.
6571
if err := stream.Send(&civ1.ExecuteCommandPipeRequest{

pkg/cmd/sandbox/exec.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func newSandboxExec() *cobra.Command {
3838
return fmt.Errorf("failed to resolve token: %w", err)
3939
}
4040

41+
orgID, err := cmd.Flags().GetString("org")
42+
cobra.CheckErr(err)
43+
4144
sandboxID, err := cmd.Flags().GetString("sandbox-id")
4245
cobra.CheckErr(err)
4346

@@ -57,14 +60,14 @@ func newSandboxExec() *cobra.Command {
5760

5861
client := api.NewComputeClient()
5962

60-
stream, err := client.RemoteExec(ctx, api.WithAuthentication(connect.NewRequest(&civ1.ExecuteCommandRequest{
63+
stream, err := client.RemoteExec(ctx, api.WithAuthenticationAndOrg(connect.NewRequest(&civ1.ExecuteCommandRequest{
6164
SandboxId: sandboxID,
6265
SessionId: sessionID,
6366
Command: &civ1.Command{
6467
CommandArray: args,
6568
TimeoutMs: int32(timeout),
6669
},
67-
}), token))
70+
}), token, orgID))
6871
if err != nil {
6972
// nolint:wrapcheck
7073
return err

pkg/cmd/sandbox/pty.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func newSandboxPty() *cobra.Command {
3535
return fmt.Errorf("failed to resolve token: %w", err)
3636
}
3737

38+
orgID, err := cmd.Flags().GetString("org")
39+
cobra.CheckErr(err)
40+
3841
sandboxID, err := cmd.Flags().GetString("sandbox-id")
3942
cobra.CheckErr(err)
4043

@@ -66,6 +69,7 @@ func newSandboxPty() *cobra.Command {
6669

6770
return pty.Run(ctx, pty.SessionOptions{
6871
Token: token,
72+
OrgID: orgID,
6973
SandboxID: sandboxID,
7074
SessionID: sessionID,
7175
Cwd: cwd,

pkg/cmd/sandbox/sandbox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Subcommands:
1919
}
2020

2121
cmd.PersistentFlags().String("token", "", "Depot API token")
22+
cmd.PersistentFlags().String("org", "", "Organization ID (required when user is a member of multiple organizations)")
2223

2324
cmd.AddCommand(newSandboxExec())
2425
cmd.AddCommand(newSandboxPty())

0 commit comments

Comments
 (0)