From 8f1dcc2698d8088509898e05b14d93ed739f42ec Mon Sep 17 00:00:00 2001 From: Vasek Mlejnsky Date: Thu, 7 May 2020 20:19:14 +0200 Subject: [PATCH] Handle admin pod --- cmd/root.go | 3 ++- connection/connection.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 326e46f..a946b05 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -19,6 +19,7 @@ import ( type FoundryConf struct { ServiceAccPath string `yaml:"serviceAcc"` IgnoreStrPatterns []string `yaml:"ignore"` + Admin bool `yaml:"admin"` CurrentDir string `yaml:"-"` // Current working directory of CLI Ignore []glob.Glob `yaml:"-"` @@ -165,7 +166,7 @@ func cobraInitCallback(cmd string) { if cmd == "go" { // Create a new connection to the cloud env fmt.Println("Connecting to your cloud environment...") - c, err := conn.New(authClient.IDToken) + c, err := conn.New(authClient.IDToken, foundryConf.Admin) if err != nil { logger.FdebuglnFatal("Connection error", err) logger.FatalLogln(err) diff --git a/connection/connection.go b/connection/connection.go index 5b15f3d..a04a232 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -2,6 +2,7 @@ package connection import ( "fmt" + "strconv" "time" "foundry/cli/connection/endpoint" @@ -26,9 +27,9 @@ type ConnectionMessage interface { // Gorilla's websocket.Conn can be accessed only from a single // goroutine. -func New(token string) (*Connection, error) { +func New(token string, admin bool) (*Connection, error) { logger.Fdebugln("WS dialing") - url := WebSocketURL(token) + url := WebSocketURL(token, admin) c, _, err := websocket.DefaultDialer.Dial(url, nil) if err != nil { return nil, err @@ -82,8 +83,8 @@ func (c *Connection) Ping(pm *msg.PingMsg, ticker *time.Ticker, stop <-chan stru } } -func WebSocketURL(token string) string { - return fmt.Sprintf("%s://%s/ws/%s", endpoint.WebSocketScheme, endpoint.WebSocketURL, token) +func WebSocketURL(token string, admin bool) string { + return fmt.Sprintf("%s://%s/ws/%s?admin=%s", endpoint.WebSocketScheme, endpoint.WebSocketURL, token, strconv.FormatBool(admin)) } func PingURL() string {