Skip to content

Commit ec3b38f

Browse files
committed
firewalldb: put Action DB methods behind an interface
So that we can easily add a different implementation and swop them out later.
1 parent 9b3349b commit ec3b38f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

firewalldb/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (db *BoltDB) GetActionsReadDB(groupID session.ID,
230230

231231
// allActionsReadDb is an implementation of the ActionsReadDB.
232232
type allActionsReadDB struct {
233-
db *BoltDB
233+
db ActionDB
234234
groupID session.ID
235235
featureName string
236236
}

firewalldb/interface.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,27 @@ type PrivacyMapper interface {
100100
// given group ID key.
101101
PrivacyDB(groupID session.ID) PrivacyMapDB
102102
}
103+
104+
// ActionDB is an interface that abstracts the database operations needed for
105+
// the Action persistence and querying.
106+
type ActionDB interface {
107+
// AddAction persists the given action to the database.
108+
AddAction(action *Action) (uint64, error)
109+
110+
// SetActionState finds the action specified by the ActionLocator and
111+
// sets its state to the given state.
112+
SetActionState(al *ActionLocator, state ActionState,
113+
errReason string) error
114+
115+
// ListActions returns a list of Actions that pass the filterFn
116+
// requirements. The query IndexOffset and MaxNum params can be used to
117+
// control the number of actions returned. The return values are the
118+
// list of actions, the last index and the total count (iff
119+
// query.CountTotal is set).
120+
ListActions(ctx context.Context, query *ListActionsQuery,
121+
options ...ListActionOption) ([]*Action, uint64, uint64, error)
122+
123+
// GetActionsReadDB produces an ActionReadDB using the given group ID
124+
// and feature name.
125+
GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
126+
}

session_rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type sessionRpcServerConfig struct {
6363
superMacBaker litmac.Baker
6464
firstConnectionDeadline time.Duration
6565
permMgr *perms.Manager
66-
actionsDB *firewalldb.BoltDB
66+
actionsDB firewalldb.ActionDB
6767
autopilot autopilotserver.Autopilot
6868
ruleMgrs rules.ManagerSet
6969
privMap firewalldb.PrivacyMapper

0 commit comments

Comments
 (0)