|
|
@@ -23,6 +23,10 @@ import (
|
|
|
"golang.org/x/net/context"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ userShowDetail bool
|
|
|
+)
|
|
|
+
|
|
|
// NewUserCommand returns the cobra command for "user".
|
|
|
func NewUserCommand() *cobra.Command {
|
|
|
ac := &cobra.Command{
|
|
|
@@ -66,12 +70,15 @@ func newUserDeleteCommand() *cobra.Command {
|
|
|
}
|
|
|
|
|
|
func newUserGetCommand() *cobra.Command {
|
|
|
- // TODO(mitake): this command should also get detailed information of roles of the user
|
|
|
- return &cobra.Command{
|
|
|
+ cmd := cobra.Command{
|
|
|
Use: "get <user name>",
|
|
|
Short: "get detailed information of a user",
|
|
|
Run: userGetCommandFunc,
|
|
|
}
|
|
|
+
|
|
|
+ cmd.Flags().BoolVar(&userShowDetail, "detail", false, "show permissions of roles granted to the user")
|
|
|
+
|
|
|
+ return &cmd
|
|
|
}
|
|
|
|
|
|
func newUserListCommand() *cobra.Command {
|
|
|
@@ -153,17 +160,30 @@ func userGetCommandFunc(cmd *cobra.Command, args []string) {
|
|
|
}
|
|
|
|
|
|
name := args[0]
|
|
|
- resp, err := mustClientFromCmd(cmd).Auth.UserGet(context.TODO(), name)
|
|
|
+ client := mustClientFromCmd(cmd)
|
|
|
+ resp, err := client.Auth.UserGet(context.TODO(), name)
|
|
|
if err != nil {
|
|
|
ExitWithError(ExitError, err)
|
|
|
}
|
|
|
|
|
|
fmt.Printf("User: %s\n", name)
|
|
|
- fmt.Printf("Roles:")
|
|
|
- for _, role := range resp.Roles {
|
|
|
- fmt.Printf(" %s", role)
|
|
|
+ if !userShowDetail {
|
|
|
+ fmt.Printf("Roles:")
|
|
|
+ for _, role := range resp.Roles {
|
|
|
+ fmt.Printf(" %s", role)
|
|
|
+ }
|
|
|
+ fmt.Printf("\n")
|
|
|
+ } else {
|
|
|
+ for _, role := range resp.Roles {
|
|
|
+ fmt.Printf("\n")
|
|
|
+ roleResp, err := client.Auth.RoleGet(context.TODO(), role)
|
|
|
+ if err != nil {
|
|
|
+ ExitWithError(ExitError, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ printRolePermissions(role, roleResp)
|
|
|
+ }
|
|
|
}
|
|
|
- fmt.Printf("\n")
|
|
|
}
|
|
|
|
|
|
// userListCommandFunc executes the "user list" command.
|