mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-19 17:20:25 +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,
|
IsRequest: true,
|
||||||
CaptureTime: time.Now(),
|
CaptureTime: time.Now(),
|
||||||
Payload: AMQPPayload{
|
Payload: AMQPPayload{
|
||||||
Type: _type,
|
|
||||||
Data: &AMQPWrapper{
|
Data: &AMQPWrapper{
|
||||||
Method: method,
|
Method: method,
|
||||||
Url: "",
|
Url: "",
|
||||||
|
@@ -5,9 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AMQPPayload struct {
|
type AMQPPayload struct {
|
||||||
Type string
|
Data interface{}
|
||||||
Method string
|
|
||||||
Data interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AMQPPayloader interface {
|
type AMQPPayloader interface {
|
||||||
@@ -16,10 +14,4 @@ type AMQPPayloader interface {
|
|||||||
|
|
||||||
func (h AMQPPayload) MarshalJSON() ([]byte, error) {
|
func (h AMQPPayload) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(h.Data)
|
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"},
|
Ports: []string{"80", "8080"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
TypeHttpRequest = iota
|
||||||
|
TypeHttpResponse
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.Println("Initializing HTTP extension.")
|
log.Println("Initializing HTTP extension.")
|
||||||
requestCounter = 0
|
requestCounter = 0
|
||||||
|
@@ -32,7 +32,7 @@ func (matcher *requestResponseMatcher) registerRequest(ident string, request *ht
|
|||||||
IsRequest: true,
|
IsRequest: true,
|
||||||
CaptureTime: captureTime,
|
CaptureTime: captureTime,
|
||||||
Payload: HTTPPayload{
|
Payload: HTTPPayload{
|
||||||
Type: "http_request",
|
Type: TypeHttpRequest,
|
||||||
Data: request,
|
Data: request,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func (matcher *requestResponseMatcher) registerResponse(ident string, response *
|
|||||||
IsRequest: false,
|
IsRequest: false,
|
||||||
CaptureTime: captureTime,
|
CaptureTime: captureTime,
|
||||||
Payload: HTTPPayload{
|
Payload: HTTPPayload{
|
||||||
Type: "http_response",
|
Type: TypeHttpResponse,
|
||||||
Data: response,
|
Data: response,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HTTPPayload struct {
|
type HTTPPayload struct {
|
||||||
Type string
|
Type uint8
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ type HTTPWrapper struct {
|
|||||||
|
|
||||||
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||||
switch h.Type {
|
switch h.Type {
|
||||||
case "http_request":
|
case TypeHttpRequest:
|
||||||
harRequest, err := har.NewRequest(h.Data.(*http.Request), true)
|
harRequest, err := har.NewRequest(h.Data.(*http.Request), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rlog.Debugf("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
|
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: "",
|
Url: "",
|
||||||
Details: harRequest,
|
Details: harRequest,
|
||||||
})
|
})
|
||||||
case "http_response":
|
case TypeHttpResponse:
|
||||||
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rlog.Debugf("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)
|
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 KafkaPayload struct {
|
||||||
Type string
|
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -257,7 +257,6 @@ func ReadResponse(r io.Reader, tcpID *api.TcpID, emitter api.Emitter) (err error
|
|||||||
IsRequest: true,
|
IsRequest: true,
|
||||||
CaptureTime: time.Now(),
|
CaptureTime: time.Now(),
|
||||||
Payload: KafkaPayload{
|
Payload: KafkaPayload{
|
||||||
Type: "kafka_request",
|
|
||||||
Data: &KafkaWrapper{
|
Data: &KafkaWrapper{
|
||||||
Method: apiNames[apiKey],
|
Method: apiNames[apiKey],
|
||||||
Url: "",
|
Url: "",
|
||||||
@@ -269,7 +268,6 @@ func ReadResponse(r io.Reader, tcpID *api.TcpID, emitter api.Emitter) (err error
|
|||||||
IsRequest: false,
|
IsRequest: false,
|
||||||
CaptureTime: time.Now(),
|
CaptureTime: time.Now(),
|
||||||
Payload: KafkaPayload{
|
Payload: KafkaPayload{
|
||||||
Type: "kafka_response",
|
|
||||||
Data: &KafkaWrapper{
|
Data: &KafkaWrapper{
|
||||||
Method: apiNames[apiKey],
|
Method: apiNames[apiKey],
|
||||||
Url: "",
|
Url: "",
|
||||||
|
Reference in New Issue
Block a user