Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ USAGE:
ARGS:
server-id Server ID to connect to
[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)
[ws-url] WebSocket URL to connect to (overrides default)

FLAGS:
-h, --help help for console
Expand Down
1 change: 1 addition & 0 deletions docs/commands/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@ scw instance server console <server-id ...> [arg=value ...]
|------|---|-------------|
| server-id | Required | Server ID to connect to |
| zone | Default: `fr-par-1`<br />One of: `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` | Zone to target. If none is passed will use default zone from the config |
| ws-url | | WebSocket URL to connect to (overrides default) |



Expand Down
13 changes: 13 additions & 0 deletions internal/gotty/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package gotty

import (
"encoding/base64"
"errors"
"fmt"
"net/url"
"os"
"strings"
"time"

"github.com/containerd/console"
Expand Down Expand Up @@ -40,6 +42,17 @@ func NewClient(zone scw.Zone, serverID string, secretKey string) (*Client, error
}, nil
}

// SetWsURL updates the WebSocket URL for the client.
func (c *Client) SetWsURL(url string) error {
// Basic validation that it's a wss URL
if !strings.HasPrefix(url, "wss://") {
return errors.New("URL must start with wss://")
}
c.wsURL = url

return nil
}

func (c *Client) Connect() error {
wsDialer := websocket.Dialer{}
conn, _, err := wsDialer.Dial(c.wsURL, nil)
Expand Down
13 changes: 13 additions & 0 deletions internal/namespaces/instance/v1/custom_server_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
type instanceConsoleServerArgs struct {
Zone scw.Zone
ServerID string
WsURL string
}

func serverConsoleCommand() *core.Command {
Expand All @@ -37,6 +38,10 @@ func serverConsoleCommand() *core.Command {
Positional: true,
},
core.ZoneArgSpec((*instance.API)(nil).Zones()...),
{
Name: "ws-url",
Short: "WebSocket URL to connect to (overrides default)",
},
},
Run: instanceServerConsoleRun,
}
Expand Down Expand Up @@ -66,6 +71,14 @@ func instanceServerConsoleRun(ctx context.Context, argsI any) (i any, e error) {
return nil, err
}

// If a custom WebSocket URL was provided, use it
if args.WsURL != "" {
err = ttyClient.SetWsURL(args.WsURL)
if err != nil {
return nil, fmt.Errorf("invalid WebSocket URL: %w", err)
}
}

// Add hint on how to quit properly
fmt.Printf(terminal.Style("Open connection to %s (%s)\n", color.Bold), server.Name, server.ID)
fmt.Println(" - You may need to hit enter to start")
Expand Down
Loading