Skip to content

Commit 09377b0

Browse files
committed
feat: add support to override gotty url
1 parent 1fb9756 commit 09377b0

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

cmd/scw/testdata/test-all-usage-instance-server-console-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ USAGE:
88
ARGS:
99
server-id Server ID to connect to
1010
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | nl-ams-3 | pl-waw-1 | pl-waw-2 | pl-waw-3)
11+
[ws-url] WebSocket URL to connect to (overrides default)
1112

1213
FLAGS:
1314
-h, --help help for console

internal/gotty/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/url"
99
"os"
10+
"strings"
1011
"time"
1112

1213
"github.com/containerd/console"
@@ -40,6 +41,16 @@ func NewClient(zone scw.Zone, serverID string, secretKey string) (*Client, error
4041
}, nil
4142
}
4243

44+
// SetWsURL updates the WebSocket URL for the client.
45+
func (c *Client) SetWsURL(url string) error {
46+
// Basic validation that it's a wss URL
47+
if !strings.HasPrefix(url, "wss://") {
48+
return fmt.Errorf("URL must start with wss://")
49+
}
50+
c.wsURL = url
51+
return nil
52+
}
53+
4354
func (c *Client) Connect() error {
4455
wsDialer := websocket.Dialer{}
4556
conn, _, err := wsDialer.Dial(c.wsURL, nil)

internal/namespaces/instance/v1/custom_server_console.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
type instanceConsoleServerArgs struct {
2121
Zone scw.Zone
2222
ServerID string
23+
WsURL string
2324
}
2425

2526
func serverConsoleCommand() *core.Command {
@@ -37,6 +38,10 @@ func serverConsoleCommand() *core.Command {
3738
Positional: true,
3839
},
3940
core.ZoneArgSpec((*instance.API)(nil).Zones()...),
41+
{
42+
Name: "ws-url",
43+
Short: "WebSocket URL to connect to (overrides default)",
44+
},
4045
},
4146
Run: instanceServerConsoleRun,
4247
}
@@ -66,6 +71,14 @@ func instanceServerConsoleRun(ctx context.Context, argsI any) (i any, e error) {
6671
return nil, err
6772
}
6873

74+
// If a custom WebSocket URL was provided, use it
75+
if args.WsURL != "" {
76+
err = ttyClient.SetWsURL(args.WsURL)
77+
if err != nil {
78+
return nil, fmt.Errorf("invalid WebSocket URL: %w", err)
79+
}
80+
}
81+
6982
// Add hint on how to quit properly
7083
fmt.Printf(terminal.Style("Open connection to %s (%s)\n", color.Bold), server.Name, server.ID)
7184
fmt.Println(" - You may need to hit enter to start")

0 commit comments

Comments
 (0)