firewall: remove redundant session ID param from AddAction method

The SessionID is already present in the Action itself and so this does
not need to be passed in as its own parameter.
This commit is contained in:
Elle Mouton 2025-04-19 14:04:38 +02:00
parent b4aadaa4bd
commit 7edb614e12
No known key found for this signature in database
GPG key ID: D7D916376026F177
4 changed files with 12 additions and 13 deletions

View file

@ -194,6 +194,7 @@ func (r *RequestLogger) addNewAction(ri *RequestInfo,
}
action := &firewalldb.Action{
SessionID: sessionID,
RPCMethod: ri.URI,
AttemptedAt: time.Now(),
State: firewalldb.ActionStateInit,
@ -222,7 +223,7 @@ func (r *RequestLogger) addNewAction(ri *RequestInfo,
}
}
id, err := r.actionsDB.AddAction(sessionID, action)
id, err := r.actionsDB.AddAction(action)
if err != nil {
return err
}

View file

@ -94,7 +94,7 @@ type ListActionsQuery struct {
// ActionsWriteDB is an abstraction over the Actions DB that will allow a
// caller to add new actions as well as change the values of an existing action.
type ActionsWriteDB interface {
AddAction(sessionID session.ID, action *Action) (uint64, error)
AddAction(action *Action) (uint64, error)
SetActionState(al *ActionLocator, state ActionState,
errReason string) error
}

View file

@ -53,9 +53,7 @@ var (
)
// AddAction serialises and adds an Action to the DB under the given sessionID.
func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
error) {
func (db *BoltDB) AddAction(action *Action) (uint64, error) {
var buf bytes.Buffer
if err := SerializeAction(&buf, action); err != nil {
return 0, err
@ -74,7 +72,7 @@ func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
}
sessBucket, err := actionsBucket.CreateBucketIfNotExists(
sessionID[:],
action.SessionID[:],
)
if err != nil {
return err
@ -104,7 +102,7 @@ func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
}
locator := ActionLocator{
SessionID: sessionID,
SessionID: action.SessionID,
ActionID: nextActionIndex,
}

View file

@ -67,11 +67,11 @@ func TestActionStorage(t *testing.T) {
require.NoError(t, err)
require.Len(t, actions, 0)
id, err := db.AddAction(sessionID1, action1)
id, err := db.AddAction(action1)
require.NoError(t, err)
require.Equal(t, uint64(1), id)
id, err = db.AddAction(sessionID2, action2)
id, err = db.AddAction(action2)
require.NoError(t, err)
require.Equal(t, uint64(1), id)
@ -104,7 +104,7 @@ func TestActionStorage(t *testing.T) {
action2.State = ActionStateDone
require.Equal(t, action2, actions[0])
id, err = db.AddAction(sessionID1, action1)
id, err = db.AddAction(action1)
require.NoError(t, err)
require.Equal(t, uint64(2), id)
@ -176,7 +176,7 @@ func TestListActions(t *testing.T) {
State: ActionStateDone,
}
_, err := db.AddAction(sessionID, action)
_, err := db.AddAction(action)
require.NoError(t, err)
}
@ -365,7 +365,7 @@ func TestListGroupActions(t *testing.T) {
require.Empty(t, al)
// Add an action under session 1.
_, err = db.AddAction(sessionID1, action1)
_, err = db.AddAction(action1)
require.NoError(t, err)
// There should now be one action in the group.
@ -375,7 +375,7 @@ func TestListGroupActions(t *testing.T) {
require.Equal(t, sessionID1, al[0].SessionID)
// Add an action under session 2.
_, err = db.AddAction(sessionID2, action2)
_, err = db.AddAction(action2)
require.NoError(t, err)
// There should now be actions in the group.