Skip to content

Commit

Permalink
[auth] Improve whoami (#1693)
Browse files Browse the repository at this point in the history
## Summary

TSIA

## How was it tested?
  • Loading branch information
mikeland73 authored Jan 2, 2024
1 parent a0fa00a commit 4e95590
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cli-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: crate-ci/typos@v1.13.16
- uses: crate-ci/typos@v1.16.26

golangci-lint:
needs: build-devbox
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ require (
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
github.com/wk8/go-ordered-map/v2 v2.1.8
github.com/zealic/go2node v0.1.0
go.jetpack.io/envsec v0.0.13
go.jetpack.io/pkg v0.0.0-20231220195442-0c2f1e897695
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848
go.jetpack.io/envsec v0.0.14-0.20231223002340-852b37835912
go.jetpack.io/pkg v0.0.0-20231222235844-de2c9c35ba7c
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
golang.org/x/mod v0.14.0
golang.org/x/sync v0.5.0
golang.org/x/tools v0.16.0
Expand All @@ -50,7 +50,7 @@ require (
)

require (
connectrpc.com/connect v1.13.0 // indirect
connectrpc.com/connect v1.14.0 // indirect
github.com/InVisionApp/go-health/v2 v2.1.3 // indirect
github.com/InVisionApp/go-logger v1.0.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
Expand Down Expand Up @@ -126,5 +126,5 @@ require (
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
connectrpc.com/connect v1.13.0 h1:lGs5maZZzWOOD+PFFiOt5OncKmMsk9ZdPwpy5jcmaYg=
connectrpc.com/connect v1.13.0/go.mod h1:uHAFHtYgeSZJxXrkN1IunDpKghnTXhYbVh0wW4StPW0=
connectrpc.com/connect v1.14.0 h1:PDS+J7uoz5Oui2VEOMcfz6Qft7opQM9hPiKvtGC01pA=
connectrpc.com/connect v1.14.0/go.mod h1:uoAq5bmhhn43TwhaKdGKN/bZcGtzPW1v+ngDTn5u+8s=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
Expand Down Expand Up @@ -377,10 +379,14 @@ go.jetpack.io/envsec v0.0.12-0.20231220042802-d784a6c23f33 h1:E7PQw+0KO7LmtT2ANO
go.jetpack.io/envsec v0.0.12-0.20231220042802-d784a6c23f33/go.mod h1:bR8d9A7SnjABK0uvjJLRedJdFRiPOWkDoo+W374z6X4=
go.jetpack.io/envsec v0.0.13 h1:ZtA747aKU/cjDOMwaiqybKu5HG9dly8/T0p4bxLEvK0=
go.jetpack.io/envsec v0.0.13/go.mod h1:K+gqk7llRfXcGF4zB4WHu6m1/DocSthk4Fh6Dx71doc=
go.jetpack.io/envsec v0.0.14-0.20231223002340-852b37835912 h1:tnth22wvh4nUTED5hZUch7W3NvGGbGqChopkJBXf06A=
go.jetpack.io/envsec v0.0.14-0.20231223002340-852b37835912/go.mod h1:oQ/a382loMMnuypIIaWTLbbVt0xiRO86r79LeAcoDqg=
go.jetpack.io/pkg v0.0.0-20231220014237-68ef53318b2e h1:XYnuIOYcIStIb2WG6krxtln5YlzY66+QdQU78jMAgmI=
go.jetpack.io/pkg v0.0.0-20231220014237-68ef53318b2e/go.mod h1:3bunF5jJUIXf8vWXvu4PHWfHuDj3hgzOyhTXeoBH8Dk=
go.jetpack.io/pkg v0.0.0-20231220195442-0c2f1e897695 h1:ttpYfHeXn9towh6MGjGbd9y+dbSvWYfu/WYoW4kRrlM=
go.jetpack.io/pkg v0.0.0-20231220195442-0c2f1e897695/go.mod h1:3bunF5jJUIXf8vWXvu4PHWfHuDj3hgzOyhTXeoBH8Dk=
go.jetpack.io/pkg v0.0.0-20231222235844-de2c9c35ba7c h1:pVMgrsVoMLRui62Ga0BBaX4ExJzlvr6B+GpFyYxqusg=
go.jetpack.io/pkg v0.0.0-20231222235844-de2c9c35ba7c/go.mod h1:3bunF5jJUIXf8vWXvu4PHWfHuDj3hgzOyhTXeoBH8Dk=
go.jetpack.io/typeid v1.0.0 h1:8gQ+iYGdyiQ0Pr40ydSB/PzMOIwlXX5DTojp1CBeSPQ=
go.jetpack.io/typeid v1.0.0/go.mod h1:+UPEaECUgFxgAjFPn5Yf9eO/3ft/3xZ98Eahv9JW/GQ=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand All @@ -407,6 +413,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -581,6 +589,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
29 changes: 6 additions & 23 deletions internal/boxcli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ package boxcli
import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"
"go.jetpack.io/devbox/internal/boxcli/usererr"
"go.jetpack.io/devbox/internal/build"
"go.jetpack.io/devbox/internal/integrations/envsec"
"go.jetpack.io/pkg/auth"
"go.jetpack.io/pkg/auth/session"
)
Expand Down Expand Up @@ -44,7 +45,7 @@ func loginCmd() *cobra.Command {
if err != nil {
return err
}
fmt.Fprintf(cmd.ErrOrStderr(), "Logged in as : %s\n", t.IDClaims().Email)
fmt.Fprintf(cmd.ErrOrStderr(), "Logged in as: %s\n", t.IDClaims().Email)
return nil
},
}
Expand Down Expand Up @@ -79,30 +80,12 @@ func whoAmICmd() *cobra.Command {
Short: "Show the current user",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
tok, err := genSession(cmd.Context())
wd, err := os.Getwd()
if err != nil {
return err
} else if tok == nil {
return usererr.New("not logged in")
}
idClaims := tok.IDClaims()

fmt.Fprintf(cmd.OutOrStdout(), "Logged in\n")
fmt.Fprintf(cmd.OutOrStdout(), "User ID: %s\n", idClaims.Subject)

if idClaims.OrgID != "" {
fmt.Fprintf(cmd.OutOrStdout(), "Org ID: %s\n", idClaims.OrgID)
}

if idClaims.Email != "" {
fmt.Fprintf(cmd.OutOrStdout(), "Email: %s\n", idClaims.Email)
}

if idClaims.Name != "" {
fmt.Fprintf(cmd.OutOrStdout(), "Name: %s\n", idClaims.Name)
}

return nil
return envsec.DefaultEnvsec(cmd.ErrOrStderr(), wd).
WhoAmI(cmd.Context(), cmd.OutOrStdout(), false)
},
}

Expand Down
8 changes: 7 additions & 1 deletion typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
AKE = "AKE"

[files]
extend-exclude=["*.svg", "**/testdata/**", "internal/cachehash/hash_test.go", "internal/devpkg/package_test.go"]
extend-exclude=[
"go.mod",
"*.svg",
"**/testdata/**",
"internal/cachehash/hash_test.go",
"internal/devpkg/package_test.go",
]

0 comments on commit 4e95590

Please sign in to comment.