snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
132
server/pkg/actionlog/policy.go
Normal file
132
server/pkg/actionlog/policy.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package actionlog
|
||||
|
||||
import "github.com/cortezaproject/corteza/server/pkg/slice"
|
||||
|
||||
type (
|
||||
policyMatcher interface {
|
||||
Match(*Action) bool
|
||||
}
|
||||
|
||||
logPolicyAny struct {
|
||||
mm []policyMatcher
|
||||
}
|
||||
|
||||
logPolicyAll struct {
|
||||
mm []policyMatcher
|
||||
}
|
||||
|
||||
logPolicyNegate struct {
|
||||
m policyMatcher
|
||||
}
|
||||
|
||||
logPolicyMatchRequestOrigin struct {
|
||||
origin map[string]bool
|
||||
}
|
||||
|
||||
logPolicyMatchResource struct {
|
||||
resources map[string]bool
|
||||
}
|
||||
|
||||
logPolicyMatchAction struct {
|
||||
actions map[string]bool
|
||||
}
|
||||
|
||||
logPolicyMatchSeverity struct {
|
||||
severities map[Severity]bool
|
||||
}
|
||||
|
||||
logPolicyNoop struct {
|
||||
v bool
|
||||
}
|
||||
)
|
||||
|
||||
// NewPolicyNone ignores all action logs
|
||||
func NewPolicyNone() policyMatcher {
|
||||
return &logPolicyNoop{v: false}
|
||||
}
|
||||
|
||||
// NewPolicyAny returns policy where at least one of the sub-policies should match
|
||||
func NewPolicyAny(mm ...policyMatcher) policyMatcher {
|
||||
return &logPolicyAny{mm: mm}
|
||||
}
|
||||
|
||||
func (p logPolicyAny) Match(a *Action) bool {
|
||||
for _, m := range p.mm {
|
||||
if m.Match(a) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// NewPolicyAll returns policy where all sub-policies should match
|
||||
func NewPolicyAll(mm ...policyMatcher) policyMatcher {
|
||||
return &logPolicyAll{mm: mm}
|
||||
}
|
||||
|
||||
func (p logPolicyAll) Match(a *Action) bool {
|
||||
for _, m := range p.mm {
|
||||
if !m.Match(a) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// NewPolicyNegate negates passed policy
|
||||
func NewPolicyNegate(m policyMatcher) policyMatcher {
|
||||
return &logPolicyNegate{m: m}
|
||||
}
|
||||
|
||||
func (p logPolicyNegate) Match(a *Action) bool {
|
||||
return !p.m.Match(a)
|
||||
}
|
||||
|
||||
// NewPolicyMatchResource matches resources
|
||||
func NewPolicyMatchResource(rr ...string) policyMatcher {
|
||||
return &logPolicyMatchResource{resources: slice.ToStringBoolMap(rr)}
|
||||
}
|
||||
|
||||
func (p logPolicyMatchResource) Match(a *Action) bool {
|
||||
return p.resources[a.Resource]
|
||||
}
|
||||
|
||||
// NewPolicyMatchAction matches action
|
||||
func NewPolicyMatchAction(aa ...string) policyMatcher {
|
||||
return &logPolicyMatchAction{actions: slice.ToStringBoolMap(aa)}
|
||||
}
|
||||
|
||||
func (p logPolicyMatchAction) Match(a *Action) bool {
|
||||
return p.actions[a.Action]
|
||||
}
|
||||
|
||||
// NewPolicyMatchSeverity matches severity
|
||||
func NewPolicyMatchSeverity(ss ...Severity) policyMatcher {
|
||||
var p = &logPolicyMatchSeverity{severities: make(map[Severity]bool)}
|
||||
|
||||
for _, s := range ss {
|
||||
p.severities[s] = true
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p logPolicyMatchSeverity) Match(a *Action) bool {
|
||||
return p.severities[a.Severity]
|
||||
}
|
||||
|
||||
// NewPolicyMatchRequestOrigin matches resources
|
||||
func NewPolicyMatchRequestOrigin(rr ...string) policyMatcher {
|
||||
return &logPolicyMatchRequestOrigin{origin: slice.ToStringBoolMap(rr)}
|
||||
}
|
||||
|
||||
func (p logPolicyMatchRequestOrigin) Match(a *Action) bool {
|
||||
return p.origin[a.RequestOrigin]
|
||||
}
|
||||
|
||||
// Match Internal policy
|
||||
func (p logPolicyNoop) Match(*Action) bool {
|
||||
return p.v
|
||||
}
|
||||
Reference in New Issue
Block a user