Skip to content

Commit 7edb614

Browse files
committed
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.
1 parent b4aadaa commit 7edb614

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

firewall/request_logger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func (r *RequestLogger) addNewAction(ri *RequestInfo,
194194
}
195195

196196
action := &firewalldb.Action{
197+
SessionID: sessionID,
197198
RPCMethod: ri.URI,
198199
AttemptedAt: time.Now(),
199200
State: firewalldb.ActionStateInit,
@@ -222,7 +223,7 @@ func (r *RequestLogger) addNewAction(ri *RequestInfo,
222223
}
223224
}
224225

225-
id, err := r.actionsDB.AddAction(sessionID, action)
226+
id, err := r.actionsDB.AddAction(action)
226227
if err != nil {
227228
return err
228229
}

firewalldb/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type ListActionsQuery struct {
9494
// ActionsWriteDB is an abstraction over the Actions DB that will allow a
9595
// caller to add new actions as well as change the values of an existing action.
9696
type ActionsWriteDB interface {
97-
AddAction(sessionID session.ID, action *Action) (uint64, error)
97+
AddAction(action *Action) (uint64, error)
9898
SetActionState(al *ActionLocator, state ActionState,
9999
errReason string) error
100100
}

firewalldb/actions_kvdb.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ var (
5353
)
5454

5555
// AddAction serialises and adds an Action to the DB under the given sessionID.
56-
func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
57-
error) {
58-
56+
func (db *BoltDB) AddAction(action *Action) (uint64, error) {
5957
var buf bytes.Buffer
6058
if err := SerializeAction(&buf, action); err != nil {
6159
return 0, err
@@ -74,7 +72,7 @@ func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
7472
}
7573

7674
sessBucket, err := actionsBucket.CreateBucketIfNotExists(
77-
sessionID[:],
75+
action.SessionID[:],
7876
)
7977
if err != nil {
8078
return err
@@ -104,7 +102,7 @@ func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
104102
}
105103

106104
locator := ActionLocator{
107-
SessionID: sessionID,
105+
SessionID: action.SessionID,
108106
ActionID: nextActionIndex,
109107
}
110108

firewalldb/actions_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func TestActionStorage(t *testing.T) {
6767
require.NoError(t, err)
6868
require.Len(t, actions, 0)
6969

70-
id, err := db.AddAction(sessionID1, action1)
70+
id, err := db.AddAction(action1)
7171
require.NoError(t, err)
7272
require.Equal(t, uint64(1), id)
7373

74-
id, err = db.AddAction(sessionID2, action2)
74+
id, err = db.AddAction(action2)
7575
require.NoError(t, err)
7676
require.Equal(t, uint64(1), id)
7777

@@ -104,7 +104,7 @@ func TestActionStorage(t *testing.T) {
104104
action2.State = ActionStateDone
105105
require.Equal(t, action2, actions[0])
106106

107-
id, err = db.AddAction(sessionID1, action1)
107+
id, err = db.AddAction(action1)
108108
require.NoError(t, err)
109109
require.Equal(t, uint64(2), id)
110110

@@ -176,7 +176,7 @@ func TestListActions(t *testing.T) {
176176
State: ActionStateDone,
177177
}
178178

179-
_, err := db.AddAction(sessionID, action)
179+
_, err := db.AddAction(action)
180180
require.NoError(t, err)
181181
}
182182

@@ -365,7 +365,7 @@ func TestListGroupActions(t *testing.T) {
365365
require.Empty(t, al)
366366

367367
// Add an action under session 1.
368-
_, err = db.AddAction(sessionID1, action1)
368+
_, err = db.AddAction(action1)
369369
require.NoError(t, err)
370370

371371
// There should now be one action in the group.
@@ -375,7 +375,7 @@ func TestListGroupActions(t *testing.T) {
375375
require.Equal(t, sessionID1, al[0].SessionID)
376376

377377
// Add an action under session 2.
378-
_, err = db.AddAction(sessionID2, action2)
378+
_, err = db.AddAction(action2)
379379
require.NoError(t, err)
380380

381381
// There should now be actions in the group.

0 commit comments

Comments
 (0)