mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
orchestrator/clickhouse: fix Networks field validation
This commit is contained in:
@@ -20,7 +20,10 @@ var Validate *validator.Validate
|
||||
func RegisterSubnetMapValidation[V any]() {
|
||||
var zero SubnetMap[V]
|
||||
validatorFunc := func(field reflect.Value) interface{} {
|
||||
if subnetMap, ok := field.Interface().(SubnetMap[V]); ok {
|
||||
switch subnetMap := field.Interface().(type) {
|
||||
case SubnetMap[V]:
|
||||
return subnetMap.ToMap()
|
||||
case *SubnetMap[V]:
|
||||
return subnetMap.ToMap()
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -37,7 +37,7 @@ type Configuration struct {
|
||||
// Communities is a mapping from exporter IPs to SNMPv2 communities
|
||||
Communities *helpers.SubnetMap[string]
|
||||
// SecurityParameters is a mapping from exporter IPs to SNMPv3 security parameters
|
||||
SecurityParameters *helpers.SubnetMap[SecurityParameters] `validate:"dive"`
|
||||
SecurityParameters *helpers.SubnetMap[SecurityParameters] `validate:"omitempty,dive"`
|
||||
}
|
||||
|
||||
// SecurityParameters describes SNMPv3 USM security parameters.
|
||||
|
||||
@@ -30,7 +30,7 @@ type Configuration struct {
|
||||
ASNs map[uint32]string
|
||||
// Networks is a mapping from IP networks to attributes. It is used
|
||||
// to instantiate the SrcNet* and DstNet* columns.
|
||||
Networks *helpers.SubnetMap[NetworkAttributes] `validate:"dive"`
|
||||
Networks *helpers.SubnetMap[NetworkAttributes] `validate:"omitempty,dive"`
|
||||
// OrchestratorURL allows one to override URL to reach
|
||||
// orchestrator from Clickhouse
|
||||
OrchestratorURL string `validate:"isdefault|url"`
|
||||
@@ -105,4 +105,5 @@ func NetworkAttributesUnmarshallerHook() mapstructure.DecodeHookFunc {
|
||||
func init() {
|
||||
helpers.RegisterMapstructureUnmarshallerHook(helpers.SubnetMapUnmarshallerHook[NetworkAttributes]())
|
||||
helpers.RegisterMapstructureUnmarshallerHook(NetworkAttributesUnmarshallerHook())
|
||||
helpers.RegisterSubnetMapValidation[NetworkAttributes]()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user