Seperate Definitions by Sub System

This commit is contained in:
Samuel Lorch 2023-04-13 17:03:11 +02:00
parent 14c8da64cc
commit 72bf96295d
31 changed files with 120 additions and 108 deletions

View file

@ -1,4 +1,4 @@
package definitions
package common
import (
"encoding/json"

View file

@ -1,4 +1,4 @@
package definitions
package common
import (
"encoding/json"

View file

@ -1,4 +1,4 @@
package definitions
package common
import (
"encoding/json"

View file

@ -1,4 +1,4 @@
package definitions
package config
import (
"encoding/json"
@ -6,13 +6,16 @@ import (
"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"
)
type Config struct {
ConfigVersion uint64 `json:"config_version" validate:"required,eq=1"`
Firewall Firewall `json:"firewall" validate:"required,dive"`
Object Object `json:"object" validate:"required,dive"`
Network Network `json:"network" validate:"required,dive"`
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"`
}
// Clone TODO find a better way to deep copy

View file

@ -1,4 +1,4 @@
package definitions
package firewall
type DestinationNATRule struct {
Rule

View file

@ -1,4 +1,4 @@
package definitions
package firewall
type Firewall struct {
ForwardRules []ForwardRule `json:"forward_rules" validate:"required,dive"`

View file

@ -1,4 +1,4 @@
package definitions
package firewall
type Match struct {
TCPDestinationPort uint64 `json:"tcp_destination_port,omitempty"`

View file

@ -1,4 +1,4 @@
package definitions
package firewall
import "encoding/json"

View file

@ -1,4 +1,4 @@
package definitions
package firewall
import "encoding/json"

View file

@ -1,14 +1,16 @@
package definitions
package network
import (
"encoding/json"
"nfsense.net/nfsense/internal/definitions/common"
)
type Interface struct {
Alias string `json:"alias,omitempty" validate:"min=0,max=3"`
Type InterfaceType `json:"type" validate:"min=0,max=3"`
AddressingMode InterfaceAddressingMode `json:"addressing_mode" validate:"min=0,max=2"`
Address *IPCIDR `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
Address *common.IPCIDR `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
HardwareDevice *string `json:"hardware_device,omitempty"`
// TODO fix Validator for int pointers with min=0,max=4094
VlanID *uint `json:"vlan_id,omitempty"`

View file

@ -1,4 +1,4 @@
package definitions
package network
type Network struct {
Interfaces map[string]Interface `json:"interfaces" validate:"required,dive"`

View file

@ -0,0 +1,15 @@
package network
import (
"net/netip"
"nfsense.net/nfsense/internal/definitions/common"
)
type StaticRoute struct {
Name string `json:"name,omitempty"`
Interface string `json:"interface,omitempty"`
Gateway netip.Addr `json:"gateway,omitempty"`
Destination common.IPNet `json:"destination,omitempty"`
Metric uint `json:"metric,omitempty"`
}

View file

@ -1,10 +1,11 @@
package definitions
package object
import (
"encoding/json"
"net/netip"
"go4.org/netipx"
"nfsense.net/nfsense/internal/definitions/common"
)
type Address struct {
@ -12,7 +13,7 @@ type Address struct {
Comment string `json:"comment,omitempty"`
Host *netip.Addr `json:"host,omitempty" validate:"excluded_unless=Type 0"`
Range *netipx.IPRange `json:"range,omitempty" validate:"excluded_unless=Type 1"`
NetworkAddress *IPNet `json:"network,omitempty" validate:"excluded_unless=Type 2"`
NetworkAddress *common.IPNet `json:"network,omitempty" validate:"excluded_unless=Type 2"`
Children *[]string `json:"children,omitempty"`
}

View file

@ -1,4 +1,4 @@
package definitions
package object
type Object struct {
Addresses map[string]Address `json:"addresses" validate:"required,dive"`

View file

@ -1,4 +1,4 @@
package definitions
package object
import (
"encoding/json"

View file

@ -1,13 +0,0 @@
package definitions
import (
"net/netip"
)
type StaticRoute struct {
Name string `json:"name,omitempty"`
Interface string `json:"interface,omitempty"`
Gateway netip.Addr `json:"gateway,omitempty"`
Destination IPNet `json:"destination,omitempty"`
Metric uint `json:"metric,omitempty"`
}