2021-08-04 11:04:01 +00:00
|
|
|
package config
|
|
|
|
|
2021-08-06 13:27:42 +00:00
|
|
|
// The struct that represents the config.json file
|
2021-08-04 11:04:01 +00:00
|
|
|
type Config struct {
|
|
|
|
ListenAddress string
|
|
|
|
Services map[string]struct {
|
2021-08-14 00:02:36 +00:00
|
|
|
Script Command
|
|
|
|
Secret string
|
|
|
|
SignaturePrefix string
|
|
|
|
SignatureHeader string
|
|
|
|
DisableSignatureVerification bool
|
|
|
|
Tests []Command
|
2021-08-04 11:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 13:27:42 +00:00
|
|
|
// Check that all required fields are filled in
|
2021-08-04 11:04:01 +00:00
|
|
|
func (c Config) Validate() error {
|
|
|
|
if c.ListenAddress == "" {
|
|
|
|
return requiredFieldError{"ListenAddress", ""}
|
|
|
|
}
|
|
|
|
|
|
|
|
for serviceName, service := range c.Services {
|
|
|
|
if service.Script.Program == "" {
|
|
|
|
return requiredFieldError{"Script.Program", serviceName}
|
|
|
|
}
|
2021-08-14 00:02:36 +00:00
|
|
|
if !service.DisableSignatureVerification && service.SignatureHeader == "" {
|
2021-08-04 11:04:01 +00:00
|
|
|
return requiredFieldError{"SignatureHeader", serviceName}
|
|
|
|
}
|
2021-08-14 00:02:36 +00:00
|
|
|
if !service.DisableSignatureVerification && service.Secret == "" {
|
2021-08-04 11:04:01 +00:00
|
|
|
return requiredFieldError{"Secret", serviceName}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|