// roleGrantPermissionCommandFunc executes the "role grant-permission" command. func roleGrantPermissionCommandFunc(cmd *cobra.Command, args []string) { if len(args) < 3 { ExitWithError(ExitBadArgs, fmt.Errorf("role grant command requires role name, permission type, and key [endkey] as its argument.")) } perm, err := clientv3.StrToPermissionType(args[1]) if err != nil { ExitWithError(ExitBadArgs, err) } rangeEnd := "" if 4 <= len(args) { if grantPermissionPrefix { ExitWithError(ExitBadArgs, fmt.Errorf("don't pass both of --prefix option and range end to grant permission command")) } rangeEnd = args[3] } else if grantPermissionPrefix { rangeEnd = clientv3.GetPrefixRangeEnd(args[2]) } _, err = mustClientFromCmd(cmd).Auth.RoleGrantPermission(context.TODO(), args[0], args[2], rangeEnd, perm) if err != nil { ExitWithError(ExitError, err) } fmt.Printf("Role %s updated\n", args[0]) }
// roleGrantCommandFunc executes the "role grant" command. func roleGrantCommandFunc(cmd *cobra.Command, args []string) { if len(args) != 3 { ExitWithError(ExitBadArgs, fmt.Errorf("role grant command requires role name, permission type, and key as its argument.")) } perm, err := clientv3.StrToPermissionType(args[1]) if err != nil { ExitWithError(ExitBadArgs, err) } _, err = mustClientFromCmd(cmd).Auth.RoleGrant(context.TODO(), args[0], args[2], perm) if err != nil { ExitWithError(ExitError, err) } fmt.Printf("Role %s updated\n", args[0]) }