-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |