From b4dc5d6841f7ded5995e5f308509b1a3a034cbed Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 24 Dec 2020 15:18:24 +0100 Subject: Began implementing config validation --- config/game.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'config/game.go') diff --git a/config/game.go b/config/game.go index 0eea917..5520659 100644 --- a/config/game.go +++ b/config/game.go @@ -1,5 +1,12 @@ package config +import ( + "errors" + "regexp" +) + +var reValidGameName = regexp.MustCompile(`^[\w\._]+$`) + // Game struct containers the configuration for a game type Game struct { // ChrootPath is the chroot path for the game @@ -8,4 +15,21 @@ type Game struct { FileMode string `yaml:"FileMode"` // Commands is the command list Commands []string `yaml:"Commands"` + // ScoreFile is relative to the chroot path for the game + ScoreCommands []string `yaml:"ScoreCommands"` + // Env is the environment in which to exec the commands + Env map[string]string `yaml:"Env"` +} + +func (a *Game) validate(name string) error { + // Game name + if ok := reValidGameName.MatchString(name); !ok { + return errors.New("Invalid Game name, must match regex `^[\\w\\._]+$` : " + name) + } + // ChrootPath TODO + // FileMode + // Commands + // ScoreFile + // Env + return nil } -- cgit v1.2.3