Skip to content

Commit 9218746

Browse files
committed
firewall: update ActionsReadDB to get group actions
1 parent c12e643 commit 9218746

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

firewall/rule_enforcer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ func (r *RuleEnforcer) initRule(reqID uint64, name string, value []byte,
363363
}
364364

365365
allActionsDB := r.actionsDB.GetActionsReadDB(sessionID, featureName)
366-
actionsDB := allActionsDB.FeatureActionsDB()
366+
actionsDB := allActionsDB.GroupFeatureActionsDB()
367367
rulesDB := r.ruleDB.GetKVStores(name, sessionID, featureName)
368368

369369
if sessionRule {
370-
actionsDB = allActionsDB.SessionActionsDB()
370+
actionsDB = allActionsDB.GroupActionsDB()
371371
rulesDB = r.ruleDB.GetKVStores(name, sessionID, "")
372372
}
373373

firewalldb/actions.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -575,67 +575,67 @@ type ActionsDB interface {
575575
ListActions(ctx context.Context) ([]*RuleAction, error)
576576
}
577577

578-
// ActionsReadDB is an abstraction gives a caller access to either a session
579-
// specific or feature specific rules.ActionDB
578+
// ActionsReadDB is an abstraction gives a caller access to either a group
579+
// specific or group and feature specific rules.ActionDB.
580580
type ActionsReadDB interface {
581-
SessionActionsDB() ActionsDB
582-
FeatureActionsDB() ActionsDB
581+
GroupActionsDB() ActionsDB
582+
GroupFeatureActionsDB() ActionsDB
583583
}
584584

585585
// ActionReadDBGetter represents a function that can be used to construct
586586
// an ActionsReadDB.
587587
type ActionReadDBGetter interface {
588-
GetActionsReadDB(sessionID session.ID, featureName string) ActionsReadDB
588+
GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
589589
}
590590

591591
// GetActionsReadDB is a method on DB that constructs an ActionsReadDB.
592-
func (db *DB) GetActionsReadDB(sessionID session.ID,
592+
func (db *DB) GetActionsReadDB(groupID session.ID,
593593
featureName string) ActionsReadDB {
594594

595595
return &allActionsReadDB{
596596
db: db,
597-
sessionID: sessionID,
597+
groupID: groupID,
598598
featureName: featureName,
599599
}
600600
}
601601

602602
// allActionsReadDb is an implementation of the ActionsReadDB.
603603
type allActionsReadDB struct {
604604
db *DB
605-
sessionID session.ID
605+
groupID session.ID
606606
featureName string
607607
}
608608

609609
var _ ActionsReadDB = (*allActionsReadDB)(nil)
610610

611-
// SessionActionsDB returns a rules.ActionsDB that will give the caller access
612-
// to all of a sessions Actions.
613-
func (a *allActionsReadDB) SessionActionsDB() ActionsDB {
614-
return &sessionActionsReadDB{a}
611+
// GroupActionsDB returns a rules.ActionsDB that will give the caller access
612+
// to all of a groups Actions.
613+
func (a *allActionsReadDB) GroupActionsDB() ActionsDB {
614+
return &groupActionsReadDB{a}
615615
}
616616

617-
// FeatureActionsDB returns an rules.ActionsDB that will give the caller access
618-
// to only a specific features Actions in a specific session.
619-
func (a *allActionsReadDB) FeatureActionsDB() ActionsDB {
620-
return &featureActionsReadDB{a}
617+
// GroupFeatureActionsDB returns a rules.ActionsDB that will give the caller
618+
// access to only a specific features Actions in a specific group.
619+
func (a *allActionsReadDB) GroupFeatureActionsDB() ActionsDB {
620+
return &groupFeatureActionsReadDB{a}
621621
}
622622

623-
// sessionActionReadDB is an implementation of the rules.ActionsDB that will
624-
// provide read access to all the Actions of a particular session.
625-
type sessionActionsReadDB struct {
623+
// groupActionsReadDB is an implementation of the rules.ActionsDB that will
624+
// provide read access to all the Actions of a particular group.
625+
type groupActionsReadDB struct {
626626
*allActionsReadDB
627627
}
628628

629-
var _ ActionsDB = (*sessionActionsReadDB)(nil)
629+
var _ ActionsDB = (*groupActionsReadDB)(nil)
630630

631-
// ListActions will return all the Actions for a particular session.
632-
func (s *sessionActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
631+
// ListActions will return all the Actions for a particular group.
632+
func (s *groupActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
633633
error) {
634634

635-
sessionActions, _, _, err := s.db.ListSessionActions(
636-
s.sessionID, func(a *Action, _ bool) (bool, bool) {
635+
sessionActions, err := s.db.ListGroupActions(
636+
s.groupID, func(a *Action, _ bool) (bool, bool) {
637637
return a.State == ActionStateDone, true
638-
}, nil,
638+
},
639639
)
640640
if err != nil {
641641
return nil, err
@@ -649,25 +649,25 @@ func (s *sessionActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
649649
return actions, nil
650650
}
651651

652-
// featureActionReadDB is an implementation of the rules.ActionsDB that will
653-
// provide read access to all the Actions of a feature within a particular
654-
// session.
655-
type featureActionsReadDB struct {
652+
// groupFeatureActionsReadDB is an implementation of the rules.ActionsDB that
653+
// will provide read access to all the Actions of a feature within a particular
654+
// group.
655+
type groupFeatureActionsReadDB struct {
656656
*allActionsReadDB
657657
}
658658

659-
var _ ActionsDB = (*featureActionsReadDB)(nil)
659+
var _ ActionsDB = (*groupFeatureActionsReadDB)(nil)
660660

661-
// ListActions will return all the Actions for a particular session that were
661+
// ListActions will return all the Actions for a particular group that were
662662
// executed by a particular feature.
663-
func (a *featureActionsReadDB) ListActions(_ context.Context) ([]*RuleAction,
664-
error) {
663+
func (a *groupFeatureActionsReadDB) ListActions(_ context.Context) (
664+
[]*RuleAction, error) {
665665

666-
featureActions, _, _, err := a.db.ListSessionActions(
667-
a.sessionID, func(action *Action, _ bool) (bool, bool) {
666+
featureActions, err := a.db.ListGroupActions(
667+
a.groupID, func(action *Action, _ bool) (bool, bool) {
668668
return action.State == ActionStateDone &&
669669
action.FeatureName == a.featureName, true
670-
}, nil,
670+
},
671671
)
672672
if err != nil {
673673
return nil, err

0 commit comments

Comments
 (0)