summaryrefslogtreecommitdiff
path: root/cmd/client/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/client/client.go')
-rw-r--r--cmd/client/client.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/cmd/client/client.go b/cmd/client/client.go
index 62f1f48..7799b87 100644
--- a/cmd/client/client.go
+++ b/cmd/client/client.go
@@ -26,19 +26,23 @@ import (
26// This should be compiled into the binary 26// This should be compiled into the binary
27var clientId string 27var clientId string
28 28
29func Register(root *cobra.Command) { 29func NewClientCommand() *cobra.Command {
30 clientCmd := &cobra.Command{ 30 clientCmd := &cobra.Command{
31 Use: "client proxy-host ssh-to-host ssh-port username", 31 Use: "client proxy-host ssh-to-host ssh-port username",
32 Short: "Run websocket client", 32 Short: "Run websocket client",
33 Args: cobra.ExactArgs(4), 33 Args: cobra.ExactArgs(3),
34 Run: func(c *cobra.Command, args []string) { 34 Run: func(c *cobra.Command, args []string) {
35 cfg := app.Config{} 35 cfg := app.Config{}
36 cli.MustGetConfig(c, &cfg) 36 cli.MustGetConfig(c, &cfg)
37 clientMain(cfg, args[0], args[1], args[2], args[3]) 37 clientMain(cfg, args[0], args[1], args[2])
38 }, 38 },
39 } 39 }
40 cli.AddFlags(clientCmd, &app.Config{}, app.DefaultConfig, "client") 40 cli.AddFlags(clientCmd, &app.Config{}, app.DefaultConfig, "client")
41 root.AddCommand(clientCmd) 41 return clientCmd
42}
43
44func Register(root *cobra.Command) {
45 root.AddCommand(NewClientCommand())
42} 46}
43 47
44func generateCertificateRequest(username, host string) (ed25519.PrivateKey, []byte, error) { 48func generateCertificateRequest(username, host string) (ed25519.PrivateKey, []byte, error) {
@@ -181,13 +185,13 @@ func fetchOauthToken(ctx context.Context, clientId, proxyHost string) (string, e
181 return tokenResponse.AccessToken, nil 185 return tokenResponse.AccessToken, nil
182} 186}
183 187
184func clientMain(cfg app.Config, proxyHost, host, port, username string) { 188func clientMain(cfg app.Config, host, port, username string) {
185 log.SetOutput(os.Stderr) 189 log.SetOutput(os.Stderr)
186 190
187 ctx, cancel := context.WithCancel(context.Background()) 191 ctx, cancel := context.WithCancel(context.Background())
188 defer cancel() 192 defer cancel()
189 193
190 oauthToken, err := fetchOauthToken(ctx, clientId, proxyHost) 194 oauthToken, err := fetchOauthToken(ctx, clientId, cfg.ClientHost)
191 if err != nil { 195 if err != nil {
192 log.Fatalf("Error fetching oauth token: %s", err) 196 log.Fatalf("Error fetching oauth token: %s", err)
193 } 197 }
@@ -197,7 +201,7 @@ func clientMain(cfg app.Config, proxyHost, host, port, username string) {
197 log.Fatalf("Error generating certificate request: %s", err) 201 log.Fatalf("Error generating certificate request: %s", err)
198 } 202 }
199 203
200 certificate, err := getCertificateFromCA(ctx, oauthToken, certRequest, proxyHost) 204 certificate, err := getCertificateFromCA(ctx, oauthToken, certRequest, cfg.ClientHost)
201 if err != nil { 205 if err != nil {
202 log.Fatalf("Error fetching certificate: %s", err) 206 log.Fatalf("Error fetching certificate: %s", err)
203 } 207 }
@@ -206,7 +210,7 @@ func clientMain(cfg app.Config, proxyHost, host, port, username string) {
206 log.Fatalf("Error adding certificate to agent: %s", err) 210 log.Fatalf("Error adding certificate to agent: %s", err)
207 } 211 }
208 212
209 ws, err := dialProxyHost(ctx, oauthToken, proxyHost, host, port) 213 ws, err := dialProxyHost(ctx, oauthToken, cfg.ClientHost, host, port)
210 if err != nil { 214 if err != nil {
211 log.Fatalf("Error dialing proxy host: %s", err) 215 log.Fatalf("Error dialing proxy host: %s", err)
212 } 216 }