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

Commit 26af99a

Browse files
committed
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.
1 parent 1f16b2b commit 26af99a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

internal/cmd/configssh.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
135135
fmt.Printf("Your private ssh key was written to \"%s\"\n", privateKeyFilepath)
136136
}
137137

138-
writeSSHUXState(ctx, client, user.ID)
138+
writeSSHUXState(ctx, client, user.ID, envs)
139139
fmt.Printf("An auto-generated ssh config was written to \"%s\"\n", *configpath)
140140
fmt.Println("You should now be able to ssh into your environment")
141141
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) {
258258
return string(contents), nil
259259
}
260260

261-
func writeSSHUXState(ctx context.Context, client *coder.Client, userID string) {
261+
func writeSSHUXState(ctx context.Context, client *coder.Client, userID string, envs []coder.Environment) {
262+
// Create a map of env.ID -> true to indicate to the web client that as of
263+
// all their current environments have SSH configured. This command needs
264+
// to be re-run each time new environments are created in order for them
265+
// to have access.
266+
cliSSHConfigured := make(map[string]bool)
267+
for _, env := range envs {
268+
cliSSHConfigured[env.ID] = true
269+
}
262270
// Update UXState that coder config-ssh has been run by the currently
263271
// authenticated user
264-
err := client.UpdateUXState(ctx, userID, map[string]interface{}{"cliSSHConfigured": true})
272+
err := client.UpdateUXState(ctx, userID, map[string]interface{}{"cliSSHConfigured": cliSSHConfigured})
265273
if err != nil {
266274
clog.LogWarn("The Coder web client may not recognize that you've configured SSH.")
267275
}

0 commit comments

Comments
 (0)