@@ -23,7 +23,8 @@ type SSHInput struct {
2323 InstanceID string // Set when a specific instance is selected or provided
2424 Project * client.Project
2525 EnvironmentIDs []string
26- Ephemeral bool `cli:"ephemeral"`
26+ Ephemeral bool `cli:"ephemeral"`
27+ Size string `cli:"size"`
2728
2829 Args []string
2930}
@@ -47,22 +48,35 @@ func handleSSHError(err error) error {
4748// createEphemeralShell creates an ephemeral shell pod for the given service
4849// and returns the ephemeral shell id from the API response (empty string if
4950// the response did not include one). This must be called before SSH'ing into
50- // an ephemeral shell.
51- func createEphemeralShell (ctx context.Context , serviceID string ) (string , error ) {
51+ // an ephemeral shell. If size is non-empty, it is sent as the requested
52+ // instance plan name.
53+ func createEphemeralShell (ctx context.Context , serviceID , size string ) (string , error ) {
5254 apiCfg , err := config .DefaultAPIConfig ()
5355 if err != nil {
5456 return "" , fmt .Errorf ("failed to get API config: %w" , err )
5557 }
5658
5759 url := fmt .Sprintf ("%sservices/%s/ephemeral-shell" , apiCfg .Host , serviceID )
5860
59- req , err := http .NewRequestWithContext (ctx , http .MethodPost , url , bytes .NewReader (nil ))
61+ var reqBody io.Reader = bytes .NewReader (nil )
62+ if size != "" {
63+ payload , err := json .Marshal (client.CreateEphemeralShellJSONRequestBody {Size : & size })
64+ if err != nil {
65+ return "" , fmt .Errorf ("failed to encode request body: %w" , err )
66+ }
67+ reqBody = bytes .NewReader (payload )
68+ }
69+
70+ req , err := http .NewRequestWithContext (ctx , http .MethodPost , url , reqBody )
6071 if err != nil {
6172 return "" , fmt .Errorf ("failed to create request: %w" , err )
6273 }
6374
6475 req .Header = client .AddHeaders (req .Header , apiCfg .Key )
6576 req .Header .Set ("Accept" , "application/json" )
77+ if size != "" {
78+ req .Header .Set ("Content-Type" , "application/json" )
79+ }
6680
6781 resp , err := http .DefaultClient .Do (req )
6882 if err != nil {
@@ -185,9 +199,16 @@ func loadDataSSH(ctx context.Context, in *SSHInput) (*exec.Cmd, error) {
185199 }
186200 }
187201
202+ if in .Size != "" && ! in .Ephemeral {
203+ return nil , tui.UserFacingError {
204+ Title : "Invalid flags" ,
205+ Message : "--size is only supported with --ephemeral." ,
206+ }
207+ }
208+
188209 if in .Ephemeral {
189210 // Create the ephemeral shell pod first
190- shellID , err := createEphemeralShell (ctx , serviceInfo .Id )
211+ shellID , err := createEphemeralShell (ctx , serviceInfo .Id , in . Size )
191212 if err != nil {
192213 return nil , tui.UserFacingError {
193214 Title : "Failed to create ephemeral shell" ,
0 commit comments