mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-01 10:36:55 +00:00
Implement representBasicPublish
method
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
@@ -90,7 +92,7 @@ type AMQPWrapper struct {
|
|||||||
Details interface{}
|
Details interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func emitBasicPublish(eventBasicPublish BasicPublish, connectionInfo *api.ConnectionInfo, emitter api.Emitter) {
|
func emitBasicPublish(event BasicPublish, connectionInfo *api.ConnectionInfo, emitter api.Emitter) {
|
||||||
request := &api.GenericMessage{
|
request := &api.GenericMessage{
|
||||||
IsRequest: true,
|
IsRequest: true,
|
||||||
CaptureTime: time.Now(),
|
CaptureTime: time.Now(),
|
||||||
@@ -98,7 +100,7 @@ func emitBasicPublish(eventBasicPublish BasicPublish, connectionInfo *api.Connec
|
|||||||
Type: "basic_publish",
|
Type: "basic_publish",
|
||||||
Data: &AMQPWrapper{
|
Data: &AMQPWrapper{
|
||||||
Method: "Basic Publish",
|
Method: "Basic Publish",
|
||||||
Details: eventBasicPublish,
|
Details: event,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -114,18 +116,160 @@ func emitBasicPublish(eventBasicPublish BasicPublish, connectionInfo *api.Connec
|
|||||||
emitter.Emit(item)
|
emitter.Emit(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEventBasicPublish(eventBasicPublish BasicPublish) {
|
func representBasicPublish(event map[string]interface{}) []interface{} {
|
||||||
return
|
rep := make([]interface{}, 0)
|
||||||
fmt.Printf(
|
|
||||||
"[%s] Exchange: %s, RoutingKey: %s, Mandatory: %t, Immediate: %t, Properties: %v, Body: %s\n",
|
details, _ := json.Marshal([]map[string]string{
|
||||||
basicMethodMap[40],
|
{
|
||||||
eventBasicPublish.Exchange,
|
"name": "Exchange",
|
||||||
eventBasicPublish.RoutingKey,
|
"value": event["Exchange"].(string),
|
||||||
eventBasicPublish.Mandatory,
|
},
|
||||||
eventBasicPublish.Immediate,
|
{
|
||||||
eventBasicPublish.Properties,
|
"name": "Immediate",
|
||||||
eventBasicPublish.Body,
|
"value": strconv.FormatBool(event["Immediate"].(bool)),
|
||||||
)
|
},
|
||||||
|
{
|
||||||
|
"name": "Mandatory",
|
||||||
|
"value": strconv.FormatBool(event["Mandatory"].(bool)),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "table",
|
||||||
|
"title": "Details",
|
||||||
|
"data": string(details),
|
||||||
|
})
|
||||||
|
|
||||||
|
contentType := ""
|
||||||
|
contentEncoding := ""
|
||||||
|
deliveryMode := ""
|
||||||
|
priority := ""
|
||||||
|
correlationId := ""
|
||||||
|
replyTo := ""
|
||||||
|
expiration := ""
|
||||||
|
messageId := ""
|
||||||
|
timestamp := ""
|
||||||
|
_type := ""
|
||||||
|
userId := ""
|
||||||
|
appId := ""
|
||||||
|
|
||||||
|
properties := event["Properties"].(map[string]interface{})
|
||||||
|
|
||||||
|
if properties["ContentType"] != nil {
|
||||||
|
contentType = properties["ContentType"].(string)
|
||||||
|
}
|
||||||
|
if properties["ContentEncoding"] != nil {
|
||||||
|
contentEncoding = properties["ContentEncoding"].(string)
|
||||||
|
}
|
||||||
|
if properties["Delivery Mode"] != nil {
|
||||||
|
deliveryMode = fmt.Sprintf("%g", properties["DeliveryMode"].(float64))
|
||||||
|
}
|
||||||
|
if properties["Priority"] != nil {
|
||||||
|
priority = fmt.Sprintf("%g", properties["Priority"].(float64))
|
||||||
|
}
|
||||||
|
if properties["CorrelationId"] != nil {
|
||||||
|
correlationId = properties["CorrelationId"].(string)
|
||||||
|
}
|
||||||
|
if properties["ReplyTo"] != nil {
|
||||||
|
replyTo = properties["ReplyTo"].(string)
|
||||||
|
}
|
||||||
|
if properties["Expiration"] != nil {
|
||||||
|
expiration = properties["Expiration"].(string)
|
||||||
|
}
|
||||||
|
if properties["MessageId"] != nil {
|
||||||
|
messageId = properties["MessageId"].(string)
|
||||||
|
}
|
||||||
|
if properties["Timestamp"] != nil {
|
||||||
|
timestamp = properties["Timestamp"].(string)
|
||||||
|
}
|
||||||
|
if properties["Type"] != nil {
|
||||||
|
_type = properties["Type"].(string)
|
||||||
|
}
|
||||||
|
if properties["UserId"] != nil {
|
||||||
|
userId = properties["UserId"].(string)
|
||||||
|
}
|
||||||
|
if properties["AppId"] != nil {
|
||||||
|
appId = properties["AppId"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
props, _ := json.Marshal([]map[string]string{
|
||||||
|
{
|
||||||
|
"name": "Content Type",
|
||||||
|
"value": contentType,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Content Encoding",
|
||||||
|
"value": contentEncoding,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delivery Mode",
|
||||||
|
"value": deliveryMode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Priority",
|
||||||
|
"value": priority,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Correlation ID",
|
||||||
|
"value": correlationId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Reply To",
|
||||||
|
"value": replyTo,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Expiration",
|
||||||
|
"value": expiration,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Message ID",
|
||||||
|
"value": messageId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Timestamp",
|
||||||
|
"value": timestamp,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Type",
|
||||||
|
"value": _type,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "User ID",
|
||||||
|
"value": userId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "App ID",
|
||||||
|
"value": appId,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "table",
|
||||||
|
"title": "Properties",
|
||||||
|
"data": string(props),
|
||||||
|
})
|
||||||
|
|
||||||
|
headers := make([]map[string]string, 0)
|
||||||
|
for name, value := range properties["Headers"].(map[string]interface{}) {
|
||||||
|
headers = append(headers, map[string]string{
|
||||||
|
"name": name,
|
||||||
|
"value": value.(string),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
headersMarshaled, _ := json.Marshal(headers)
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "table",
|
||||||
|
"title": "Headers",
|
||||||
|
"data": string(headersMarshaled),
|
||||||
|
})
|
||||||
|
|
||||||
|
rep = append(rep, map[string]string{
|
||||||
|
"type": "body",
|
||||||
|
"title": "Body",
|
||||||
|
"encoding": contentEncoding,
|
||||||
|
"mime_type": contentType,
|
||||||
|
"data": event["Body"].(string),
|
||||||
|
}) // FIXME: `Body` value seems wrong
|
||||||
|
|
||||||
|
return rep
|
||||||
}
|
}
|
||||||
|
|
||||||
func printEventBasicDeliver(eventBasicDeliver BasicDeliver) {
|
func printEventBasicDeliver(eventBasicDeliver BasicDeliver) {
|
||||||
|
@@ -103,7 +103,6 @@ func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, em
|
|||||||
switch lastMethodFrameMessage.(type) {
|
switch lastMethodFrameMessage.(type) {
|
||||||
case *BasicPublish:
|
case *BasicPublish:
|
||||||
eventBasicPublish.Body = f.Body
|
eventBasicPublish.Body = f.Body
|
||||||
printEventBasicPublish(*eventBasicPublish)
|
|
||||||
emitBasicPublish(*eventBasicPublish, connectionInfo, emitter)
|
emitBasicPublish(*eventBasicPublish, connectionInfo, emitter)
|
||||||
case *BasicDeliver:
|
case *BasicDeliver:
|
||||||
eventBasicDeliver.Body = f.Body
|
eventBasicDeliver.Body = f.Body
|
||||||
@@ -258,11 +257,19 @@ func (d dissecting) Represent(entry string) ([]byte, error) {
|
|||||||
var root map[string]interface{}
|
var root map[string]interface{}
|
||||||
json.Unmarshal([]byte(entry), &root)
|
json.Unmarshal([]byte(entry), &root)
|
||||||
representation := make(map[string]interface{}, 0)
|
representation := make(map[string]interface{}, 0)
|
||||||
// request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||||
|
log.Printf("request: %+v\n", request)
|
||||||
|
var repRequest []interface{}
|
||||||
|
details := request["Details"].(map[string]interface{})
|
||||||
|
switch request["Method"].(string) {
|
||||||
|
case "Basic Publish":
|
||||||
|
repRequest = representBasicPublish(details)
|
||||||
|
break
|
||||||
|
}
|
||||||
// response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
// response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||||
// repRequest := representRequest(request)
|
// repRequest := representRequest(request)
|
||||||
// repResponse := representResponse(response)
|
// repResponse := representResponse(response)
|
||||||
// representation["request"] = repRequest
|
representation["request"] = repRequest
|
||||||
// representation["response"] = repResponse
|
// representation["response"] = repResponse
|
||||||
return json.Marshal(representation)
|
return json.Marshal(representation)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user