Skip to content

Commit

Permalink
[DEBUG] add debug command
Browse files Browse the repository at this point in the history
  • Loading branch information
iQQBot committed Jun 14, 2022
1 parent 50d2add commit 565d03d
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions dev/gpctl/cmd/workspaces-update-ssh-keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"context"
"io/ioutil"
"strings"

"github.com/spf13/cobra"

"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/ws-manager/api"
)

// workspaceUpdateSSHKeys represents the describe command
var workspaceUpdateSSHKeys = &cobra.Command{
Use: "update-ssh-keys <workspaceID> <public_key_path>",
Short: "update ssh keys",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

conn, client, err := getWorkspacesClient(ctx)
if err != nil {
log.WithError(err).Fatal("cannot connect")
}
defer conn.Close()

instanceID := args[0]
fp := args[1]
var content []byte
if content, err = ioutil.ReadFile(fp); err != nil {
panic(err)
}
if strings.ContainsAny(instanceID, ".") || strings.HasPrefix(instanceID, "http://") || strings.HasPrefix(instanceID, "https://") {
s, err := getStatusByURL(ctx, client, instanceID)
if err != nil {
log.Fatal(err)
}
instanceID = s.Id
}
keys := []string{string(content)}
_, err = client.UpdateSSHKey(ctx, &api.UpdateSSHKeyRequest{
Id: instanceID,
Keys: keys,
})
if err != nil {
log.WithError(err).Fatal("error during RPC call")
}
},
}

func init() {
workspacesCmd.AddCommand(workspaceUpdateSSHKeys)
}

0 comments on commit 565d03d

Please sign in to comment.