mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-22 18:47:02 +00:00
Remove OAS contract monitoring feature (#1163)
This commit is contained in:
250
tap/api/api.go
250
tap/api/api.go
@@ -2,24 +2,13 @@ package api
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/martian/har"
|
||||
|
||||
"github.com/up9inc/mizu/tap/dbgctl"
|
||||
)
|
||||
|
||||
const mizuTestEnvVar = "MIZU_TEST"
|
||||
const UnknownNamespace = ""
|
||||
|
||||
var UnknownIp = net.IP{0, 0, 0, 0}
|
||||
@@ -161,26 +150,21 @@ func (e *Emitting) Emit(item *OutputChannelItem) {
|
||||
}
|
||||
|
||||
type Entry struct {
|
||||
Id string `json:"id"`
|
||||
Protocol Protocol `json:"proto"`
|
||||
Capture Capture `json:"capture"`
|
||||
Source *TCP `json:"src"`
|
||||
Destination *TCP `json:"dst"`
|
||||
Namespace string `json:"namespace"`
|
||||
Outgoing bool `json:"outgoing"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
StartTime time.Time `json:"startTime"`
|
||||
Request map[string]interface{} `json:"request"`
|
||||
Response map[string]interface{} `json:"response"`
|
||||
RequestSize int `json:"requestSize"`
|
||||
ResponseSize int `json:"responseSize"`
|
||||
ElapsedTime int64 `json:"elapsedTime"`
|
||||
Rules ApplicableRules `json:"rules,omitempty"`
|
||||
ContractStatus ContractStatus `json:"contractStatus,omitempty"`
|
||||
ContractRequestReason string `json:"contractRequestReason,omitempty"`
|
||||
ContractResponseReason string `json:"contractResponseReason,omitempty"`
|
||||
ContractContent string `json:"contractContent,omitempty"`
|
||||
HTTPPair string `json:"httpPair,omitempty"`
|
||||
Id string `json:"id"`
|
||||
Protocol Protocol `json:"proto"`
|
||||
Capture Capture `json:"capture"`
|
||||
Source *TCP `json:"src"`
|
||||
Destination *TCP `json:"dst"`
|
||||
Namespace string `json:"namespace"`
|
||||
Outgoing bool `json:"outgoing"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
StartTime time.Time `json:"startTime"`
|
||||
Request map[string]interface{} `json:"request"`
|
||||
Response map[string]interface{} `json:"response"`
|
||||
RequestSize int `json:"requestSize"`
|
||||
ResponseSize int `json:"responseSize"`
|
||||
ElapsedTime int64 `json:"elapsedTime"`
|
||||
Rules ApplicableRules `json:"rules,omitempty"`
|
||||
}
|
||||
|
||||
type EntryWrapper struct {
|
||||
@@ -193,22 +177,21 @@ type EntryWrapper struct {
|
||||
}
|
||||
|
||||
type BaseEntry struct {
|
||||
Id string `json:"id"`
|
||||
Protocol Protocol `json:"proto,omitempty"`
|
||||
Capture Capture `json:"capture"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
SummaryQuery string `json:"summaryQuery,omitempty"`
|
||||
Status int `json:"status"`
|
||||
StatusQuery string `json:"statusQuery"`
|
||||
Method string `json:"method,omitempty"`
|
||||
MethodQuery string `json:"methodQuery,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
Source *TCP `json:"src"`
|
||||
Destination *TCP `json:"dst"`
|
||||
IsOutgoing bool `json:"isOutgoing,omitempty"`
|
||||
Latency int64 `json:"latency"`
|
||||
Rules ApplicableRules `json:"rules,omitempty"`
|
||||
ContractStatus ContractStatus `json:"contractStatus"`
|
||||
Id string `json:"id"`
|
||||
Protocol Protocol `json:"proto,omitempty"`
|
||||
Capture Capture `json:"capture"`
|
||||
Summary string `json:"summary,omitempty"`
|
||||
SummaryQuery string `json:"summaryQuery,omitempty"`
|
||||
Status int `json:"status"`
|
||||
StatusQuery string `json:"statusQuery"`
|
||||
Method string `json:"method,omitempty"`
|
||||
MethodQuery string `json:"methodQuery,omitempty"`
|
||||
Timestamp int64 `json:"timestamp,omitempty"`
|
||||
Source *TCP `json:"src"`
|
||||
Destination *TCP `json:"dst"`
|
||||
IsOutgoing bool `json:"isOutgoing,omitempty"`
|
||||
Latency int64 `json:"latency"`
|
||||
Rules ApplicableRules `json:"rules,omitempty"`
|
||||
}
|
||||
|
||||
type ApplicableRules struct {
|
||||
@@ -217,15 +200,6 @@ type ApplicableRules struct {
|
||||
NumberOfRules int `json:"numberOfRules,omitempty"`
|
||||
}
|
||||
|
||||
type ContractStatus int
|
||||
|
||||
type Contract struct {
|
||||
Status ContractStatus `json:"status"`
|
||||
RequestReason string `json:"requestReason"`
|
||||
ResponseReason string `json:"responseReason"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
const (
|
||||
TABLE string = "table"
|
||||
BODY string = "body"
|
||||
@@ -246,170 +220,6 @@ type TableData struct {
|
||||
Selector string `json:"selector"`
|
||||
}
|
||||
|
||||
const (
|
||||
TypeHttpRequest = iota
|
||||
TypeHttpResponse
|
||||
)
|
||||
|
||||
type HTTPPayload struct {
|
||||
Type uint8
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type HTTPPayloader interface {
|
||||
MarshalJSON() ([]byte, error)
|
||||
}
|
||||
|
||||
type HTTPWrapper struct {
|
||||
Method string `json:"method"`
|
||||
Url string `json:"url"`
|
||||
Details interface{} `json:"details"`
|
||||
RawRequest *HTTPRequestWrapper `json:"rawRequest"`
|
||||
RawResponse *HTTPResponseWrapper `json:"rawResponse"`
|
||||
}
|
||||
|
||||
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||
_, testEnvEnabled := os.LookupEnv(mizuTestEnvVar)
|
||||
switch h.Type {
|
||||
case TypeHttpRequest:
|
||||
harRequest, err := har.NewRequest(h.Data.(*http.Request), true)
|
||||
if err != nil {
|
||||
return nil, errors.New("Failed converting request to HAR")
|
||||
}
|
||||
sort.Slice(harRequest.Headers, func(i, j int) bool {
|
||||
if harRequest.Headers[i].Name < harRequest.Headers[j].Name {
|
||||
return true
|
||||
}
|
||||
if harRequest.Headers[i].Name > harRequest.Headers[j].Name {
|
||||
return false
|
||||
}
|
||||
return harRequest.Headers[i].Value < harRequest.Headers[j].Value
|
||||
})
|
||||
sort.Slice(harRequest.QueryString, func(i, j int) bool {
|
||||
if harRequest.QueryString[i].Name < harRequest.QueryString[j].Name {
|
||||
return true
|
||||
}
|
||||
if harRequest.QueryString[i].Name > harRequest.QueryString[j].Name {
|
||||
return false
|
||||
}
|
||||
return harRequest.QueryString[i].Value < harRequest.QueryString[j].Value
|
||||
})
|
||||
if harRequest.PostData != nil {
|
||||
sort.Slice(harRequest.PostData.Params, func(i, j int) bool {
|
||||
if harRequest.PostData.Params[i].Name < harRequest.PostData.Params[j].Name {
|
||||
return true
|
||||
}
|
||||
if harRequest.PostData.Params[i].Name > harRequest.PostData.Params[j].Name {
|
||||
return false
|
||||
}
|
||||
return harRequest.PostData.Params[i].Value < harRequest.PostData.Params[j].Value
|
||||
})
|
||||
}
|
||||
if testEnvEnabled {
|
||||
harRequest.URL = ""
|
||||
}
|
||||
var reqWrapper *HTTPRequestWrapper
|
||||
if !testEnvEnabled {
|
||||
reqWrapper = &HTTPRequestWrapper{Request: h.Data.(*http.Request)}
|
||||
}
|
||||
return json.Marshal(&HTTPWrapper{
|
||||
Method: harRequest.Method,
|
||||
Details: harRequest,
|
||||
RawRequest: reqWrapper,
|
||||
})
|
||||
case TypeHttpResponse:
|
||||
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
||||
if err != nil {
|
||||
return nil, errors.New("Failed converting response to HAR")
|
||||
}
|
||||
sort.Slice(harResponse.Headers, func(i, j int) bool {
|
||||
if harResponse.Headers[i].Name < harResponse.Headers[j].Name {
|
||||
return true
|
||||
}
|
||||
if harResponse.Headers[i].Name > harResponse.Headers[j].Name {
|
||||
return false
|
||||
}
|
||||
return harResponse.Headers[i].Value < harResponse.Headers[j].Value
|
||||
})
|
||||
sort.Slice(harResponse.Cookies, func(i, j int) bool {
|
||||
if harResponse.Cookies[i].Name < harResponse.Cookies[j].Name {
|
||||
return true
|
||||
}
|
||||
if harResponse.Cookies[i].Name > harResponse.Cookies[j].Name {
|
||||
return false
|
||||
}
|
||||
return harResponse.Cookies[i].Value < harResponse.Cookies[j].Value
|
||||
})
|
||||
var resWrapper *HTTPResponseWrapper
|
||||
if !testEnvEnabled {
|
||||
resWrapper = &HTTPResponseWrapper{Response: h.Data.(*http.Response)}
|
||||
}
|
||||
return json.Marshal(&HTTPWrapper{
|
||||
Method: "",
|
||||
Url: "",
|
||||
Details: harResponse,
|
||||
RawResponse: resWrapper,
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("HTTP payload cannot be marshaled: %v", h.Type))
|
||||
}
|
||||
}
|
||||
|
||||
type HTTPWrapperTricky struct {
|
||||
Method string `json:"method"`
|
||||
Url string `json:"url"`
|
||||
Details interface{} `json:"details"`
|
||||
RawRequest *http.Request `json:"rawRequest"`
|
||||
RawResponse *http.Response `json:"rawResponse"`
|
||||
}
|
||||
|
||||
type HTTPMessage struct {
|
||||
IsRequest bool `json:"isRequest"`
|
||||
CaptureTime time.Time `json:"captureTime"`
|
||||
Payload HTTPWrapperTricky `json:"payload"`
|
||||
}
|
||||
|
||||
type HTTPRequestResponsePair struct {
|
||||
Request HTTPMessage `json:"request"`
|
||||
Response HTTPMessage `json:"response"`
|
||||
}
|
||||
|
||||
type HTTPRequestWrapper struct {
|
||||
*http.Request
|
||||
}
|
||||
|
||||
func (r *HTTPRequestWrapper) MarshalJSON() ([]byte, error) {
|
||||
body, _ := ioutil.ReadAll(r.Request.Body)
|
||||
r.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
||||
return json.Marshal(&struct { //nolint
|
||||
Body string `json:"Body,omitempty"`
|
||||
GetBody string `json:"GetBody,omitempty"`
|
||||
Cancel string `json:"Cancel,omitempty"`
|
||||
*http.Request
|
||||
}{
|
||||
Body: string(body),
|
||||
Request: r.Request,
|
||||
})
|
||||
}
|
||||
|
||||
type HTTPResponseWrapper struct {
|
||||
*http.Response
|
||||
}
|
||||
|
||||
func (r *HTTPResponseWrapper) MarshalJSON() ([]byte, error) {
|
||||
body, _ := ioutil.ReadAll(r.Response.Body)
|
||||
r.Response.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
||||
return json.Marshal(&struct { //nolint
|
||||
Body string `json:"Body,omitempty"`
|
||||
GetBody string `json:"GetBody,omitempty"`
|
||||
Cancel string `json:"Cancel,omitempty"`
|
||||
*http.Response
|
||||
}{
|
||||
Body: string(body),
|
||||
Response: r.Response,
|
||||
})
|
||||
}
|
||||
|
||||
type TcpReaderDataMsg interface {
|
||||
GetBytes() []byte
|
||||
GetTimestamp() time.Time
|
||||
|
@@ -2,9 +2,6 @@ module github.com/up9inc/mizu/tap/api
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/google/martian v2.1.0+incompatible
|
||||
github.com/up9inc/mizu/tap/dbgctl v0.0.0
|
||||
)
|
||||
require github.com/up9inc/mizu/tap/dbgctl v0.0.0
|
||||
|
||||
replace github.com/up9inc/mizu/tap/dbgctl v0.0.0 => ../dbgctl
|
||||
|
@@ -1,2 +0,0 @@
|
||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
|
@@ -13,4 +13,4 @@ test-pull-bin:
|
||||
|
||||
test-pull-expect:
|
||||
@mkdir -p expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect8/amqp/\* expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect11/amqp/\* expect
|
||||
|
@@ -9,7 +9,6 @@ require (
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/google/martian v2.1.0+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/up9inc/mizu/tap/dbgctl v0.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
|
@@ -1,7 +1,5 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@@ -276,22 +276,21 @@ func (d dissecting) Summarize(entry *api.Entry) *api.BaseEntry {
|
||||
}
|
||||
|
||||
return &api.BaseEntry{
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: 0,
|
||||
StatusQuery: "",
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
ContractStatus: entry.ContractStatus,
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: 0,
|
||||
StatusQuery: "",
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -13,4 +13,4 @@ test-pull-bin:
|
||||
|
||||
test-pull-expect:
|
||||
@mkdir -p expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect10/http/\* expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect12/http/\* expect
|
||||
|
@@ -4,6 +4,7 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/beevik/etree v1.1.0
|
||||
github.com/google/martian v2.1.0+incompatible
|
||||
github.com/mertyildiran/gqlparser/v2 v2.4.6
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/up9inc/mizu/tap/api v0.0.0
|
||||
@@ -12,7 +13,6 @@ require (
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/google/martian v2.1.0+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/up9inc/mizu/tap/dbgctl v0.0.0 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
|
@@ -32,7 +32,7 @@ func replaceForwardedFor(item *api.OutputChannelItem) {
|
||||
return
|
||||
}
|
||||
|
||||
request := item.Pair.Request.Payload.(api.HTTPPayload).Data.(*http.Request)
|
||||
request := item.Pair.Request.Payload.(HTTPPayload).Data.(*http.Request)
|
||||
|
||||
forwardedFor := request.Header.Get("X-Forwarded-For")
|
||||
if forwardedFor == "" {
|
||||
|
@@ -279,7 +279,7 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, resolvedSource string,
|
||||
if elapsedTime < 0 {
|
||||
elapsedTime = 0
|
||||
}
|
||||
httpPair, _ := json.Marshal(item.Pair)
|
||||
|
||||
return &api.Entry{
|
||||
Protocol: item.Protocol,
|
||||
Capture: item.Capture,
|
||||
@@ -302,7 +302,6 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, resolvedSource string,
|
||||
Timestamp: item.Timestamp,
|
||||
StartTime: item.Pair.Request.CaptureTime,
|
||||
ElapsedTime: elapsedTime,
|
||||
HTTPPair: string(httpPair),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,22 +314,21 @@ func (d dissecting) Summarize(entry *api.Entry) *api.BaseEntry {
|
||||
statusQuery := fmt.Sprintf(`response.status == %d`, status)
|
||||
|
||||
return &api.BaseEntry{
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: status,
|
||||
StatusQuery: statusQuery,
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
ContractStatus: entry.ContractStatus,
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: status,
|
||||
StatusQuery: statusQuery,
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -29,7 +29,7 @@ func (matcher *requestResponseMatcher) registerRequest(ident string, request *ht
|
||||
IsRequest: true,
|
||||
CaptureTime: captureTime,
|
||||
CaptureSize: captureSize,
|
||||
Payload: api.HTTPPayload{
|
||||
Payload: HTTPPayload{
|
||||
Type: TypeHttpRequest,
|
||||
Data: request,
|
||||
},
|
||||
@@ -53,7 +53,7 @@ func (matcher *requestResponseMatcher) registerResponse(ident string, response *
|
||||
IsRequest: false,
|
||||
CaptureTime: captureTime,
|
||||
CaptureSize: captureSize,
|
||||
Payload: api.HTTPPayload{
|
||||
Payload: HTTPPayload{
|
||||
Type: TypeHttpResponse,
|
||||
Data: response,
|
||||
},
|
||||
|
@@ -30,7 +30,7 @@ func IsIgnoredUserAgent(item *api.OutputChannelItem, options *api.TrafficFilteri
|
||||
return false
|
||||
}
|
||||
|
||||
request := item.Pair.Request.Payload.(api.HTTPPayload).Data.(*http.Request)
|
||||
request := item.Pair.Request.Payload.(HTTPPayload).Data.(*http.Request)
|
||||
|
||||
for headerKey, headerValues := range request.Header {
|
||||
if strings.ToLower(headerKey) == userAgent {
|
||||
@@ -50,8 +50,8 @@ func IsIgnoredUserAgent(item *api.OutputChannelItem, options *api.TrafficFilteri
|
||||
}
|
||||
|
||||
func FilterSensitiveData(item *api.OutputChannelItem, options *api.TrafficFilteringOptions) {
|
||||
request := item.Pair.Request.Payload.(api.HTTPPayload).Data.(*http.Request)
|
||||
response := item.Pair.Response.Payload.(api.HTTPPayload).Data.(*http.Response)
|
||||
request := item.Pair.Request.Payload.(HTTPPayload).Data.(*http.Request)
|
||||
response := item.Pair.Response.Payload.(HTTPPayload).Data.(*http.Response)
|
||||
|
||||
filterHeaders(&request.Header)
|
||||
filterHeaders(&response.Header)
|
||||
|
100
tap/extensions/http/structs.go
Normal file
100
tap/extensions/http/structs.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/google/martian/har"
|
||||
)
|
||||
|
||||
type HTTPPayload struct {
|
||||
Type uint8
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type HTTPPayloader interface {
|
||||
MarshalJSON() ([]byte, error)
|
||||
}
|
||||
|
||||
type HTTPWrapper struct {
|
||||
Method string `json:"method"`
|
||||
Url string `json:"url"`
|
||||
Details interface{} `json:"details"`
|
||||
}
|
||||
|
||||
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||
switch h.Type {
|
||||
case TypeHttpRequest:
|
||||
harRequest, err := har.NewRequest(h.Data.(*http.Request), true)
|
||||
if err != nil {
|
||||
return nil, errors.New("Failed converting request to HAR")
|
||||
}
|
||||
sort.Slice(harRequest.Headers, func(i, j int) bool {
|
||||
if harRequest.Headers[i].Name < harRequest.Headers[j].Name {
|
||||
return true
|
||||
}
|
||||
if harRequest.Headers[i].Name > harRequest.Headers[j].Name {
|
||||
return false
|
||||
}
|
||||
return harRequest.Headers[i].Value < harRequest.Headers[j].Value
|
||||
})
|
||||
sort.Slice(harRequest.QueryString, func(i, j int) bool {
|
||||
if harRequest.QueryString[i].Name < harRequest.QueryString[j].Name {
|
||||
return true
|
||||
}
|
||||
if harRequest.QueryString[i].Name > harRequest.QueryString[j].Name {
|
||||
return false
|
||||
}
|
||||
return harRequest.QueryString[i].Value < harRequest.QueryString[j].Value
|
||||
})
|
||||
if harRequest.PostData != nil {
|
||||
sort.Slice(harRequest.PostData.Params, func(i, j int) bool {
|
||||
if harRequest.PostData.Params[i].Name < harRequest.PostData.Params[j].Name {
|
||||
return true
|
||||
}
|
||||
if harRequest.PostData.Params[i].Name > harRequest.PostData.Params[j].Name {
|
||||
return false
|
||||
}
|
||||
return harRequest.PostData.Params[i].Value < harRequest.PostData.Params[j].Value
|
||||
})
|
||||
}
|
||||
return json.Marshal(&HTTPWrapper{
|
||||
Method: harRequest.Method,
|
||||
Url: "",
|
||||
Details: harRequest,
|
||||
})
|
||||
case TypeHttpResponse:
|
||||
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
||||
if err != nil {
|
||||
return nil, errors.New("Failed converting response to HAR")
|
||||
}
|
||||
sort.Slice(harResponse.Headers, func(i, j int) bool {
|
||||
if harResponse.Headers[i].Name < harResponse.Headers[j].Name {
|
||||
return true
|
||||
}
|
||||
if harResponse.Headers[i].Name > harResponse.Headers[j].Name {
|
||||
return false
|
||||
}
|
||||
return harResponse.Headers[i].Value < harResponse.Headers[j].Value
|
||||
})
|
||||
sort.Slice(harResponse.Cookies, func(i, j int) bool {
|
||||
if harResponse.Cookies[i].Name < harResponse.Cookies[j].Name {
|
||||
return true
|
||||
}
|
||||
if harResponse.Cookies[i].Name > harResponse.Cookies[j].Name {
|
||||
return false
|
||||
}
|
||||
return harResponse.Cookies[i].Value < harResponse.Cookies[j].Value
|
||||
})
|
||||
return json.Marshal(&HTTPWrapper{
|
||||
Method: "",
|
||||
Url: "",
|
||||
Details: harResponse,
|
||||
})
|
||||
default:
|
||||
panic(fmt.Sprintf("HTTP payload cannot be marshaled: %v", h.Type))
|
||||
}
|
||||
}
|
@@ -13,4 +13,4 @@ test-pull-bin:
|
||||
|
||||
test-pull-expect:
|
||||
@mkdir -p expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect9/kafka/\* expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect11/kafka/\* expect
|
||||
|
@@ -14,7 +14,6 @@ require (
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/martian v2.1.0+incompatible // indirect
|
||||
github.com/klauspost/compress v1.14.2 // indirect
|
||||
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
|
@@ -11,8 +11,6 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/klauspost/compress v1.9.8/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/compress v1.14.2 h1:S0OHlFk/Gbon/yauFJ4FfJJF5V0fc5HbBTJazi28pRw=
|
||||
github.com/klauspost/compress v1.14.2/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
|
@@ -186,22 +186,21 @@ func (d dissecting) Summarize(entry *api.Entry) *api.BaseEntry {
|
||||
}
|
||||
|
||||
return &api.BaseEntry{
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: status,
|
||||
StatusQuery: statusQuery,
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
ContractStatus: entry.ContractStatus,
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: status,
|
||||
StatusQuery: statusQuery,
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -13,4 +13,4 @@ test-pull-bin:
|
||||
|
||||
test-pull-expect:
|
||||
@mkdir -p expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect8/redis/\* expect
|
||||
@[ "${skipexpect}" ] && echo "Skipping downloading expected JSONs" || gsutil -o 'GSUtil:parallel_process_count=5' -o 'GSUtil:parallel_thread_count=5' -m cp -r gs://static.up9.io/mizu/test-pcap/expect11/redis/\* expect
|
||||
|
@@ -9,7 +9,6 @@ require (
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/google/martian v2.1.0+incompatible // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/up9inc/mizu/tap/dbgctl v0.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
|
@@ -1,7 +1,5 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@@ -114,22 +114,21 @@ func (d dissecting) Summarize(entry *api.Entry) *api.BaseEntry {
|
||||
}
|
||||
|
||||
return &api.BaseEntry{
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: status,
|
||||
StatusQuery: statusQuery,
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
ContractStatus: entry.ContractStatus,
|
||||
Id: entry.Id,
|
||||
Protocol: entry.Protocol,
|
||||
Capture: entry.Capture,
|
||||
Summary: summary,
|
||||
SummaryQuery: summaryQuery,
|
||||
Status: status,
|
||||
StatusQuery: statusQuery,
|
||||
Method: method,
|
||||
MethodQuery: methodQuery,
|
||||
Timestamp: entry.Timestamp,
|
||||
Source: entry.Source,
|
||||
Destination: entry.Destination,
|
||||
IsOutgoing: entry.Outgoing,
|
||||
Latency: entry.ElapsedTime,
|
||||
Rules: entry.Rules,
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,6 @@ require (
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/google/go-cmp v0.5.7 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/martian v2.1.0+incompatible // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
|
@@ -68,8 +68,6 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
|
||||
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
|
||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU=
|
||||
github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
|
||||
|
Reference in New Issue
Block a user