5
5
package cmd
6
6
7
7
import (
8
+ "context"
9
+
8
10
"github.com/bufbuild/connect-go"
11
+ "github.com/gitpod-io/gitpod/components/public-api/go/client"
9
12
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
10
13
"github.com/gitpod-io/local-app/pkg/config"
11
14
"github.com/gitpod-io/local-app/pkg/prettyprint"
@@ -28,27 +31,37 @@ var whoamiCmd = &cobra.Command{
28
31
return err
29
32
}
30
33
31
- user , err := client .User .GetAuthenticatedUser (cmd .Context (), & connect.Request [v1.GetAuthenticatedUserRequest ]{})
32
- if err != nil {
33
- return err
34
- }
35
- org , err := client .Teams .GetTeam (cmd .Context (), & connect.Request [v1.GetTeamRequest ]{Msg : & v1.GetTeamRequest {TeamId : gpctx .OrganizationID }})
34
+ who , err := whoami (cmd .Context (), client , gpctx )
36
35
if err != nil {
37
36
return err
38
37
}
39
38
40
- return WriteTabular ([]whoamiResult {
41
- {
42
- Name : user .Msg .GetUser ().Name ,
43
- ID : user .Msg .GetUser ().Id ,
44
- Org : org .Msg .GetTeam ().Name ,
45
- OrgID : org .Msg .GetTeam ().Id ,
46
- Host : gpctx .Host .String (),
47
- },
48
- }, whoamiOpts .Format , prettyprint .WriterFormatNarrow )
39
+ return WriteTabular (who , whoamiOpts .Format , prettyprint .WriterFormatNarrow )
49
40
},
50
41
}
51
42
43
+ // whoami returns information about the currently logged in user
44
+ func whoami (ctx context.Context , client * client.Gitpod , gpctx * config.ConnectionContext ) ([]whoamiResult , error ) {
45
+ user , err := client .User .GetAuthenticatedUser (ctx , & connect.Request [v1.GetAuthenticatedUserRequest ]{})
46
+ if err != nil {
47
+ return nil , err
48
+ }
49
+ org , err := client .Teams .GetTeam (ctx , & connect.Request [v1.GetTeamRequest ]{Msg : & v1.GetTeamRequest {TeamId : gpctx .OrganizationID }})
50
+ if err != nil {
51
+ return nil , err
52
+ }
53
+
54
+ return []whoamiResult {
55
+ {
56
+ Name : user .Msg .GetUser ().Name ,
57
+ ID : user .Msg .GetUser ().Id ,
58
+ Org : org .Msg .GetTeam ().Name ,
59
+ OrgID : org .Msg .GetTeam ().Id ,
60
+ Host : gpctx .Host .String (),
61
+ },
62
+ }, nil
63
+ }
64
+
52
65
type whoamiResult struct {
53
66
Name string `print:"user name"`
54
67
ID string `print:"user id"`
0 commit comments