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

@ -4,11 +4,11 @@ import (
"context"
"fmt"
"nfsense.net/nfsense/internal/definitions"
"nfsense.net/nfsense/internal/definitions/firewall"
)
type GetDestinationNATRulesResult struct {
DestinationNATRules []definitions.DestinationNATRule `json:"destination_nat_rules"`
DestinationNATRules []firewall.DestinationNATRule `json:"destination_nat_rules"`
}
func (f *Firewall) GetDestinationNATRules(ctx context.Context, params struct{}) (GetDestinationNATRulesResult, error) {
@ -18,7 +18,7 @@ func (f *Firewall) GetDestinationNATRules(ctx context.Context, params struct{})
}
type CreateDestinationNATRuleParameters struct {
DestinationNATRule definitions.DestinationNATRule `json:"destination_nat_rule"`
DestinationNATRule firewall.DestinationNATRule `json:"destination_nat_rule"`
}
func (f *Firewall) CreateDestinationNATRule(ctx context.Context, params CreateDestinationNATRuleParameters) (struct{}, error) {
@ -30,8 +30,8 @@ func (f *Firewall) CreateDestinationNATRule(ctx context.Context, params CreateDe
}
type UpdateDestinationNATRuleParameters struct {
Index uint64 `json:"index"`
DestinationNATRule definitions.DestinationNATRule `json:"destination_nat_rule"`
Index uint64 `json:"index"`
DestinationNATRule firewall.DestinationNATRule `json:"destination_nat_rule"`
}
func (f *Firewall) UpdateDestinationNATRule(ctx context.Context, params UpdateDestinationNATRuleParameters) (struct{}, error) {
@ -61,7 +61,7 @@ func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params MoveDestin
rule := conf.Firewall.DestinationNATRules[params.Index]
sliceWithoutRule := append(conf.Firewall.DestinationNATRules[:params.Index], conf.Firewall.DestinationNATRules[params.Index+1:]...)
newSlice := make([]definitions.DestinationNATRule, params.ToIndex+1)
newSlice := make([]firewall.DestinationNATRule, params.ToIndex+1)
copy(newSlice, sliceWithoutRule[:params.ToIndex])
newSlice[params.ToIndex] = rule
conf.Firewall.DestinationNATRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...)

View file

@ -4,11 +4,11 @@ import (
"context"
"fmt"
"nfsense.net/nfsense/internal/definitions"
"nfsense.net/nfsense/internal/definitions/firewall"
)
type GetForwardRulesResult struct {
ForwardRules []definitions.ForwardRule `json:"forward_rules"`
ForwardRules []firewall.ForwardRule `json:"forward_rules"`
}
func (f *Firewall) GetForwardRules(ctx context.Context, params struct{}) (GetForwardRulesResult, error) {
@ -18,7 +18,7 @@ func (f *Firewall) GetForwardRules(ctx context.Context, params struct{}) (GetFor
}
type CreateForwardRuleParameters struct {
ForwardRule definitions.ForwardRule `json:"forward_rule"`
ForwardRule firewall.ForwardRule `json:"forward_rule"`
}
func (f *Firewall) CreateForwardRule(ctx context.Context, params CreateForwardRuleParameters) (struct{}, error) {
@ -30,8 +30,8 @@ func (f *Firewall) CreateForwardRule(ctx context.Context, params CreateForwardRu
}
type UpdateForwardRuleParameters struct {
Index uint64 `json:"index"`
ForwardRule definitions.ForwardRule `json:"forward_rule"`
Index uint64 `json:"index"`
ForwardRule firewall.ForwardRule `json:"forward_rule"`
}
func (f *Firewall) UpdateForwardRule(ctx context.Context, params UpdateForwardRuleParameters) (struct{}, error) {
@ -61,7 +61,7 @@ func (f *Firewall) MoveForwardRule(ctx context.Context, params MoveForwardRulePa
rule := conf.Firewall.ForwardRules[params.Index]
sliceWithoutRule := append(conf.Firewall.ForwardRules[:params.Index], conf.Firewall.ForwardRules[params.Index+1:]...)
newSlice := make([]definitions.ForwardRule, params.ToIndex+1)
newSlice := make([]firewall.ForwardRule, params.ToIndex+1)
copy(newSlice, sliceWithoutRule[:params.ToIndex])
newSlice[params.ToIndex] = rule
conf.Firewall.ForwardRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...)

View file

@ -4,11 +4,11 @@ import (
"context"
"fmt"
"nfsense.net/nfsense/internal/definitions"
"nfsense.net/nfsense/internal/definitions/firewall"
)
type GetSourceNATRulesResult struct {
SourceNATRules []definitions.SourceNATRule `json:"source_nat_rules"`
SourceNATRules []firewall.SourceNATRule `json:"source_nat_rules"`
}
func (f *Firewall) GetSourceNATRules(ctx context.Context, params struct{}) (GetSourceNATRulesResult, error) {
@ -18,7 +18,7 @@ func (f *Firewall) GetSourceNATRules(ctx context.Context, params struct{}) (GetS
}
type CreateSourceNATRuleParameters struct {
SourceNATRule definitions.SourceNATRule `json:"source_nat_rule"`
SourceNATRule firewall.SourceNATRule `json:"source_nat_rule"`
}
func (f *Firewall) CreateSourceNATRule(ctx context.Context, params CreateSourceNATRuleParameters) (struct{}, error) {
@ -30,8 +30,8 @@ func (f *Firewall) CreateSourceNATRule(ctx context.Context, params CreateSourceN
}
type UpdateSourceNATRuleParameters struct {
Index uint64 `json:"index"`
SourceNATRule definitions.SourceNATRule `json:"source_nat_rule"`
Index uint64 `json:"index"`
SourceNATRule firewall.SourceNATRule `json:"source_nat_rule"`
}
func (f *Firewall) UpdateSourceNATRule(ctx context.Context, params UpdateSourceNATRuleParameters) (struct{}, error) {
@ -61,7 +61,7 @@ func (f *Firewall) MoveSourceNATRule(ctx context.Context, params MoveSourceNATRu
rule := conf.Firewall.SourceNATRules[params.Index]
sliceWithoutRule := append(conf.Firewall.SourceNATRules[:params.Index], conf.Firewall.SourceNATRules[params.Index+1:]...)
newSlice := make([]definitions.SourceNATRule, params.ToIndex+1)
newSlice := make([]firewall.SourceNATRule, params.ToIndex+1)
copy(newSlice, sliceWithoutRule[:params.ToIndex])
newSlice[params.ToIndex] = rule
conf.Firewall.SourceNATRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...)