firewall: update ActionsReadDB to get group actions

This commit is contained in:
Elle Mouton 2023-06-19 15:51:06 +02:00
parent c12e643a43
commit 921874608c
No known key found for this signature in database
GPG key ID: D7D916376026F177
2 changed files with 38 additions and 38 deletions

View file

@ -363,11 +363,11 @@ func (r *RuleEnforcer) initRule(reqID uint64, name string, value []byte,
}
allActionsDB := r.actionsDB.GetActionsReadDB(sessionID, featureName)
actionsDB := allActionsDB.FeatureActionsDB()
actionsDB := allActionsDB.GroupFeatureActionsDB()
rulesDB := r.ruleDB.GetKVStores(name, sessionID, featureName)
if sessionRule {
actionsDB = allActionsDB.SessionActionsDB()
actionsDB = allActionsDB.GroupActionsDB()
rulesDB = r.ruleDB.GetKVStores(name, sessionID, "")
}

View file

@ -575,26 +575,26 @@ type ActionsDB interface {
ListActions(ctx context.Context) ([]*RuleAction, error)
}
// ActionsReadDB is an abstraction gives a caller access to either a session
// specific or feature specific rules.ActionDB
// ActionsReadDB is an abstraction gives a caller access to either a group
// specific or group and feature specific rules.ActionDB.
type ActionsReadDB interface {
SessionActionsDB() ActionsDB
FeatureActionsDB() ActionsDB
GroupActionsDB() ActionsDB
GroupFeatureActionsDB() ActionsDB
}
// ActionReadDBGetter represents a function that can be used to construct
// an ActionsReadDB.
type ActionReadDBGetter interface {
GetActionsReadDB(sessionID session.ID, featureName string) ActionsReadDB
GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
}
// GetActionsReadDB is a method on DB that constructs an ActionsReadDB.
func (db *DB) GetActionsReadDB(sessionID session.ID,
func (db *DB) GetActionsReadDB(groupID session.ID,
featureName string) ActionsReadDB {
return &allActionsReadDB{
db: db,
sessionID: sessionID,
groupID: groupID,
featureName: featureName,
}
}
@ -602,40 +602,40 @@ func (db *DB) GetActionsReadDB(sessionID session.ID,
// allActionsReadDb is an implementation of the ActionsReadDB.
type allActionsReadDB struct {
db *DB
sessionID session.ID
groupID session.ID
featureName string
}
var _ ActionsReadDB = (*allActionsReadDB)(nil)
// SessionActionsDB returns a rules.ActionsDB that will give the caller access
// to all of a sessions Actions.
func (a *allActionsReadDB) SessionActionsDB() ActionsDB {
return &sessionActionsReadDB{a}
// GroupActionsDB returns a rules.ActionsDB that will give the caller access
// to all of a groups Actions.
func (a *allActionsReadDB) GroupActionsDB() ActionsDB {
return &groupActionsReadDB{a}
}
// FeatureActionsDB returns an rules.ActionsDB that will give the caller access
// to only a specific features Actions in a specific session.
func (a *allActionsReadDB) FeatureActionsDB() ActionsDB {
return &featureActionsReadDB{a}
// GroupFeatureActionsDB returns a rules.ActionsDB that will give the caller
// access to only a specific features Actions in a specific group.
func (a *allActionsReadDB) GroupFeatureActionsDB() ActionsDB {
return &groupFeatureActionsReadDB{a}
}
// sessionActionReadDB is an implementation of the rules.ActionsDB that will
// provide read access to all the Actions of a particular session.
type sessionActionsReadDB struct {
// groupActionsReadDB is an implementation of the rules.ActionsDB that will
// provide read access to all the Actions of a particular group.
type groupActionsReadDB struct {
*allActionsReadDB
}
var _ ActionsDB = (*sessionActionsReadDB)(nil)
var _ ActionsDB = (*groupActionsReadDB)(nil)
// ListActions will return all the Actions for a particular session.
func (s *sessionActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
// ListActions will return all the Actions for a particular group.
func (s *groupActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
error) {
sessionActions, _, _, err := s.db.ListSessionActions(
s.sessionID, func(a *Action, _ bool) (bool, bool) {
sessionActions, err := s.db.ListGroupActions(
s.groupID, func(a *Action, _ bool) (bool, bool) {
return a.State == ActionStateDone, true
}, nil,
},
)
if err != nil {
return nil, err
@ -649,25 +649,25 @@ func (s *sessionActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
return actions, nil
}
// featureActionReadDB is an implementation of the rules.ActionsDB that will
// provide read access to all the Actions of a feature within a particular
// session.
type featureActionsReadDB struct {
// groupFeatureActionsReadDB is an implementation of the rules.ActionsDB that
// will provide read access to all the Actions of a feature within a particular
// group.
type groupFeatureActionsReadDB struct {
*allActionsReadDB
}
var _ ActionsDB = (*featureActionsReadDB)(nil)
var _ ActionsDB = (*groupFeatureActionsReadDB)(nil)
// ListActions will return all the Actions for a particular session that were
// ListActions will return all the Actions for a particular group that were
// executed by a particular feature.
func (a *featureActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
error) {
func (a *groupFeatureActionsReadDB) ListActions(_ context.Context) (
[]*RuleAction, error) {
featureActions, _, _, err := a.db.ListSessionActions(
a.sessionID, func(action *Action, _ bool) (bool, bool) {
featureActions, err := a.db.ListGroupActions(
a.groupID, func(action *Action, _ bool) (bool, bool) {
return action.State == ActionStateDone &&
action.FeatureName == a.featureName, true
}, nil,
},
)
if err != nil {
return nil, err