gohookr/config/config.go

36 lines
979 B
Go
Raw Permalink Normal View History

2021-08-04 11:04:01 +00:00
package config
// 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 {
Script Command
Secret string
SignaturePrefix string
SignatureHeader string
DisableSignatureVerification bool
Tests []Command
2021-08-04 11:04:01 +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}
}
if !service.DisableSignatureVerification && service.SignatureHeader == "" {
2021-08-04 11:04:01 +00:00
return requiredFieldError{"SignatureHeader", serviceName}
}
if !service.DisableSignatureVerification && service.Secret == "" {
2021-08-04 11:04:01 +00:00
return requiredFieldError{"Secret", serviceName}
}
}
return nil
}