feat(cmd/joj3): expire unix timestamp conf
This commit is contained in:
		
							parent
							
								
									b1d10dc3f9
								
							
						
					
					
						commit
						f09dc8c1c1
					
				|  | @ -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" | ||||||
|  | @ -30,9 +31,10 @@ type ConfStage struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Conf struct { | type Conf struct { | ||||||
| 	Name    string `default:"unknown"` | 	Name                string `default:"unknown"` | ||||||
| 	LogPath string `default:""` | 	LogPath             string `default:""` | ||||||
| 	Stage   struct { | 	ExpireUnixTimestamp int64  `default:"-1"` | ||||||
|  | 	Stage               struct { | ||||||
| 		SandboxExecServer string `default:"localhost:5051"` | 		SandboxExecServer string `default:"localhost:5051"` | ||||||
| 		SandboxToken      string `default:""` | 		SandboxToken      string `default:""` | ||||||
| 		OutputPath        string `default:"joj3_result.json"` | 		OutputPath        string `default:"joj3_result.json"` | ||||||
|  | @ -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 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user