mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 18:16:26 +00:00
More work to support nullable foreign keys
Adds nullable int/uint types
This commit is contained in:
@ -12,27 +12,27 @@ import (
|
||||
// ValidateHost will check if associated objects exist and other checks
|
||||
// will return a nil error if things are OK
|
||||
func ValidateHost(h host.Model) error {
|
||||
if h.CertificateID > 0 {
|
||||
if h.CertificateID.Uint > 0 {
|
||||
// Check certificate exists and is valid
|
||||
// This will not determine if the certificate is Ready to use,
|
||||
// as this validation only cares that the row exists.
|
||||
if _, cErr := certificate.GetByID(h.CertificateID); cErr != nil {
|
||||
return eris.Wrapf(cErr, "Certificate #%d does not exist", h.CertificateID)
|
||||
if _, cErr := certificate.GetByID(h.CertificateID.Uint); cErr != nil {
|
||||
return eris.Wrapf(cErr, "Certificate #%d does not exist", h.CertificateID.Uint)
|
||||
}
|
||||
}
|
||||
|
||||
if h.UpstreamID > 0 {
|
||||
if h.UpstreamID.Uint > 0 {
|
||||
// Check upstream exists
|
||||
if _, uErr := upstream.GetByID(h.UpstreamID); uErr != nil {
|
||||
return eris.Wrapf(uErr, "Upstream #%d does not exist", h.UpstreamID)
|
||||
if _, uErr := upstream.GetByID(h.UpstreamID.Uint); uErr != nil {
|
||||
return eris.Wrapf(uErr, "Upstream #%d does not exist", h.UpstreamID.Uint)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure either UpstreamID is set or appropriate proxy host params are set
|
||||
if h.UpstreamID > 0 && (h.ProxyHost != "" || h.ProxyPort > 0) {
|
||||
if h.UpstreamID.Uint > 0 && (h.ProxyHost != "" || h.ProxyPort > 0) {
|
||||
return eris.Errorf("Proxy Host or Port cannot be set when using an Upstream")
|
||||
}
|
||||
if h.UpstreamID == 0 && (h.ProxyHost == "" || h.ProxyPort < 1) {
|
||||
if h.UpstreamID.Uint == 0 && (h.ProxyHost == "" || h.ProxyPort < 1) {
|
||||
return eris.Errorf("Proxy Host and Port must be specified, unless using an Upstream")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user