diff --git a/agent/pkg/api/main.go b/agent/pkg/api/main.go index 02525fabd..7163877fb 100644 --- a/agent/pkg/api/main.go +++ b/agent/pkg/api/main.go @@ -113,7 +113,7 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension json.Unmarshal([]byte(mizuEntry.Entry), &pair) harEntry, err := utils.NewEntry(&pair) if err == nil { - rules, _ := models.RunValidationRulesState(*harEntry, mizuEntry.Service) + rules, _, _ := models.RunValidationRulesState(*harEntry, mizuEntry.Service) baseEntry.Rules = rules } } diff --git a/agent/pkg/controllers/entries_controller.go b/agent/pkg/controllers/entries_controller.go index 035d99fb6..4737884ff 100644 --- a/agent/pkg/controllers/entries_controller.go +++ b/agent/pkg/controllers/entries_controller.go @@ -143,11 +143,13 @@ func GetEntry(c *gin.Context) { protocol, representation, bodySize, _ := extension.Dissector.Represent(&entryData) var rules []map[string]interface{} + var isRulesEnabled bool if entryData.ProtocolName == "http" { var pair tapApi.RequestResponsePair json.Unmarshal([]byte(entryData.Entry), &pair) harEntry, _ := utils.NewEntry(&pair) - _, rulesMatched := models.RunValidationRulesState(*harEntry, entryData.Service) + _, rulesMatched, _isRulesEnabled := models.RunValidationRulesState(*harEntry, entryData.Service) + isRulesEnabled = _isRulesEnabled inrec, _ := json.Marshal(rulesMatched) json.Unmarshal(inrec, &rules) } @@ -158,6 +160,7 @@ func GetEntry(c *gin.Context) { BodySize: bodySize, Data: entryData, Rules: rules, + IsRulesEnabled: isRulesEnabled, }) } diff --git a/agent/pkg/models/models.go b/agent/pkg/models/models.go index fa733b6cb..3356dc75a 100644 --- a/agent/pkg/models/models.go +++ b/agent/pkg/models/models.go @@ -97,8 +97,8 @@ type ExtendedCreator struct { Source *string `json:"_source"` } -func RunValidationRulesState(harEntry har.Entry, service string) (tapApi.ApplicableRules, []rules.RulesMatched) { - resultPolicyToSend := rules.MatchRequestPolicy(harEntry, service) +func RunValidationRulesState(harEntry har.Entry, service string) (tapApi.ApplicableRules, []rules.RulesMatched, bool) { + resultPolicyToSend, isEnabled := rules.MatchRequestPolicy(harEntry, service) statusPolicyToSend, latency, numberOfRules := rules.PassedValidationRules(resultPolicyToSend) - return tapApi.ApplicableRules{Status: statusPolicyToSend, Latency: latency, NumberOfRules: numberOfRules}, resultPolicyToSend + return tapApi.ApplicableRules{Status: statusPolicyToSend, Latency: latency, NumberOfRules: numberOfRules}, resultPolicyToSend, isEnabled } diff --git a/agent/pkg/rules/rulesHTTP.go b/agent/pkg/rules/rulesHTTP.go index e4dc927b4..855768344 100644 --- a/agent/pkg/rules/rulesHTTP.go +++ b/agent/pkg/rules/rulesHTTP.go @@ -4,11 +4,12 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/romana/rlog" "reflect" "regexp" "strings" + "github.com/romana/rlog" + "github.com/google/martian/har" "github.com/up9inc/mizu/shared" jsonpath "github.com/yalp/jsonpath" @@ -43,9 +44,11 @@ func ValidateService(serviceFromRule string, service string) bool { return true } -func MatchRequestPolicy(harEntry har.Entry, service string) []RulesMatched { - enforcePolicy, _ := shared.DecodeEnforcePolicy(fmt.Sprintf("%s/%s", shared.RulePolicyPath, shared.RulePolicyFileName)) - var resultPolicyToSend []RulesMatched +func MatchRequestPolicy(harEntry har.Entry, service string) (resultPolicyToSend []RulesMatched, isEnabled bool) { + enforcePolicy, err := shared.DecodeEnforcePolicy(fmt.Sprintf("%s/%s", shared.RulePolicyPath, shared.RulePolicyFileName)) + if err == nil { + isEnabled = true + } for _, rule := range enforcePolicy.Rules { if !ValidatePath(rule.Path, harEntry.Request.URL) || !ValidateService(rule.Service, service) { continue @@ -93,7 +96,7 @@ func MatchRequestPolicy(harEntry har.Entry, service string) []RulesMatched { resultPolicyToSend = appendRulesMatched(resultPolicyToSend, true, rule) } } - return resultPolicyToSend + return } func PassedValidationRules(rulesMatched []RulesMatched) (bool, int64, int) { diff --git a/cli/kubernetes/provider.go b/cli/kubernetes/provider.go index bc0463791..5f361fe73 100644 --- a/cli/kubernetes/provider.go +++ b/cli/kubernetes/provider.go @@ -447,7 +447,7 @@ func (provider *Provider) RemoveDaemonSet(ctx context.Context, namespace string, func (provider *Provider) handleRemovalError(err error) error { // Ignore NotFound - There is nothing to delete. // Ignore Forbidden - Assume that a user could not have created the resource in the first place. - if k8serrors.IsNotFound(err) || k8serrors.IsForbidden(err){ + if k8serrors.IsNotFound(err) || k8serrors.IsForbidden(err) { return nil } diff --git a/tap/api/api.go b/tap/api/api.go index d65511012..da629ad07 100644 --- a/tap/api/api.go +++ b/tap/api/api.go @@ -138,6 +138,7 @@ type MizuEntryWrapper struct { BodySize int64 `json:"bodySize"` Data MizuEntry `json:"data"` Rules []map[string]interface{} `json:"rulesMatched,omitempty"` + IsRulesEnabled bool `json:"isRulesEnabled"` } type BaseEntryDetails struct { diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 003fbc8fe..3783e061f 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -91,7 +91,7 @@ const App = () => { - + return (