feat(api): add namespaces, batch ops, and admin logs

This commit is contained in:
zenfun
2025-12-21 23:16:27 +08:00
parent 73147fc55a
commit c2ed2f3f9e
12 changed files with 824 additions and 42 deletions

View File

@@ -127,7 +127,7 @@ func main() {
// Auto Migrate
if logDB != db {
if err := db.AutoMigrate(&model.Master{}, &model.Key{}, &model.Provider{}, &model.Model{}, &model.Binding{}); err != nil {
if err := db.AutoMigrate(&model.Master{}, &model.Key{}, &model.Provider{}, &model.Model{}, &model.Binding{}, &model.Namespace{}, &model.OperationLog{}); err != nil {
fatal(logger, "failed to auto migrate", "err", err)
}
if err := logDB.AutoMigrate(&model.LogRecord{}); err != nil {
@@ -137,7 +137,7 @@ func main() {
fatal(logger, "failed to ensure log indexes", "err", err)
}
} else {
if err := db.AutoMigrate(&model.Master{}, &model.Key{}, &model.Provider{}, &model.Model{}, &model.Binding{}, &model.LogRecord{}); err != nil {
if err := db.AutoMigrate(&model.Master{}, &model.Key{}, &model.Provider{}, &model.Model{}, &model.Binding{}, &model.Namespace{}, &model.OperationLog{}, &model.LogRecord{}); err != nil {
fatal(logger, "failed to auto migrate", "err", err)
}
if err := service.EnsureLogIndexes(db); err != nil {
@@ -250,18 +250,26 @@ func main() {
// Admin Routes
adminGroup := r.Group("/admin")
adminGroup.Use(middleware.AdminAuthMiddleware(adminService))
adminGroup.Use(middleware.OperationLogMiddleware(db))
{
adminGroup.POST("/masters", adminHandler.CreateMaster)
adminGroup.GET("/masters", adminHandler.ListMasters)
adminGroup.GET("/masters/:id", adminHandler.GetMaster)
adminGroup.PUT("/masters/:id", adminHandler.UpdateMaster)
adminGroup.DELETE("/masters/:id", adminHandler.DeleteMaster)
adminGroup.POST("/masters/batch", adminHandler.BatchMasters)
adminGroup.POST("/masters/:id/manage", adminHandler.ManageMaster)
adminGroup.POST("/masters/:id/keys", adminHandler.IssueChildKeyForMaster)
adminGroup.GET("/masters/:id/access", handler.GetMasterAccess)
adminGroup.PUT("/masters/:id/access", handler.UpdateMasterAccess)
adminGroup.GET("/keys/:id/access", handler.GetKeyAccess)
adminGroup.PUT("/keys/:id/access", handler.UpdateKeyAccess)
adminGroup.GET("/operation-logs", adminHandler.ListOperationLogs)
adminGroup.POST("/namespaces", handler.CreateNamespace)
adminGroup.GET("/namespaces", handler.ListNamespaces)
adminGroup.GET("/namespaces/:id", handler.GetNamespace)
adminGroup.PUT("/namespaces/:id", handler.UpdateNamespace)
adminGroup.DELETE("/namespaces/:id", handler.DeleteNamespace)
adminGroup.GET("/features", featureHandler.ListFeatures)
adminGroup.PUT("/features", featureHandler.UpdateFeatures)
adminGroup.GET("/model-registry/status", modelRegistryHandler.GetStatus)
@@ -277,12 +285,14 @@ func main() {
adminGroup.POST("/providers/google", handler.CreateProviderGoogle)
adminGroup.PUT("/providers/:id", handler.UpdateProvider)
adminGroup.DELETE("/providers/:id", handler.DeleteProvider)
adminGroup.POST("/providers/batch", handler.BatchProviders)
adminGroup.POST("/providers/:id/test", handler.TestProvider)
adminGroup.POST("/providers/:id/fetch-models", handler.FetchProviderModels)
adminGroup.POST("/models", handler.CreateModel)
adminGroup.GET("/models", handler.ListModels)
adminGroup.PUT("/models/:id", handler.UpdateModel)
adminGroup.DELETE("/models/:id", handler.DeleteModel)
adminGroup.POST("/models/batch", handler.BatchModels)
adminGroup.GET("/logs", handler.ListLogs)
adminGroup.DELETE("/logs", handler.DeleteLogs)
adminGroup.GET("/logs/stats", handler.LogStats)
@@ -294,6 +304,7 @@ func main() {
adminGroup.GET("/bindings/:id", handler.GetBinding)
adminGroup.PUT("/bindings/:id", handler.UpdateBinding)
adminGroup.DELETE("/bindings/:id", handler.DeleteBinding)
adminGroup.POST("/bindings/batch", handler.BatchBindings)
adminGroup.POST("/sync/snapshot", handler.SyncSnapshot)
}