-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic user get/search command #77
Merged
+304
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we wanna add the rest of CRUD now?