From 565d03df79f127bb4bbcf0768715afb983b029b7 Mon Sep 17 00:00:00 2001 From: Pudong Zheng Date: Mon, 13 Jun 2022 08:16:49 +0000 Subject: [PATCH] [DEBUG] add debug command --- dev/gpctl/cmd/workspaces-update-ssh-keys.go | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 dev/gpctl/cmd/workspaces-update-ssh-keys.go diff --git a/dev/gpctl/cmd/workspaces-update-ssh-keys.go b/dev/gpctl/cmd/workspaces-update-ssh-keys.go new file mode 100644 index 00000000000000..187733a2a93ce3 --- /dev/null +++ b/dev/gpctl/cmd/workspaces-update-ssh-keys.go @@ -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 ", + 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) +}