Skip to content

Commit cffb2f4

Browse files
committed
Print information after login
1 parent cf78ae0 commit cffb2f4

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

components/local-app/cmd/login.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ var loginCmd = &cobra.Command{
6666

6767
err = auth.SetToken(loginOpts.Host, token)
6868
if err != nil {
69-
slog.Warn("could not write token to keyring, storing in config file instead", "err", err)
69+
slog.Debug("could not write token to keyring, storing in config file instead")
70+
slog.Warn("could not write token to keyring, storing in config file instead. Use -v to see the error.")
7071
gpctx.Token = token
7172
}
7273

@@ -115,7 +116,18 @@ var loginCmd = &cobra.Command{
115116
return err
116117
}
117118

118-
return nil
119+
client, err := getGitpodClient(config.ToContext(cmd.Context(), cfg))
120+
if err != nil {
121+
return err
122+
}
123+
who, err := whoami(cmd.Context(), client, gpctx)
124+
if err != nil {
125+
return err
126+
}
127+
128+
slog.Info("Login succesfull")
129+
fmt.Println()
130+
return WriteTabular(who, formatOpts{}, prettyprint.WriterFormatNarrow)
119131
},
120132
}
121133

components/local-app/cmd/whoami.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
package cmd
66

77
import (
8+
"context"
9+
810
"github.com/bufbuild/connect-go"
11+
"github.com/gitpod-io/gitpod/components/public-api/go/client"
912
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
1013
"github.com/gitpod-io/local-app/pkg/config"
1114
"github.com/gitpod-io/local-app/pkg/prettyprint"
@@ -28,27 +31,37 @@ var whoamiCmd = &cobra.Command{
2831
return err
2932
}
3033

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)
3635
if err != nil {
3736
return err
3837
}
3938

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)
4940
},
5041
}
5142

43+
// printWhoami prints 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+
5265
type whoamiResult struct {
5366
Name string `print:"user name"`
5467
ID string `print:"user id"`

0 commit comments

Comments
 (0)