mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-07 07:30:12 +00:00
* Fix rules * Not reay, error on running * Empty dissector Rules() * almost working * Finally, fixed * undo changes on agent/pkg/utils/har.go * fix not showing service on rules detail * Update tap/api/api.go Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com> * Update agent/pkg/controllers/entries_controller.go Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com> * Update agent/pkg/controllers/entries_controller.go Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com> * unwrap Data * Fix bug off using more than one latency rule that always get the first. * fix json type, decoding base64 before unmarshal * Run `go mod tidy` on `cli/go.sum` * Fix the linting issues * Remove a `FIXME` comment * Remove a CSS rule * Adapt `ruleNumberText` CSS class to the design language of the UI * Fix an issue in the UI related to `rule.Latency` slipping out * Removed unecessary codes. Co-authored-by: gadotroee <55343099+gadotroee@users.noreply.github.com> Co-authored-by: M. Mert Yildiran <mehmet@up9.com>
105 lines
2.9 KiB
Go
105 lines
2.9 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
tapApi "github.com/up9inc/mizu/tap/api"
|
|
|
|
"mizuserver/pkg/rules"
|
|
|
|
"github.com/google/martian/har"
|
|
"github.com/up9inc/mizu/shared"
|
|
"github.com/up9inc/mizu/tap"
|
|
)
|
|
|
|
func GetEntry(r *tapApi.MizuEntry, v tapApi.DataUnmarshaler) error {
|
|
return v.UnmarshalData(r)
|
|
}
|
|
|
|
type EntriesFilter struct {
|
|
Limit int `form:"limit" validate:"required,min=1,max=200"`
|
|
Operator string `form:"operator" validate:"required,oneof='lt' 'gt'"`
|
|
Timestamp int64 `form:"timestamp" validate:"required,min=1"`
|
|
}
|
|
|
|
type UploadEntriesRequestQuery struct {
|
|
Dest string `form:"dest"`
|
|
SleepIntervalSec int `form:"interval"`
|
|
}
|
|
|
|
type HarFetchRequestQuery struct {
|
|
From int64 `form:"from"`
|
|
To int64 `form:"to"`
|
|
}
|
|
|
|
type WebSocketEntryMessage struct {
|
|
*shared.WebSocketMessageMetadata
|
|
Data *tapApi.BaseEntryDetails `json:"data,omitempty"`
|
|
}
|
|
|
|
type WebSocketTappedEntryMessage struct {
|
|
*shared.WebSocketMessageMetadata
|
|
Data *tapApi.OutputChannelItem
|
|
}
|
|
|
|
type WebsocketOutboundLinkMessage struct {
|
|
*shared.WebSocketMessageMetadata
|
|
Data *tap.OutboundLink
|
|
}
|
|
|
|
func CreateBaseEntryWebSocketMessage(base *tapApi.BaseEntryDetails) ([]byte, error) {
|
|
message := &WebSocketEntryMessage{
|
|
WebSocketMessageMetadata: &shared.WebSocketMessageMetadata{
|
|
MessageType: shared.WebSocketMessageTypeEntry,
|
|
},
|
|
Data: base,
|
|
}
|
|
return json.Marshal(message)
|
|
}
|
|
|
|
func CreateWebsocketTappedEntryMessage(base *tapApi.OutputChannelItem) ([]byte, error) {
|
|
message := &WebSocketTappedEntryMessage{
|
|
WebSocketMessageMetadata: &shared.WebSocketMessageMetadata{
|
|
MessageType: shared.WebSocketMessageTypeTappedEntry,
|
|
},
|
|
Data: base,
|
|
}
|
|
return json.Marshal(message)
|
|
}
|
|
|
|
func CreateWebsocketOutboundLinkMessage(base *tap.OutboundLink) ([]byte, error) {
|
|
message := &WebsocketOutboundLinkMessage{
|
|
WebSocketMessageMetadata: &shared.WebSocketMessageMetadata{
|
|
MessageType: shared.WebsocketMessageTypeOutboundLink,
|
|
},
|
|
Data: base,
|
|
}
|
|
return json.Marshal(message)
|
|
}
|
|
|
|
// ExtendedHAR is the top level object of a HAR log.
|
|
type ExtendedHAR struct {
|
|
Log *ExtendedLog `json:"log"`
|
|
}
|
|
|
|
// ExtendedLog is the HAR HTTP request and response log.
|
|
type ExtendedLog struct {
|
|
// Version number of the HAR format.
|
|
Version string `json:"version"`
|
|
// Creator holds information about the log creator application.
|
|
Creator *ExtendedCreator `json:"creator"`
|
|
// Entries is a list containing requests and responses.
|
|
Entries []*har.Entry `json:"entries"`
|
|
}
|
|
|
|
type ExtendedCreator struct {
|
|
*har.Creator
|
|
Source *string `json:"_source"`
|
|
}
|
|
|
|
func RunValidationRulesState(harEntry har.Entry, service string) (tapApi.ApplicableRules, []rules.RulesMatched) {
|
|
resultPolicyToSend := rules.MatchRequestPolicy(harEntry, service)
|
|
statusPolicyToSend, latency, numberOfRules := rules.PassedValidationRules(resultPolicyToSend)
|
|
return tapApi.ApplicableRules{Status: statusPolicyToSend, Latency: latency, NumberOfRules: numberOfRules}, resultPolicyToSend
|
|
}
|