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

cli: Update UXState from config-ssh #195

Merged
merged 1 commit into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions coder-sdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ func (c Client) UpdateUser(ctx context.Context, userID string, req UpdateUserReq
return c.requestBody(ctx, http.MethodPatch, "/api/private/users/"+userID, req, nil)
}

// UpdateUXState applies a partial update of the user's UX State.
func (c Client) UpdateUXState(ctx context.Context, userID string, uxsPartial map[string]interface{}) error {
if err := c.requestBody(ctx, http.MethodPut, "/api/private/users/"+userID+"/ux-state", uxsPartial, nil); err != nil {
return err
}
return nil
}

// CreateUserReq defines the request parameters for creating a new user resource.
type CreateUserReq struct {
Name string `json:"name"`
Expand Down
12 changes: 12 additions & 0 deletions internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"
"time"

"cdr.dev/coder-cli/pkg/clog"

"cdr.dev/coder-cli/coder-sdk"
"cdr.dev/coder-cli/internal/config"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -135,6 +137,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)
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 @@ -215,3 +218,12 @@ func readStr(filename string) (string, error) {
}
return string(contents), nil
}

func writeSSHUXState(ctx context.Context, client *coder.Client, userID string) {
// Update UXState that coder config-ssh has been run by the currently
// authenticated user
err := client.UpdateUXState(ctx, userID, map[string]interface{}{"cliSSHConfigured": true})
if err != nil {
clog.LogWarn("The Coder web client may not recognize that you've configured SSH.")
}
}