mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-18 16:05:37 +00:00
Refactor the protocol payload structs
This commit is contained in:
@@ -98,7 +98,6 @@ func emitAMQP(event interface{}, _type string, method string, connectionInfo *ap
|
||||
IsRequest: true,
|
||||
CaptureTime: time.Now(),
|
||||
Payload: AMQPPayload{
|
||||
Type: _type,
|
||||
Data: &AMQPWrapper{
|
||||
Method: method,
|
||||
Url: "",
|
||||
|
@@ -5,8 +5,6 @@ import (
|
||||
)
|
||||
|
||||
type AMQPPayload struct {
|
||||
Type string
|
||||
Method string
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
@@ -16,10 +14,4 @@ type AMQPPayloader interface {
|
||||
|
||||
func (h AMQPPayload) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(h.Data)
|
||||
// switch h.Type {
|
||||
// case "amqp_request":
|
||||
// return json.Marshal(h.Data)
|
||||
// default:
|
||||
// panic(fmt.Sprintf("AMQP payload cannot be marshaled: %s\n", h.Type))
|
||||
// }
|
||||
}
|
||||
|
@@ -39,6 +39,11 @@ var http2Protocol api.Protocol = api.Protocol{
|
||||
Ports: []string{"80", "8080"},
|
||||
}
|
||||
|
||||
const (
|
||||
TypeHttpRequest = iota
|
||||
TypeHttpResponse
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.Println("Initializing HTTP extension.")
|
||||
requestCounter = 0
|
||||
|
@@ -32,7 +32,7 @@ func (matcher *requestResponseMatcher) registerRequest(ident string, request *ht
|
||||
IsRequest: true,
|
||||
CaptureTime: captureTime,
|
||||
Payload: HTTPPayload{
|
||||
Type: "http_request",
|
||||
Type: TypeHttpRequest,
|
||||
Data: request,
|
||||
},
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func (matcher *requestResponseMatcher) registerResponse(ident string, response *
|
||||
IsRequest: false,
|
||||
CaptureTime: captureTime,
|
||||
Payload: HTTPPayload{
|
||||
Type: "http_response",
|
||||
Type: TypeHttpResponse,
|
||||
Data: response,
|
||||
},
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type HTTPPayload struct {
|
||||
Type string
|
||||
Type uint8
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type HTTPWrapper struct {
|
||||
|
||||
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||
switch h.Type {
|
||||
case "http_request":
|
||||
case TypeHttpRequest:
|
||||
harRequest, err := har.NewRequest(h.Data.(*http.Request), true)
|
||||
if err != nil {
|
||||
rlog.Debugf("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
|
||||
@@ -38,7 +38,7 @@ func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||
Url: "",
|
||||
Details: harRequest,
|
||||
})
|
||||
case "http_response":
|
||||
case TypeHttpResponse:
|
||||
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
||||
if err != nil {
|
||||
rlog.Debugf("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)
|
||||
|
@@ -7,7 +7,6 @@ import (
|
||||
)
|
||||
|
||||
type KafkaPayload struct {
|
||||
Type string
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
|
@@ -257,7 +257,6 @@ func ReadResponse(r io.Reader, tcpID *api.TcpID, emitter api.Emitter) (err error
|
||||
IsRequest: true,
|
||||
CaptureTime: time.Now(),
|
||||
Payload: KafkaPayload{
|
||||
Type: "kafka_request",
|
||||
Data: &KafkaWrapper{
|
||||
Method: apiNames[apiKey],
|
||||
Url: "",
|
||||
@@ -269,7 +268,6 @@ func ReadResponse(r io.Reader, tcpID *api.TcpID, emitter api.Emitter) (err error
|
||||
IsRequest: false,
|
||||
CaptureTime: time.Now(),
|
||||
Payload: KafkaPayload{
|
||||
Type: "kafka_response",
|
||||
Data: &KafkaWrapper{
|
||||
Method: apiNames[apiKey],
|
||||
Url: "",
|
||||
|
Reference in New Issue
Block a user