@@ -2,6 +2,7 @@ package cli
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
5
6
6
7
"github.com/coder/coder/v2/cli/cliui"
7
8
"github.com/coder/coder/v2/codersdk"
@@ -10,8 +11,13 @@ import (
10
11
)
11
12
12
13
type whoamiRow struct {
13
- URL string `json:"url" table:"URL,default_sort"`
14
- Username string `json:"username" table:"Username"`
14
+ URL string `json:"url" table:"URL,default_sort"`
15
+ Username string `json:"username" table:"Username"`
16
+ UserID string `json:"user_id" table:"ID"`
17
+ OrganizationIDs string `json:"-" table:"Orgs"`
18
+ OrganizationIDsJSON []string `json:"organization_ids" table:"-"`
19
+ Roles string `json:"-" table:"Roles"`
20
+ RolesJSON map [string ][]string `json:"roles" table:"-"`
15
21
}
16
22
17
23
func (r whoamiRow )String ()string {
@@ -26,7 +32,7 @@ func (r *RootCmd) whoami() *serpent.Command {
26
32
formatter := cliui .NewOutputFormatter (
27
33
cliui .TextFormat (),
28
34
cliui .JSONFormat (),
29
- cliui .TableFormat ([]whoamiRow {}, []string {"url" ,"username" }),
35
+ cliui .TableFormat ([]whoamiRow {}, []string {"url" ,"username" , "id" }),
30
36
)
31
37
cmd := & serpent.Command {
32
38
Annotations :workspaceCommand ,
@@ -50,10 +56,29 @@ func (r *RootCmd) whoami() *serpent.Command {
50
56
return err
51
57
}
52
58
59
+ orgIDs := make ([]string ,0 ,len (resp .OrganizationIDs ))
60
+ for _ ,orgID := range resp .OrganizationIDs {
61
+ orgIDs = append (orgIDs ,orgID .String ())
62
+ }
63
+
64
+ roles := make ([]string ,0 ,len (resp .Roles ))
65
+ jsonRoles := make (map [string ][]string )
66
+ for _ ,role := range resp .Roles {
67
+ if role .OrganizationID == "" {
68
+ role .OrganizationID = "*"
69
+ }
70
+ roles = append (roles ,fmt .Sprintf ("%s:%s" ,role .OrganizationID ,role .DisplayName ))
71
+ jsonRoles [role .OrganizationID ]= append (jsonRoles [role .OrganizationID ],role .DisplayName )
72
+ }
53
73
out ,err := formatter .Format (ctx , []whoamiRow {
54
74
{
55
- URL :clientURL .String (),
56
- Username :resp .Username ,
75
+ URL :clientURL .String (),
76
+ Username :resp .Username ,
77
+ UserID :resp .ID .String (),
78
+ OrganizationIDs :strings .Join (orgIDs ,"," ),
79
+ OrganizationIDsJSON :orgIDs ,
80
+ Roles :strings .Join (roles ,"," ),
81
+ RolesJSON :jsonRoles ,
57
82
},
58
83
})
59
84
if err != nil {