Skip to content

Commit f451f21

Browse files
committed
Adding filtering by ip support
Signed-off-by: Matan Schatzman <[email protected]>
1 parent e28be4d commit f451f21

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
server.GET("/health", cache.CacheByRequestURI(memoryStore, HEALTH_CACHE_TIME), handlers.HealthHandler)
2424
server.GET("/apis/*path", cache.CacheByRequestURI(memoryStore, API_CACHE_TIME), handlers.RequestHandler)
2525

26-
log.Printf("listening for server 8080 - v0.0.8 - API cache time: %v", API_CACHE_TIME)
26+
log.Printf("listening for server 8080 - v0.0.9 - API cache time: %v", API_CACHE_TIME)
2727

2828
err := server.RunTLS(":8080", "./cert/tls.crt", "./cert/tls.key") // listen and serve on 0.0.0.0:8080
2929

util/util.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ func isMigratable(statuses []interface{}, search string) bool {
182182
return true
183183
}
184184

185+
func isIPExist(interfaces []interface{}, search string) bool {
186+
result := false
187+
for _, nic := range interfaces {
188+
nicsArr := nic.(map[string]interface{})["ipAddresses"].([]interface{})
189+
isExist := slices.ContainsFunc(nicsArr, func(ip interface{}) bool {
190+
return strings.Contains(ip.(string), search)
191+
})
192+
if isExist {
193+
result = true
194+
break
195+
}
196+
}
197+
return result
198+
}
199+
185200
func FilterResponseQuery(bodyBytes []byte, query url.Values) map[string]interface{} {
186201
items := gjson.ParseBytes(bodyBytes).Get("items").Array()
187202
filteredJson := []interface{}{}
@@ -206,6 +221,13 @@ func FilterResponseQuery(bodyBytes []byte, query url.Values) map[string]interfac
206221
}
207222
continue
208223
}
224+
if key == "status.interfaces" {
225+
isIP := isIPExist(itemValue.Value().([]interface{}), search)
226+
if !isIP {
227+
continue nextItem
228+
}
229+
continue
230+
}
209231
okInclude := labelsIncludes(itemValue.Value().(map[string]interface{}), search)
210232
if !okInclude {
211233
continue nextItem

0 commit comments

Comments
 (0)