Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Use environment dictionary in config-ssh ux state call #199

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
greyscaled committed Dec 4, 2020
commit 26af99a8a24afaae948f5312ad22ee5850087d3c
14 changes: 11 additions & 3 deletions internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.")
}
Expand Down