mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
Remove old, broken Validation
This commit is contained in:
parent
e12a1fe16f
commit
f67ec52fae
13 changed files with 39 additions and 64 deletions
|
@ -4,8 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"golang.org/x/exp/slog"
|
||||
"nfsense.net/nfsense/internal/definitions/firewall"
|
||||
"nfsense.net/nfsense/internal/definitions/network"
|
||||
"nfsense.net/nfsense/internal/definitions/object"
|
||||
|
@ -16,13 +14,13 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
ConfigVersion uint64 `json:"config_version" validate:"required,eq=1"`
|
||||
Firewall firewall.Firewall `json:"firewall" validate:"required,dive"`
|
||||
Object object.Object `json:"object" validate:"required,dive"`
|
||||
Network network.Network `json:"network" validate:"required,dive"`
|
||||
Service service.Service `json:"service" validate:"required,dive"`
|
||||
VPN vpn.VPN `json:"vpn" validate:"required,dive"`
|
||||
System system.System `json:"system" validate:"required,dive"`
|
||||
ConfigVersion uint64 `json:"config_version"`
|
||||
Firewall firewall.Firewall `json:"firewall"`
|
||||
Object object.Object `json:"object"`
|
||||
Network network.Network `json:"network"`
|
||||
Service service.Service `json:"service"`
|
||||
VPN vpn.VPN `json:"vpn"`
|
||||
System system.System `json:"system"`
|
||||
}
|
||||
|
||||
// Clone TODO find a better way to deep copy
|
||||
|
@ -40,28 +38,5 @@ func (c *Config) Clone() *Config {
|
|||
}
|
||||
|
||||
func ValidateConfig(conf *Config) error {
|
||||
err := validation.ValidateConfig(*conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
val := validator.New()
|
||||
val.RegisterValidation("test", nilIfOtherNil)
|
||||
return val.Struct(conf)
|
||||
}
|
||||
|
||||
func nilIfOtherNil(fl validator.FieldLevel) bool {
|
||||
slog.Info("Start", "field", fl.FieldName(), "param", fl.Param())
|
||||
if !fl.Field().IsNil() {
|
||||
slog.Info("Field is not nil", "field", fl.FieldName())
|
||||
f := fl.Parent().FieldByName(fl.Param())
|
||||
if f.IsZero() {
|
||||
panic(fmt.Errorf("Param %v is not a Valid Field", fl.Param()))
|
||||
}
|
||||
if !f.IsNil() {
|
||||
slog.Info("Fail", "field", fl.FieldName(), "param", fl.Param())
|
||||
return false
|
||||
}
|
||||
}
|
||||
slog.Info("Success", "field", fl.FieldName(), "param", fl.Param())
|
||||
return true
|
||||
return validation.ValidateConfig(*conf)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue