Skip to content

Commit 3ea943b

Browse files
committed
[DEBUG] add debug command
1 parent 4b2f218 commit 3ea943b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"context"
9+
"io/ioutil"
10+
"strings"
11+
12+
"github.com/spf13/cobra"
13+
14+
"github.com/gitpod-io/gitpod/common-go/log"
15+
"github.com/gitpod-io/gitpod/ws-manager/api"
16+
)
17+
18+
// workspaceUpdateSSHKeys represents the describe command
19+
var workspaceUpdateSSHKeys = &cobra.Command{
20+
Use: "update-ssh-keys <workspaceID> <public_key_path>",
21+
Short: "update ssh keys",
22+
Args: cobra.ExactArgs(2),
23+
Run: func(cmd *cobra.Command, args []string) {
24+
ctx, cancel := context.WithCancel(context.Background())
25+
defer cancel()
26+
27+
conn, client, err := getWorkspacesClient(ctx)
28+
if err != nil {
29+
log.WithError(err).Fatal("cannot connect")
30+
}
31+
defer conn.Close()
32+
33+
instanceID := args[0]
34+
fp := args[1]
35+
var content []byte
36+
if content, err = ioutil.ReadFile(fp); err != nil {
37+
panic(err)
38+
}
39+
if strings.ContainsAny(instanceID, ".") || strings.HasPrefix(instanceID, "http://") || strings.HasPrefix(instanceID, "https://") {
40+
s, err := getStatusByURL(ctx, client, instanceID)
41+
if err != nil {
42+
log.Fatal(err)
43+
}
44+
instanceID = s.Id
45+
}
46+
keys := []string{string(content)}
47+
_, err = client.UpdateSSHKey(ctx, &api.UpdateSSHKeyRequest{
48+
Id: instanceID,
49+
Keys: keys,
50+
})
51+
if err != nil {
52+
log.WithError(err).Fatal("error during RPC call")
53+
}
54+
},
55+
}
56+
57+
func init() {
58+
workspacesCmd.AddCommand(workspaceUpdateSSHKeys)
59+
}

0 commit comments

Comments
 (0)