From e970e217e22c1900dad8a99f935659dba4c08d1e Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 30 Apr 2019 12:08:59 +0200 Subject: [PATCH] config: add global agola id field --- internal/services/config/config.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/services/config/config.go b/internal/services/config/config.go index d811bd0..5fcbb8d 100644 --- a/internal/services/config/config.go +++ b/internal/services/config/config.go @@ -19,10 +19,20 @@ import ( "time" "github.com/pkg/errors" + "github.com/sorintlab/agola/internal/util" yaml "gopkg.in/yaml.v2" ) +const ( + maxIDLength = 20 +) + type Config struct { + // ID defines the agola installation id. It's used inside the + // various services to uniquely distinguish it from other installations + // Defaults to "agola" + ID string `yaml:"id"` + Gateway Gateway `yaml:"gateway"` Scheduler Scheduler `yaml:"scheduler"` RunServiceScheduler RunServiceScheduler `yaml:"runServiceScheduler"` @@ -192,6 +202,7 @@ type TokenSigning struct { } var defaultConfig = Config{ + ID: "agola", Gateway: Gateway{ TokenSigning: TokenSigning{ Duration: 12 * time.Hour, @@ -237,6 +248,14 @@ func validateWeb(w *Web) error { } func Validate(c *Config) error { + // Global + if len(c.ID) > maxIDLength { + return errors.Errorf("id too long") + } + if !util.ValidateName(c.ID) { + return errors.Errorf("invalid id") + } + // Gateway if c.Gateway.APIExposedURL == "" { return errors.Errorf("gateway apiExposedURL is empty")