diff --git a/.codex-tmp/inspect_device_cache_roundtrip.go b/.codex-tmp/inspect_device_cache_roundtrip.go new file mode 100644 index 0000000..4a6f5c6 --- /dev/null +++ b/.codex-tmp/inspect_device_cache_roundtrip.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + + "github.com/perfect-panel/server/internal/config" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/conf" +) + +func main() { + var c config.Config + conf.MustLoad("/private/tmp/ppanel-local-upload.yaml", &c) + ctx := svc.NewServiceContext(c) + const key = "cache:auth:method:device" + before, _ := ctx.Redis.Get(ctx.DB.Statement.Context, key).Result() + fmt.Printf("cache before=%q\n", before) + m, err := ctx.AuthModel.FindOneByMethod(ctx.DB.Statement.Context, "device") + fmt.Printf("model err=%v enabled_nil=%v", err, m == nil || m.Enabled == nil) + if m != nil && m.Enabled != nil { fmt.Printf(" enabled=%v", *m.Enabled) } + if m != nil { fmt.Printf(" config=%s", m.Config) } + fmt.Println() + after, _ := ctx.Redis.Get(ctx.DB.Statement.Context, key).Result() + fmt.Printf("cache after=%q\n", after) +} diff --git a/.codex-tmp/inspect_device_config.go b/.codex-tmp/inspect_device_config.go new file mode 100644 index 0000000..9299623 --- /dev/null +++ b/.codex-tmp/inspect_device_config.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + + initpkg "github.com/perfect-panel/server/initialize" + "github.com/perfect-panel/server/internal/config" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/conf" +) + +func main() { + var c config.Config + conf.MustLoad("/private/tmp/ppanel-local-upload.yaml", &c) + ctx := svc.NewServiceContext(c) + method, err := ctx.AuthModel.FindOneByMethod(ctx.DB.Statement.Context, "device") + if err != nil { + panic(err) + } + fmt.Printf("db auth_method.enabled=%v config=%s\n", *method.Enabled, method.Config) + initpkg.Device(ctx) + fmt.Printf("ctx.Config.Device.Enable=%v SecuritySecret=%q EnableSecurity=%v\n", ctx.Config.Device.Enable, ctx.Config.Device.SecuritySecret, ctx.Config.Device.EnableSecurity) +} diff --git a/.codex-tmp/inspect_device_db_vs_model.go b/.codex-tmp/inspect_device_db_vs_model.go new file mode 100644 index 0000000..ee58a04 --- /dev/null +++ b/.codex-tmp/inspect_device_db_vs_model.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + + "github.com/perfect-panel/server/internal/config" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/conf" +) + +type row struct { + ID int64 + Method string + Enabled int + Config string +} + +func main() { + var c config.Config + conf.MustLoad("/private/tmp/ppanel-local-upload.yaml", &c) + ctx := svc.NewServiceContext(c) + + var rows []row + if err := ctx.DB.Raw("SELECT id, method, enabled, config FROM auth_method WHERE method = ?", "device").Scan(&rows).Error; err != nil { + panic(err) + } + fmt.Printf("raw rows: %+v\n", rows) + + m, err := ctx.AuthModel.FindOneByMethod(ctx.DB.Statement.Context, "device") + fmt.Printf("model err=%v\n", err) + if err == nil && m != nil && m.Enabled != nil { + fmt.Printf("model row: id=%d method=%s enabled=%v config=%s\n", m.Id, m.Method, *m.Enabled, m.Config) + } else { + fmt.Printf("model row nil or no enabled ptr: %#v\n", m) + } +} diff --git a/.codex-tmp/inspect_device_gorm.go b/.codex-tmp/inspect_device_gorm.go new file mode 100644 index 0000000..7da8d6f --- /dev/null +++ b/.codex-tmp/inspect_device_gorm.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "github.com/perfect-panel/server/internal/config" + authmodel "github.com/perfect-panel/server/internal/model/auth" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/conf" +) + +func main() { + var c config.Config + conf.MustLoad("/private/tmp/ppanel-local-upload.yaml", &c) + ctx := svc.NewServiceContext(c) + + var a1 authmodel.Auth + err1 := ctx.DB.Model(&authmodel.Auth{}).Where("method = ?", "device").First(&a1).Error + fmt.Printf("gorm direct err=%v enabled_nil=%v", err1, a1.Enabled == nil) + if a1.Enabled != nil { fmt.Printf(" enabled=%v", *a1.Enabled) } + fmt.Printf(" config=%s\n", a1.Config) + + var a2 authmodel.Auth + err2 := ctx.DB.Table("auth_method").Where("method = ?", "device").First(&a2).Error + fmt.Printf("gorm table err=%v enabled_nil=%v", err2, a2.Enabled == nil) + if a2.Enabled != nil { fmt.Printf(" enabled=%v", *a2.Enabled) } + fmt.Printf(" config=%s\n", a2.Config) +}