diff --git a/cmd/dashboard/controller/waf.go b/cmd/dashboard/controller/waf.go index 91eb389281..4b5faf7334 100644 --- a/cmd/dashboard/controller/waf.go +++ b/cmd/dashboard/controller/waf.go @@ -1,6 +1,8 @@ package controller import ( + "net" + "slices" "strconv" "github.com/gin-gonic/gin" @@ -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 @@ -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.ConvertSeq(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, diff --git a/pkg/geoip/geoip.db b/pkg/geoip/geoip.db index 7bd069c80f..39802f6428 100644 --- a/pkg/geoip/geoip.db +++ b/pkg/geoip/geoip.db @@ -1 +1 @@ -stub \ No newline at end of file +stub diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 98ab9bf3ae..cd8ba76b2b 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -3,6 +3,7 @@ package utils import ( "crypto/rand" "errors" + "iter" "maps" "math/big" "net/netip" @@ -164,3 +165,13 @@ func Unique[T comparable](s []T) []T { } return ret } + +func ConvertSeq[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 + } + } + } +}