Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(waf): return ip in string literal #947

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion pkg/geoip/geoip.db
Original file line number Diff line number Diff line change
@@ -1 +1 @@
stub
stub
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] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改个名 MapSlice 不然以为是 map

return func(yield func(U) bool) {
for e := range seq {
if !yield(f(e)) {
return
}
}
}
}
Loading