Skip to content

Commit

Permalink
adding positioning support
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Mar 29, 2024
1 parent fa1ad7d commit 218bca4
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions rule/position.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package rule

import (
"fmt"

"github.com/PaloAltoNetworks/pango/errors"
)

type Position struct {
First *bool `json:"first,omitempty"`
Last *bool `json:"last,omitempty"`
SomewhereBefore *string `json:"somewhere_before,omitempty"`
DirectlyBefore *string `json:"directly_before,omitempty"`
SomewhereAfter *string `json:"somewhere_after,omitempty"`
DirectlyAfter *string `json:"directly_after,omitempty"`
}

func (o *Position) IsValid(removeEverythingElse bool) error {
count := 0

if o.First != nil && *o.First {
count++
}

if o.Last != nil && *o.Last {
count++
}

if o.SomewhereBefore != nil {
if removeEverythingElse {
return errors.RelativePositionWithRemoveEverythingElseError
}
if *o.SomewhereBefore != "" {
count++
}
}

if o.DirectlyBefore != nil {
if removeEverythingElse {
return errors.RelativePositionWithRemoveEverythingElseError
}
if *o.DirectlyBefore != "" {
count++
}
}

if o.SomewhereAfter != nil {
if removeEverythingElse {
return errors.RelativePositionWithRemoveEverythingElseError
}
if *o.SomewhereAfter != "" {
count++
}
}

if o.DirectlyAfter != nil {
if removeEverythingElse {
return errors.RelativePositionWithRemoveEverythingElseError
}
if *o.DirectlyAfter != "" {
count++
}
}

if count > 1 {
return fmt.Errorf("multiple positions specified: only one should be specified")
}

return nil
}

0 comments on commit 218bca4

Please sign in to comment.