feat(cmd/joj3): expire unix timestamp conf
All checks were successful
build / build (push) Successful in 1m11s
build / trigger-build-image (push) Successful in 9s

This commit is contained in:
张泊明518370910136 2024-10-14 09:41:10 -04:00
parent b1d10dc3f9
commit f09dc8c1c1
GPG Key ID: D47306D7062CDA9D
2 changed files with 17 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"time"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
@ -32,6 +33,7 @@ type ConfStage struct {
type Conf struct { type Conf struct {
Name string `default:"unknown"` Name string `default:"unknown"`
LogPath string `default:""` LogPath string `default:""`
ExpireUnixTimestamp int64 `default:"-1"`
Stage struct { Stage struct {
SandboxExecServer string `default:"localhost:5051"` SandboxExecServer string `default:"localhost:5051"`
SandboxToken string `default:""` SandboxToken string `default:""`
@ -254,3 +256,11 @@ func ListValidScopes(confRoot, confName string) ([]string, error) {
}) })
return validScopes, err return validScopes, err
} }
func CheckExpire(conf *Conf) error {
if conf.ExpireUnixTimestamp > 0 &&
conf.ExpireUnixTimestamp < time.Now().Unix() {
return fmt.Errorf("config file expired: %d", conf.ExpireUnixTimestamp)
}
return nil
}

View File

@ -69,6 +69,10 @@ func mainImpl() error {
slog.Error("setup slog", "error", err) slog.Error("setup slog", "error", err)
return err return err
} }
if err := conf.CheckExpire(confObj); err != nil {
slog.Error("conf check expire", "error", err)
return err
}
if err := stage.Run(confObj, group); err != nil { if err := stage.Run(confObj, group); err != nil {
slog.Error("stage run", "error", err) slog.Error("stage run", "error", err)
return err return err