Skip to content

Commit

Permalink
add new formatter (#77)
Browse files Browse the repository at this point in the history
* add f5 formatter
* Add netmask
* Add category scenario split / index 1
* Handle lists scenarios
  • Loading branch information
LaurenceJJones authored Jan 3, 2024
1 parent 61b396d commit 9a368ca
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/formatters/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
var ByName = map[string]func(w http.ResponseWriter, r *http.Request){
"plain_text": PlainText,
"mikrotik": MikroTik,
"f5": F5,
}

func PlainText(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -49,3 +50,35 @@ func MikroTik(w http.ResponseWriter, r *http.Request) {
)
}
}

func F5(w http.ResponseWriter, r *http.Request) {
decisions := r.Context().Value(registry.GlobalDecisionRegistry.Key).([]*models.Decision)
for _, decision := range decisions {
var category = *decision.Scenario
if strings.Contains(*decision.Scenario, "/") {
category = strings.Split(*decision.Scenario, "/")[1]
}
switch strings.ToLower(*decision.Scope) {
case "ip":
mask := 32
if strings.Contains(*decision.Value, ":") {
mask = 64
}
fmt.Fprintf(w,
"%s,%d,bl,%s\n",
*decision.Value,
mask,
category,
)
case "range":
sep := strings.Split(*decision.Value, "/")
fmt.Fprintf(w,
"%s,%s,bl,%s\n",
sep[0],
sep[1],
category,
)
default:
}
}
}

0 comments on commit 9a368ca

Please sign in to comment.