package classes import ( "fmt" "strings" "time" "git.golem15.com/golem15/summercms/modules/backpack" ) // JWTBlacklistTable is the table of migration // 202609220007_create_jwt_blacklist that the plugin's blacklist store uses. const JWTBlacklistTable = "jwt_blacklist" // DefaultBlacklistSweepInterval is how often the scheduler runs // user:jwt-blacklist-sweep when golem15.user.jwt.blacklist_sweep_interval is // not set. const DefaultBlacklistSweepInterval = 10 * time.Minute const blacklistSweepIntervalKey = "golem15.user.jwt.blacklist_sweep_interval" // BlacklistSweepInterval reads golem15.user.jwt.blacklist_sweep_interval, a // Go duration (10m by default). 0 means no sweep is scheduled. Any other // value must be at least 1s and divide 24h evenly: the scheduler's Every // cadence is aligned to local midnight, so a period that does not divide the // day cannot be scheduled. A value that does not parse, is negative, is // shorter than a second or does not divide 24h is an error, so a typo fails // the boot instead of silently stopping the sweep. func BlacklistSweepInterval(app *backpack.App) (time.Duration, error) { if app == nil || app.Config == nil { return DefaultBlacklistSweepInterval, nil } raw := strings.TrimSpace(app.Config.String(blacklistSweepIntervalKey)) if raw == "" { // A non-string value (an unquoted YAML 0) may read as "". if v, ok := app.Config.Lookup(blacklistSweepIntervalKey); ok && v != nil { raw = strings.TrimSpace(fmt.Sprint(v)) } } if raw == "" { return DefaultBlacklistSweepInterval, nil } d, err := time.ParseDuration(raw) switch { case err != nil: case d == 0: return 0, nil case d >= time.Second && (24*time.Hour)%d == 0: return d, nil } return 0, fmt.Errorf("golem15.user: %s must be 0 (no sweep) or a duration of at least 1s that divides 24h evenly, such as 10m, got %q", blacklistSweepIntervalKey, raw) }