mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-06-22 22:39:40 +00:00
Policy rules remove redundant function (#193)
This commit is contained in:
parent
8c9b8d3217
commit
c4afeee5b3
@ -54,17 +54,9 @@ type BaseEntryDetails struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApplicableRules struct {
|
type ApplicableRules struct {
|
||||||
Latency int64 `json:"latency,omitempty"`
|
Latency int64 `json:"latency,omitempty"`
|
||||||
Status bool `json:"status,omitempty"`
|
Status bool `json:"status,omitempty"`
|
||||||
NumberOfRules int `json:"numberOfRules,omitempty"`
|
NumberOfRules int `json:"numberOfRules,omitempty"`
|
||||||
}
|
|
||||||
|
|
||||||
func NewApplicableRules(status bool, latency int64, number int) ApplicableRules {
|
|
||||||
ar := ApplicableRules{}
|
|
||||||
ar.Status = status
|
|
||||||
ar.Latency = latency
|
|
||||||
ar.NumberOfRules = number
|
|
||||||
return ar
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FullEntryDetails struct {
|
type FullEntryDetails struct {
|
||||||
@ -219,8 +211,6 @@ func (fewp *FullEntryWithPolicy) UnmarshalData(entry *MizuEntry) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RunValidationRulesState(harEntry har.Entry, service string) ApplicableRules {
|
func RunValidationRulesState(harEntry har.Entry, service string) ApplicableRules {
|
||||||
numberOfRules, resultPolicyToSend := rules.MatchRequestPolicy(harEntry, service)
|
_, resultPolicyToSend := rules.MatchRequestPolicy(harEntry, service)
|
||||||
statusPolicyToSend, latency, numberOfRules := rules.PassedValidationRules(resultPolicyToSend, numberOfRules)
|
return rules.PassedValidationRules(resultPolicyToSend)
|
||||||
ar := NewApplicableRules(statusPolicyToSend, latency, numberOfRules)
|
|
||||||
return ar
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package rules
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"mizuserver/pkg/models"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -92,19 +93,35 @@ func MatchRequestPolicy(harEntry har.Entry, service string) (int, []RulesMatched
|
|||||||
return len(enforcePolicy.Rules), resultPolicyToSend
|
return len(enforcePolicy.Rules), resultPolicyToSend
|
||||||
}
|
}
|
||||||
|
|
||||||
func PassedValidationRules(rulesMatched []RulesMatched, numberOfRules int) (bool, int64, int) {
|
func PassedValidationRules(rulesMatched []RulesMatched) models.ApplicableRules {
|
||||||
if len(rulesMatched) == 0 {
|
if len(rulesMatched) == 0 {
|
||||||
return false, 0, 0
|
return models.ApplicableRules{
|
||||||
|
Status: false,
|
||||||
|
Latency: 0,
|
||||||
|
NumberOfRules: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, rule := range rulesMatched {
|
for _, rule := range rulesMatched {
|
||||||
if rule.Matched == false {
|
if rule.Matched == false {
|
||||||
return false, -1, len(rulesMatched)
|
return models.ApplicableRules{
|
||||||
|
Status: false,
|
||||||
|
Latency: -1,
|
||||||
|
NumberOfRules: len(rulesMatched),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, rule := range rulesMatched {
|
for _, rule := range rulesMatched {
|
||||||
if strings.ToLower(rule.Rule.Type) == "latency" {
|
if strings.ToLower(rule.Rule.Type) == "latency" {
|
||||||
return true, rule.Rule.Latency, len(rulesMatched)
|
return models.ApplicableRules{
|
||||||
|
Status: true,
|
||||||
|
Latency: rule.Rule.Latency,
|
||||||
|
NumberOfRules: len(rulesMatched),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true, -1, len(rulesMatched)
|
return models.ApplicableRules{
|
||||||
|
Status: true,
|
||||||
|
Latency: -1,
|
||||||
|
NumberOfRules: len(rulesMatched),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user