mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 02:48:21 +00:00
Get Move API Method Working
This commit is contained in:
parent
d4741c933f
commit
5ebf7f1f4b
3 changed files with 24 additions and 6 deletions
|
@ -51,7 +51,7 @@ type MoveDestinationNATRuleParameters struct {
|
|||
ToIndex uint64 `json:"to_index"`
|
||||
}
|
||||
|
||||
func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params DeleteDestinationNATRuleParameters) (struct{}, error) {
|
||||
func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params MoveDestinationNATRuleParameters) (struct{}, error) {
|
||||
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.DestinationNATRules) {
|
||||
return struct{}{}, fmt.Errorf("DestinationNATRule does not Exist")
|
||||
}
|
||||
|
@ -59,7 +59,13 @@ func (f *Firewall) MoveDestinationNATRule(ctx context.Context, params DeleteDest
|
|||
t, conf := f.ConfigManager.StartTransaction()
|
||||
defer t.Discard()
|
||||
|
||||
conf.Firewall.DestinationNATRules = append(conf.Firewall.DestinationNATRules[:params.Index], conf.Firewall.DestinationNATRules[params.Index+1:]...)
|
||||
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)
|
||||
copy(newSlice, sliceWithoutRule[:params.ToIndex])
|
||||
newSlice[params.ToIndex] = rule
|
||||
conf.Firewall.DestinationNATRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...)
|
||||
|
||||
return struct{}{}, t.Commit()
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ type MoveForwardRuleParameters struct {
|
|||
ToIndex uint64 `json:"to_index"`
|
||||
}
|
||||
|
||||
func (f *Firewall) MoveForwardRule(ctx context.Context, params DeleteForwardRuleParameters) (struct{}, error) {
|
||||
func (f *Firewall) MoveForwardRule(ctx context.Context, params MoveForwardRuleParameters) (struct{}, error) {
|
||||
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.ForwardRules) {
|
||||
return struct{}{}, fmt.Errorf("ForwardRule does not Exist")
|
||||
}
|
||||
|
@ -59,7 +59,13 @@ func (f *Firewall) MoveForwardRule(ctx context.Context, params DeleteForwardRule
|
|||
t, conf := f.ConfigManager.StartTransaction()
|
||||
defer t.Discard()
|
||||
|
||||
conf.Firewall.ForwardRules = append(conf.Firewall.ForwardRules[:params.Index], conf.Firewall.ForwardRules[params.Index+1:]...)
|
||||
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)
|
||||
copy(newSlice, sliceWithoutRule[:params.ToIndex])
|
||||
newSlice[params.ToIndex] = rule
|
||||
conf.Firewall.ForwardRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...)
|
||||
|
||||
return struct{}{}, t.Commit()
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ type MoveSourceNATRuleParameters struct {
|
|||
ToIndex uint64 `json:"to_index"`
|
||||
}
|
||||
|
||||
func (f *Firewall) MoveSourceNATRule(ctx context.Context, params DeleteSourceNATRuleParameters) (struct{}, error) {
|
||||
func (f *Firewall) MoveSourceNATRule(ctx context.Context, params MoveSourceNATRuleParameters) (struct{}, error) {
|
||||
if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.SourceNATRules) {
|
||||
return struct{}{}, fmt.Errorf("SourceNATRule does not Exist")
|
||||
}
|
||||
|
@ -59,7 +59,13 @@ func (f *Firewall) MoveSourceNATRule(ctx context.Context, params DeleteSourceNAT
|
|||
t, conf := f.ConfigManager.StartTransaction()
|
||||
defer t.Discard()
|
||||
|
||||
conf.Firewall.SourceNATRules = append(conf.Firewall.SourceNATRules[:params.Index], conf.Firewall.SourceNATRules[params.Index+1:]...)
|
||||
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)
|
||||
copy(newSlice, sliceWithoutRule[:params.ToIndex])
|
||||
newSlice[params.ToIndex] = rule
|
||||
conf.Firewall.SourceNATRules = append(newSlice, sliceWithoutRule[params.ToIndex:]...)
|
||||
|
||||
return struct{}{}, t.Commit()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue