Skip to content

Commit

Permalink
feat(waf): return ip in string literal
Browse files Browse the repository at this point in the history
  • Loading branch information
uubulb committed Jan 4, 2025
1 parent 3999d1f commit d29fb79
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/dashboard/controller/waf.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller

import (
"net"
"slices"
"strconv"

"github.com/gin-gonic/gin"
Expand All @@ -21,7 +23,7 @@ import (
// @Produce json
// @Success 200 {object} model.PaginatedResponse[[]model.WAFApiMock, model.WAFApiMock]
// @Router /waf [get]
func listBlockedAddress(c *gin.Context) (*model.Value[[]*model.WAF], error) {
func listBlockedAddress(c *gin.Context) (*model.Value[[]*model.WAFApiMock], error) {
limit, err := strconv.Atoi(c.Query("limit"))
if err != nil || limit < 1 {
limit = 25
Expand All @@ -42,8 +44,16 @@ func listBlockedAddress(c *gin.Context) (*model.Value[[]*model.WAF], error) {
return nil, err
}

return &model.Value[[]*model.WAF]{
Value: waf,
return &model.Value[[]*model.WAFApiMock]{
Value: slices.Collect(utils.Map(slices.Values(waf), func(e *model.WAF) *model.WAFApiMock {
return &model.WAFApiMock{
IP: net.IP(e.IP).String(),
BlockIdentifier: e.BlockIdentifier,
BlockReason: e.BlockReason,
BlockTimestamp: e.BlockTimestamp,
Count: e.Count,
}
})),
Pagination: model.Pagination{
Offset: offset,
Limit: limit,
Expand Down
Binary file modified pkg/geoip/geoip.db
Binary file not shown.
11 changes: 11 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"crypto/rand"
"errors"
"iter"
"maps"
"math/big"
"net/netip"
Expand Down Expand Up @@ -164,3 +165,13 @@ func Unique[T comparable](s []T) []T {
}
return ret
}

func Map[T, U any](seq iter.Seq[T], f func(e T) U) iter.Seq[U] {
return func(yield func(U) bool) {
for e := range seq {
if !yield(f(e)) {
return
}
}
}
}

0 comments on commit d29fb79

Please sign in to comment.