mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-29 05:43:58 +00:00
Merge repeated keys in query parameters into arrays (#674)
This commit is contained in:
parent
18d90cdf36
commit
a702f0f93a
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
@ -18,16 +19,55 @@ func mapSliceRebuildAsMap(mapSlice []interface{}) (newMap map[string]interface{}
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapSliceMergeRepeatedKeys(mapSlice []interface{}) (newMapSlice []interface{}) {
|
||||||
|
newMapSlice = make([]interface{}, 0)
|
||||||
|
valuesMap := make(map[string][]interface{})
|
||||||
|
for _, item := range mapSlice {
|
||||||
|
h := item.(map[string]interface{})
|
||||||
|
key := h["name"].(string)
|
||||||
|
valuesMap[key] = append(valuesMap[key], h["value"])
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, values := range valuesMap {
|
||||||
|
h := make(map[string]interface{})
|
||||||
|
h["name"] = key
|
||||||
|
if len(values) == 1 {
|
||||||
|
h["value"] = values[0]
|
||||||
|
} else {
|
||||||
|
h["value"] = values
|
||||||
|
}
|
||||||
|
newMapSlice = append(newMapSlice, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (representation string) {
|
func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (representation string) {
|
||||||
var table []api.TableData
|
var table []api.TableData
|
||||||
for _, item := range mapSlice {
|
for _, item := range mapSlice {
|
||||||
h := item.(map[string]interface{})
|
h := item.(map[string]interface{})
|
||||||
selector := fmt.Sprintf("%s[\"%s\"]", selectorPrefix, h["name"].(string))
|
key := h["name"].(string)
|
||||||
table = append(table, api.TableData{
|
value := h["value"]
|
||||||
Name: h["name"].(string),
|
switch reflect.TypeOf(value).Kind() {
|
||||||
Value: h["value"],
|
case reflect.Slice:
|
||||||
Selector: selector,
|
fallthrough
|
||||||
})
|
case reflect.Array:
|
||||||
|
for i, el := range value.([]interface{}) {
|
||||||
|
selector := fmt.Sprintf("%s.%s[%d]", selectorPrefix, key, i)
|
||||||
|
table = append(table, api.TableData{
|
||||||
|
Name: fmt.Sprintf("%s [%d]", key, i),
|
||||||
|
Value: el,
|
||||||
|
Selector: selector,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
selector := fmt.Sprintf("%s[\"%s\"]", selectorPrefix, key)
|
||||||
|
table = append(table, api.TableData{
|
||||||
|
Name: key,
|
||||||
|
Value: value,
|
||||||
|
Selector: selector,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, _ := json.Marshal(table)
|
obj, _ := json.Marshal(table)
|
||||||
|
@ -239,7 +239,8 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, resolvedSource string,
|
|||||||
resDetails["cookies"] = mapSliceRebuildAsMap(resDetails["_cookies"].([]interface{}))
|
resDetails["cookies"] = mapSliceRebuildAsMap(resDetails["_cookies"].([]interface{}))
|
||||||
|
|
||||||
reqDetails["_queryString"] = reqDetails["queryString"]
|
reqDetails["_queryString"] = reqDetails["queryString"]
|
||||||
reqDetails["queryString"] = mapSliceRebuildAsMap(reqDetails["_queryString"].([]interface{}))
|
reqDetails["_queryStringMerged"] = mapSliceMergeRepeatedKeys(reqDetails["_queryString"].([]interface{}))
|
||||||
|
reqDetails["queryString"] = mapSliceRebuildAsMap(reqDetails["_queryStringMerged"].([]interface{}))
|
||||||
|
|
||||||
method := reqDetails["method"].(string)
|
method := reqDetails["method"].(string)
|
||||||
statusCode := int(resDetails["status"].(float64))
|
statusCode := int(resDetails["status"].(float64))
|
||||||
@ -336,7 +337,7 @@ func representRequest(request map[string]interface{}) (repRequest []interface{})
|
|||||||
repRequest = append(repRequest, api.SectionData{
|
repRequest = append(repRequest, api.SectionData{
|
||||||
Type: api.TABLE,
|
Type: api.TABLE,
|
||||||
Title: "Query String",
|
Title: "Query String",
|
||||||
Data: representMapSliceAsTable(request["_queryString"].([]interface{}), `request.queryString`),
|
Data: representMapSliceAsTable(request["_queryStringMerged"].([]interface{}), `request.queryString`),
|
||||||
})
|
})
|
||||||
|
|
||||||
postData, _ := request["postData"].(map[string]interface{})
|
postData, _ := request["postData"].(map[string]interface{})
|
||||||
|
Loading…
Reference in New Issue
Block a user