Configuration - Validate handlers for certificates
* Handlers referenced in certificate file sections must exist. No handlers may be referenced more than once by the same section.
This commit is contained in:
parent
8c33db2cc5
commit
bccd467968
1 changed files with 26 additions and 7 deletions
33
config.go
33
config.go
|
@ -230,11 +230,23 @@ func checkFileList(files []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate a certificate file configuration entry
|
// Validate the list of handles
|
||||||
func (c *tCertificateFileConfig) Validate() error {
|
func (c *tCertFileUpdateConfig) Validate(handlers *tHandlers) error {
|
||||||
if c.Path == "" {
|
set := make(map[string]bool)
|
||||||
return fmt.Errorf("Certificate file entry has no path.")
|
for _, handler := range c.Handlers {
|
||||||
|
if _, exists := (*handlers)[handler]; !exists {
|
||||||
|
return fmt.Errorf("Handler '%s' does not exist.", handler)
|
||||||
|
}
|
||||||
|
if _, exists := set[handler]; exists {
|
||||||
|
return fmt.Errorf("Handler '%s' specified more than once.", handler)
|
||||||
|
}
|
||||||
|
set[handler] = true
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate a certificate file configuration entry
|
||||||
|
func (c *tCertificateFileConfig) Validate(handlers *tHandlers) error {
|
||||||
if !valid.IsUnixFilePath(c.Path) {
|
if !valid.IsUnixFilePath(c.Path) {
|
||||||
return fmt.Errorf("Certificate file path '%s' is invalid.", c.Path)
|
return fmt.Errorf("Certificate file path '%s' is invalid.", c.Path)
|
||||||
}
|
}
|
||||||
|
@ -263,6 +275,10 @@ func (c *tCertificateFileConfig) Validate() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = c.AfterUpdate.Validate(handlers)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,10 +292,13 @@ func (c *tConfiguration) Validate() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, cfc := range c.Certificates {
|
for idx, cfc := range c.Certificates {
|
||||||
err = cfc.Validate()
|
if cfc.Path == "" {
|
||||||
|
return fmt.Errorf("Certificate file entry #%d has no path.", idx+1)
|
||||||
|
}
|
||||||
|
err = cfc.Validate(&c.Handlers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("Certificate file %s (#%d): %s", cfc.Path, idx+1, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue