Get Move API Method Working

This commit is contained in:
Samuel Lorch 2023-04-02 12:44:15 +02:00
parent d4741c933f
commit 5ebf7f1f4b
3 changed files with 24 additions and 6 deletions

View file

@ -51,7 +51,7 @@ type MoveDestinationNATRuleParameters struct {
ToIndex uint64 `json:"to_index"` 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) { if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.DestinationNATRules) {
return struct{}{}, fmt.Errorf("DestinationNATRule does not Exist") 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() t, conf := f.ConfigManager.StartTransaction()
defer t.Discard() 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() return struct{}{}, t.Commit()
} }

View file

@ -51,7 +51,7 @@ type MoveForwardRuleParameters struct {
ToIndex uint64 `json:"to_index"` 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) { if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.ForwardRules) {
return struct{}{}, fmt.Errorf("ForwardRule does not Exist") 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() t, conf := f.ConfigManager.StartTransaction()
defer t.Discard() 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() return struct{}{}, t.Commit()
} }

View file

@ -51,7 +51,7 @@ type MoveSourceNATRuleParameters struct {
ToIndex uint64 `json:"to_index"` 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) { if int(params.Index) >= len(f.ConfigManager.GetPendingConfig().Firewall.SourceNATRules) {
return struct{}{}, fmt.Errorf("SourceNATRule does not Exist") 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() t, conf := f.ConfigManager.StartTransaction()
defer t.Discard() 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() return struct{}{}, t.Commit()
} }