2026-05-20 23:51:22 +00:00
|
|
|
// Command mongo-index ensures Gateway MongoDB indexes exist.
|
2026-05-20 07:01:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"gateway/internal/config"
|
2026-05-21 06:45:35 +00:00
|
|
|
authrepo "gateway/internal/model/auth/repository"
|
2026-05-20 23:51:22 +00:00
|
|
|
memberrepo "gateway/internal/model/member/repository"
|
2026-05-20 07:01:08 +00:00
|
|
|
notifrepo "gateway/internal/model/notification/repository"
|
feat(permission): add RBAC module with Casbin enforcement and policy reload
- Multi-tenant RBAC: permission catalog, roles, role-permission mapping,
user-role assignment, and external IdP role mapping (zitadel/ldap/scim).
- Casbin enforcer with Redis-backed adapter and Pub/Sub reload for
multi-instance policy sync; HTTP middleware enforces (tenant, role,
path, method) with platform admin bypass.
- /api/v1/permissions routes: catalog, me, policy/reload, roles CRUD,
role permissions, user roles, role mappings.
- New error scope (31) for Permission and biz code descriptions.
- Wire Permission module into ServiceContext, config, mongo-index, and
add cmd/permission-seed CLI plus etc/rbac.conf model.
- Redis client gains lazy PubSubClient helper (go-zero wrapper lacks Subscribe).
- Rewrite internal/model/member/README to cover Tenant/Member/Identity.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 08:47:35 +00:00
|
|
|
permrepo "gateway/internal/model/permission/repository"
|
2026-05-20 07:01:08 +00:00
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-20 23:51:22 +00:00
|
|
|
var configFile = flag.String("f", "etc/gateway.dev.yaml", "config file")
|
2026-05-20 07:01:08 +00:00
|
|
|
|
|
|
|
|
func main() {
|
2026-05-20 13:03:59 +00:00
|
|
|
if err := run(); err != nil {
|
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func run() error {
|
2026-05-20 07:01:08 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
var c config.Config
|
|
|
|
|
conf.MustLoad(*configFile, &c)
|
|
|
|
|
if c.Mongo.Host == "" {
|
2026-05-20 13:03:59 +00:00
|
|
|
return fmt.Errorf("mongo-index: Mongo.Host is empty in config")
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
notifRepo := notifrepo.NewNotificationRepository(notifrepo.NotificationRepositoryParam{Conf: &c.Mongo})
|
|
|
|
|
dlqRepo := notifrepo.NewNotificationDLQRepository(notifrepo.NotificationDLQRepositoryParam{Conf: &c.Mongo})
|
|
|
|
|
|
|
|
|
|
if err := notifRepo.Index20260520001UP(ctx); err != nil {
|
2026-05-20 13:03:59 +00:00
|
|
|
return fmt.Errorf("mongo-index: notifications: %w", err)
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|
|
|
|
|
if err := dlqRepo.Index20260520001UP(ctx); err != nil {
|
2026-05-20 13:03:59 +00:00
|
|
|
return fmt.Errorf("mongo-index: notification_dlq: %w", err)
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|
2026-05-20 23:51:22 +00:00
|
|
|
if err := memberrepo.EnsureMongoIndexes(ctx, &c.Mongo); err != nil {
|
|
|
|
|
return fmt.Errorf("mongo-index: member: %w", err)
|
|
|
|
|
}
|
2026-05-21 06:45:35 +00:00
|
|
|
if err := authrepo.EnsureMongoIndexes(ctx, &c.Mongo); err != nil {
|
|
|
|
|
return fmt.Errorf("mongo-index: auth: %w", err)
|
|
|
|
|
}
|
feat(permission): add RBAC module with Casbin enforcement and policy reload
- Multi-tenant RBAC: permission catalog, roles, role-permission mapping,
user-role assignment, and external IdP role mapping (zitadel/ldap/scim).
- Casbin enforcer with Redis-backed adapter and Pub/Sub reload for
multi-instance policy sync; HTTP middleware enforces (tenant, role,
path, method) with platform admin bypass.
- /api/v1/permissions routes: catalog, me, policy/reload, roles CRUD,
role permissions, user roles, role mappings.
- New error scope (31) for Permission and biz code descriptions.
- Wire Permission module into ServiceContext, config, mongo-index, and
add cmd/permission-seed CLI plus etc/rbac.conf model.
- Redis client gains lazy PubSubClient helper (go-zero wrapper lacks Subscribe).
- Rewrite internal/model/member/README to cover Tenant/Member/Identity.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 08:47:35 +00:00
|
|
|
if err := permrepo.EnsureMongoIndexes(ctx, &c.Mongo); err != nil {
|
|
|
|
|
return fmt.Errorf("mongo-index: permission: %w", err)
|
|
|
|
|
}
|
2026-05-20 07:01:08 +00:00
|
|
|
|
feat(permission): add RBAC module with Casbin enforcement and policy reload
- Multi-tenant RBAC: permission catalog, roles, role-permission mapping,
user-role assignment, and external IdP role mapping (zitadel/ldap/scim).
- Casbin enforcer with Redis-backed adapter and Pub/Sub reload for
multi-instance policy sync; HTTP middleware enforces (tenant, role,
path, method) with platform admin bypass.
- /api/v1/permissions routes: catalog, me, policy/reload, roles CRUD,
role permissions, user roles, role mappings.
- New error scope (31) for Permission and biz code descriptions.
- Wire Permission module into ServiceContext, config, mongo-index, and
add cmd/permission-seed CLI plus etc/rbac.conf model.
- Redis client gains lazy PubSubClient helper (go-zero wrapper lacks Subscribe).
- Rewrite internal/model/member/README to cover Tenant/Member/Identity.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 08:47:35 +00:00
|
|
|
fmt.Println("mongo-index: notifications + notification_dlq + member + auth + permission indexes OK")
|
2026-05-20 13:03:59 +00:00
|
|
|
return nil
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|