- Added upstream objects

- Renamed host templates to nginx templates
- Generate upstream templates
- Better nginx error reporting when reloading
- Use tparse for golang test reporting
This commit is contained in:
Jamie Curnow
2023-01-04 15:36:56 +10:00
parent b3ae2f4dbb
commit 5e5f0de0e2
82 changed files with 2209 additions and 294 deletions

View File

@ -5,7 +5,7 @@ import (
"npm/internal/entity/certificate"
"npm/internal/entity/host"
"npm/internal/entity/hosttemplate"
"npm/internal/entity/nginxtemplate"
)
// ValidateHost will check if associated objects exist and other checks
@ -20,13 +20,13 @@ func ValidateHost(h host.Model) error {
}
}
// Check the host template exists and has the same type.
hostTemplate, tErr := hosttemplate.GetByID(h.HostTemplateID)
// Check the nginx template exists and has the same type.
nginxTemplate, tErr := nginxtemplate.GetByID(h.NginxTemplateID)
if tErr != nil {
return fmt.Errorf("Host Template #%d does not exist", h.HostTemplateID)
return fmt.Errorf("Host Template #%d does not exist", h.NginxTemplateID)
}
if hostTemplate.Type != h.Type {
return fmt.Errorf("Host Template #%d is not valid for this host type", h.HostTemplateID)
if nginxTemplate.Type != h.Type {
return fmt.Errorf("Host Template #%d is not valid for this host type", h.NginxTemplateID)
}
return nil

View File

@ -0,0 +1,39 @@
package validator
import (
"errors"
"fmt"
"npm/internal/entity/nginxtemplate"
"npm/internal/entity/upstream"
)
// ValidateUpstream will check if associated objects exist and other checks
// will return a nil error if things are OK
func ValidateUpstream(u upstream.Model) error {
// Needs to have more than 1 server
if len(u.Servers) < 2 {
return errors.New("Upstreams require at least 2 servers")
}
// Backup servers aren't permitted with hash balancing
if u.IPHash {
// check all servers for a backup param
for _, server := range u.Servers {
if server.Backup {
return errors.New("Backup servers cannot be used with hash balancing")
}
}
}
// Check the nginx template exists and has the same type.
nginxTemplate, err := nginxtemplate.GetByID(u.NginxTemplateID)
if err != nil {
return fmt.Errorf("Nginx Template #%d does not exist", u.NginxTemplateID)
}
if nginxTemplate.Type != "upstream" {
return fmt.Errorf("Host Template #%d is not valid for this upstream", u.NginxTemplateID)
}
return nil
}