Adds proxy host vars
This commit is contained in:
@ -17,7 +17,8 @@ func CreateHost() string {
|
||||
"required": [
|
||||
"type",
|
||||
"domain_names",
|
||||
"nginx_template_id"
|
||||
"nginx_template_id",
|
||||
"proxy_scheme"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
@ -33,6 +34,16 @@ func CreateHost() string {
|
||||
"upstream_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"proxy_scheme": {
|
||||
"type": "string",
|
||||
"pattern": "^https?$"
|
||||
},
|
||||
"proxy_host": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy_port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"certificate_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
|
@ -36,6 +36,9 @@ type Model struct {
|
||||
ListenInterface string `json:"listen_interface" db:"listen_interface" filter:"listen_interface,string"`
|
||||
DomainNames types.JSONB `json:"domain_names" db:"domain_names" filter:"domain_names,string"`
|
||||
UpstreamID int `json:"upstream_id" db:"upstream_id" filter:"upstream_id,integer"`
|
||||
ProxyScheme string `json:"proxy_scheme" db:"proxy_scheme" filter:"proxy_scheme,string"`
|
||||
ProxyHost string `json:"proxy_host" db:"proxy_host" filter:"proxy_host,string"`
|
||||
ProxyPort int `json:"proxy_port" db:"proxy_port" filter:"proxy_port,integer"`
|
||||
CertificateID int `json:"certificate_id" db:"certificate_id" filter:"certificate_id,integer"`
|
||||
AccessListID int `json:"access_list_id" db:"access_list_id" filter:"access_list_id,integer"`
|
||||
SSLForced bool `json:"ssl_forced" db:"ssl_forced" filter:"ssl_forced,boolean"`
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"npm/internal/entity/certificate"
|
||||
"npm/internal/entity/host"
|
||||
"npm/internal/entity/nginxtemplate"
|
||||
"npm/internal/entity/upstream"
|
||||
)
|
||||
|
||||
// ValidateHost will check if associated objects exist and other checks
|
||||
@ -20,6 +21,21 @@ func ValidateHost(h host.Model) error {
|
||||
}
|
||||
}
|
||||
|
||||
if h.UpstreamID > 0 {
|
||||
// Check upstream exists
|
||||
if _, uErr := upstream.GetByID(h.UpstreamID); uErr != nil {
|
||||
return fmt.Errorf("Upstream #%d does not exist", h.UpstreamID)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure either UpstreamID is set or appropriate proxy host params are set
|
||||
if h.UpstreamID > 0 && (h.ProxyHost != "" || h.ProxyPort > 0) {
|
||||
return fmt.Errorf("Proxy Host or Port cannot be set when using an Upstream")
|
||||
}
|
||||
if h.UpstreamID == 0 && (h.ProxyHost == "" || h.ProxyPort < 1) {
|
||||
return fmt.Errorf("Proxy Host and Port must be specified, unless using an Upstream")
|
||||
}
|
||||
|
||||
// Check the nginx template exists and has the same type.
|
||||
nginxTemplate, tErr := nginxtemplate.GetByID(h.NginxTemplateID)
|
||||
if tErr != nil {
|
||||
|
Reference in New Issue
Block a user