From 26af99a8a24afaae948f5312ad22ee5850087d3c Mon Sep 17 00:00:00 2001 From: G r e y Date: Fri, 4 Dec 2020 05:46:45 +0000 Subject: [PATCH 1/2] cli: Use map for config-ssh ux State write Context: config-ssh needs to be re-ran when new environments are created. Therefore the existing data structure assumption of cliSSHConfigured as a boolean needs to be udpated to reflect environment identifiers. --- internal/cmd/configssh.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index aa709c61..05bf0142 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -135,7 +135,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st fmt.Printf("Your private ssh key was written to \"%s\"\n", privateKeyFilepath) } - writeSSHUXState(ctx, client, user.ID) + writeSSHUXState(ctx, client, user.ID, envs) fmt.Printf("An auto-generated ssh config was written to \"%s\"\n", *configpath) fmt.Println("You should now be able to ssh into your environment") fmt.Printf("For example, try running\n\n\t$ ssh coder.%s\n\n", envs[0].Name) @@ -258,10 +258,18 @@ func readStr(filename string) (string, error) { return string(contents), nil } -func writeSSHUXState(ctx context.Context, client *coder.Client, userID string) { +func writeSSHUXState(ctx context.Context, client *coder.Client, userID string, envs []coder.Environment) { + // Create a map of env.ID -> true to indicate to the web client that as of + // all their current environments have SSH configured. This command needs + // to be re-run each time new environments are created in order for them + // to have access. + cliSSHConfigured := make(map[string]bool) + for _, env := range envs { + cliSSHConfigured[env.ID] = true + } // Update UXState that coder config-ssh has been run by the currently // authenticated user - err := client.UpdateUXState(ctx, userID, map[string]interface{}{"cliSSHConfigured": true}) + err := client.UpdateUXState(ctx, userID, map[string]interface{}{"cliSSHConfigured": cliSSHConfigured}) if err != nil { clog.LogWarn("The Coder web client may not recognize that you've configured SSH.") } From 647362331ddf40b685ec07efa90717d7a1c3bec6 Mon Sep 17 00:00:00 2001 From: G r e y Date: Fri, 4 Dec 2020 05:55:57 +0000 Subject: [PATCH 2/2] fixup! cli: Use map for config-ssh ux State write --- internal/cmd/configssh.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index 05bf0142..5af1ea56 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -259,10 +259,8 @@ func readStr(filename string) (string, error) { } func writeSSHUXState(ctx context.Context, client *coder.Client, userID string, envs []coder.Environment) { - // Create a map of env.ID -> true to indicate to the web client that as of - // all their current environments have SSH configured. This command needs - // to be re-run each time new environments are created in order for them - // to have access. + // Create a map of env.ID -> true to indicate to the web client that all + // current environments have SSH configured cliSSHConfigured := make(map[string]bool) for _, env := range envs { cliSSHConfigured[env.ID] = true