firewalldb: put Action DB methods behind an interface

So that we can easily add a different implementation and swop them out
later.
This commit is contained in:
Elle Mouton 2025-04-19 14:24:32 +02:00
parent 9b3349b31e
commit ec3b38f607
No known key found for this signature in database
GPG key ID: D7D916376026F177
3 changed files with 26 additions and 2 deletions

View file

@ -230,7 +230,7 @@ func (db *BoltDB) GetActionsReadDB(groupID session.ID,
// allActionsReadDb is an implementation of the ActionsReadDB.
type allActionsReadDB struct {
db *BoltDB
db ActionDB
groupID session.ID
featureName string
}

View file

@ -100,3 +100,27 @@ type PrivacyMapper interface {
// given group ID key.
PrivacyDB(groupID session.ID) PrivacyMapDB
}
// ActionDB is an interface that abstracts the database operations needed for
// the Action persistence and querying.
type ActionDB interface {
// AddAction persists the given action to the database.
AddAction(action *Action) (uint64, error)
// SetActionState finds the action specified by the ActionLocator and
// sets its state to the given state.
SetActionState(al *ActionLocator, state ActionState,
errReason string) error
// ListActions returns a list of Actions that pass the filterFn
// requirements. The query IndexOffset and MaxNum params can be used to
// control the number of actions returned. The return values are the
// list of actions, the last index and the total count (iff
// query.CountTotal is set).
ListActions(ctx context.Context, query *ListActionsQuery,
options ...ListActionOption) ([]*Action, uint64, uint64, error)
// GetActionsReadDB produces an ActionReadDB using the given group ID
// and feature name.
GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
}

View file

@ -63,7 +63,7 @@ type sessionRpcServerConfig struct {
superMacBaker litmac.Baker
firstConnectionDeadline time.Duration
permMgr *perms.Manager
actionsDB *firewalldb.BoltDB
actionsDB firewalldb.ActionDB
autopilot autopilotserver.Autopilot
ruleMgrs rules.ManagerSet
privMap firewalldb.PrivacyMapper