From 2c5d513c4bdd5d2e29df4381af7b9d00b3a3f41e Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 05:28:14 +0300 Subject: [PATCH] feat: Add subscriber management API endpoints with RBAC authorization - Add SubscriberHandler to serverDeps with NewSubscriberService initialization - Add subscriber routes to v1 API with GET (list, by id, by IMSI) and protected POST/PUT operations - Add RBAC enforcement for subscriber creation, updates, suspension, and termination (admin, operator roles) - Add registerSubscriberRoutes function with /subscribers endpoint group --- apps/api-server/cmd/server_deps.go | 3 +++ apps/api-server/cmd/server_routes.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/apps/api-server/cmd/server_deps.go b/apps/api-server/cmd/server_deps.go index a2f3d08..99a5fd0 100644 --- a/apps/api-server/cmd/server_deps.go +++ b/apps/api-server/cmd/server_deps.go @@ -18,6 +18,7 @@ type serverDeps struct { casbinSvc *rbac.CasbinService authH *handlers.AuthHandler + subscriberH *handlers.SubscriberHandler servicesH *handlers.ServicesHandler monitoringH *handlers.MonitoringHandler deploymentsH *handlers.DeploymentsHandler @@ -46,6 +47,7 @@ func buildDeps(db *database.Database, cfg *config.Config) *serverDeps { configStoreSvc := services.NewConfigStoreService(db) deploymentSvc := services.NewDeploymentService(db) promSvc := monitoring.NewPrometheusService() + subscriberSvc := services.NewSubscriberService(db, cfg) // Initialize charging engine client chargingEngineClient := services.NewChargingEngineClient(&cfg.ChargingEngine) @@ -59,6 +61,7 @@ func buildDeps(db *database.Database, cfg *config.Config) *serverDeps { authSvc: authSvc, casbinSvc: casbinSvc, authH: handlers.NewAuthHandler(authSvc), + subscriberH: handlers.NewSubscriberHandler(subscriberSvc), servicesH: handlers.NewServicesHandler(k8sSvc), monitoringH: handlers.NewMonitoringHandler(promSvc), deploymentsH: handlers.NewDeploymentsHandler(deploymentSvc), diff --git a/apps/api-server/cmd/server_routes.go b/apps/api-server/cmd/server_routes.go index 52d2a4f..0a681b5 100644 --- a/apps/api-server/cmd/server_routes.go +++ b/apps/api-server/cmd/server_routes.go @@ -57,6 +57,7 @@ func registerV1Routes(router *gin.Engine, d *serverDeps) { apiProtected := v1.Group("/") apiProtected.Use(middleware.AuthMiddleware(d.authSvc)) { + registerSubscriberRoutes(apiProtected, d) registerServicesRoutes(apiProtected, d) registerMonitoringRoutes(apiProtected, d) registerDeployRoutes(apiProtected, d) @@ -173,3 +174,17 @@ func registerChaosRoutes(api *gin.RouterGroup, d *serverDeps) { applyRBAC(w, d.casbinSvc, "/v1/chaos", "POST", "admin") w.POST("/experiments", d.chaosH.Run) } + +func registerSubscriberRoutes(api *gin.RouterGroup, d *serverDeps) { + subs := api.Group("/subscribers") + subs.GET("", d.subscriberH.ListSubscribers) + subs.GET("/:id", d.subscriberH.GetSubscriber) + subs.GET("/imsi/:imsi", d.subscriberH.GetSubscriberByIMSI) + + w := subs.Group("/") + applyRBAC(w, d.casbinSvc, "/v1/subscribers", "POST", "admin", "operator") + w.POST("", d.subscriberH.CreateSubscriber) + w.PUT("/:id", d.subscriberH.UpdateSubscriber) + w.POST("/:id/suspend", d.subscriberH.SuspendSubscriber) + w.POST("/:id/terminate", d.subscriberH.TerminateSubscriber) +}