-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aa048a
commit 209afec
Showing
7 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:generate mockgen -source=user.go -destination=user_mock.go -package=auth0 | ||
|
||
package auth0 | ||
|
||
import "gopkg.in/auth0.v5/management" | ||
|
||
type UserAPI interface { | ||
// Read a user by its id. | ||
Read(id string, opts ...management.RequestOption) (u *management.User, err error) | ||
|
||
// List users by email. | ||
ListByEmail(email string, opts ...management.RequestOption) (us []*management.User, err error) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
func usersCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "users", | ||
Short: "manage users.", | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(getusersCmd(cli)) | ||
|
||
return cmd | ||
} | ||
|
||
func getusersCmd(cli *cli) *cobra.Command { | ||
var flags struct { | ||
id string | ||
email string | ||
fields string | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "get", | ||
Short: "Get a user's details", | ||
Long: `$ auth0 users get | ||
Get a user | ||
`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
userID, err := cmd.LocalFlags().GetString("id") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userEmail, err := cmd.LocalFlags().GetString("email") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if userID == "" && userEmail == "" { | ||
return errors.New("User id or email flag must be specified") | ||
} | ||
|
||
if userID != "" && userEmail != "" { | ||
return errors.New("User id and email flags cannot be combined") | ||
} | ||
|
||
var users []*management.User | ||
var user *management.User | ||
|
||
if userID != "" { | ||
err := ansi.Spinner("Getting user", func() error { | ||
var err error | ||
user, err = cli.api.User.Read(flags.id) | ||
return err | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
users = append(users, user) | ||
|
||
cli.renderer.UserList(users) | ||
return nil | ||
} | ||
|
||
if userEmail != "" { | ||
err := ansi.Spinner("Getting user(s)", func() error { | ||
var err error | ||
users, err = cli.api.User.ListByEmail(userEmail) | ||
return err | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
cli.renderer.UserList(users) | ||
return nil | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&flags.id, "id", "i", "", "User ID of user to get.") | ||
cmd.Flags().StringVarP(&flags.email, "email", "e", "", "Email of user to get.") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package display | ||
|
||
import ( | ||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"github.com/auth0/auth0-cli/internal/auth0" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
type userView struct { | ||
UserID string | ||
Connection string | ||
Name string | ||
Email string | ||
LatestLogin string | ||
} | ||
|
||
func (v *userView) AsTableHeader() []string { | ||
return []string{"User ID", "Name", "Email", "Latest Login"} | ||
} | ||
|
||
func (v *userView) AsTableRow() []string { | ||
return []string{ansi.Faint(v.UserID), v.Name, v.Email, v.LatestLogin} | ||
} | ||
|
||
func (r *Renderer) UserList(users []*management.User) { | ||
r.Heading(ansi.Bold(r.Tenant), "users\n") | ||
|
||
var res []View | ||
for _, u := range users { | ||
res = append(res, &userView{ | ||
UserID: auth0.StringValue(u.ID), | ||
Name: auth0.StringValue(u.Name), | ||
Email: auth0.StringValue(u.Email), | ||
LatestLogin: u.LastLogin.String(), | ||
}) | ||
} | ||
|
||
r.Results(res) | ||
} |