Skip to content

Commit 190d3dc

Browse files
committed
multi: rename GetSessionByID to GetSession
By default, we fetch records by an ID.
1 parent 1ba381c commit 190d3dc

File tree

8 files changed

+23
-25
lines changed

8 files changed

+23
-25
lines changed

firewall/privacy_mapper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (p *PrivacyMapper) checkAndReplaceIncomingRequest(ctx context.Context,
190190
uri string, req proto.Message, sessionID session.ID) (proto.Message,
191191
error) {
192192

193-
session, err := p.sessionDB.GetSessionByID(ctx, sessionID)
193+
session, err := p.sessionDB.GetSession(ctx, sessionID)
194194
if err != nil {
195195
return nil, err
196196
}
@@ -220,7 +220,7 @@ func (p *PrivacyMapper) checkAndReplaceIncomingRequest(ctx context.Context,
220220
func (p *PrivacyMapper) replaceOutgoingResponse(ctx context.Context, uri string,
221221
resp proto.Message, sessionID session.ID) (proto.Message, error) {
222222

223-
session, err := p.sessionDB.GetSessionByID(ctx, sessionID)
223+
session, err := p.sessionDB.GetSession(ctx, sessionID)
224224
if err != nil {
225225
return nil, err
226226
}

firewall/rule_enforcer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (r *RuleEnforcer) initRule(ctx context.Context, reqID uint64, name string,
386386
return nil, err
387387
}
388388

389-
session, err := r.sessionDB.GetSessionByID(ctx, sessionID)
389+
session, err := r.sessionDB.GetSession(ctx, sessionID)
390390
if err != nil {
391391
return nil, err
392392
}

firewalldb/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import (
1111
type SessionDB interface {
1212
session.IDToGroupIndex
1313

14-
// GetSessionByID returns the session for a specific id.
15-
GetSessionByID(context.Context, session.ID) (*session.Session, error)
14+
// GetSession returns the session for a specific id.
15+
GetSession(context.Context, session.ID) (*session.Session, error)
1616
}

firewalldb/mock.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ func (m *mockSessionDB) GetSessionIDs(_ context.Context, groupID session.ID) (
5858
return ids, nil
5959
}
6060

61-
// GetSessionByID returns the session for a specific id.
62-
func (m *mockSessionDB) GetSessionByID(_ context.Context,
63-
sessionID session.ID) (*session.Session, error) {
61+
// GetSession returns the session for a specific id.
62+
func (m *mockSessionDB) GetSession(_ context.Context,
63+
id session.ID) (*session.Session, error) {
6464

65-
s, ok := m.sessionToGroupID[sessionID]
65+
s, ok := m.sessionToGroupID[id]
6666
if !ok {
6767
return nil, fmt.Errorf("no session found for session ID")
6868
}
6969

70-
f, ok := m.privacyFlags[sessionID]
70+
f, ok := m.privacyFlags[id]
7171
if !ok {
7272
return nil, fmt.Errorf("no privacy flags found for session ID")
7373
}

session/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ type Store interface {
315315
UpdateSessionRemotePubKey(ctx context.Context, localPubKey,
316316
remotePubKey *btcec.PublicKey) error
317317

318-
// GetSessionByID fetches the session with the given ID.
319-
GetSessionByID(ctx context.Context, id ID) (*Session, error)
318+
// GetSession fetches the session with the given ID.
319+
GetSession(ctx context.Context, id ID) (*Session, error)
320320

321321
// DeleteReservedSessions deletes all sessions that are in the
322322
// StateReserved state.

session/kvdb_store.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,10 @@ func (db *BoltStore) ShiftState(_ context.Context, id ID, dest State) error {
575575
})
576576
}
577577

578-
// GetSessionByID fetches the session with the given ID.
578+
// GetSession fetches the session with the given ID.
579579
//
580580
// NOTE: this is part of the Store interface.
581-
func (db *BoltStore) GetSessionByID(_ context.Context, id ID) (*Session,
582-
error) {
583-
581+
func (db *BoltStore) GetSession(_ context.Context, id ID) (*Session, error) {
584582
var session *Session
585583
err := db.View(func(tx *bbolt.Tx) error {
586584
sessionBucket, err := getBucket(tx, sessionBucketKey)

session/store_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ func TestBasicSessionStore(t *testing.T) {
2929
db := NewTestDB(t, clock)
3030

3131
// Try fetch a session that doesn't exist yet.
32-
_, err := db.GetSessionByID(ctx, ID{1, 3, 4, 4})
32+
_, err := db.GetSession(ctx, ID{1, 3, 4, 4})
3333
require.ErrorIs(t, err, ErrSessionNotFound)
3434

3535
// Reserve a session. This should succeed.
3636
s1, err := reserveSession(db, "session 1")
3737
require.NoError(t, err)
3838

3939
// Show that the session starts in the reserved state.
40-
s1, err = db.GetSessionByID(ctx, s1.ID)
40+
s1, err = db.GetSession(ctx, s1.ID)
4141
require.NoError(t, err)
4242
require.Equal(t, StateReserved, s1.State)
4343

@@ -46,7 +46,7 @@ func TestBasicSessionStore(t *testing.T) {
4646
require.NoError(t, err)
4747

4848
// Show that the session is now in the created state.
49-
s1, err = db.GetSessionByID(ctx, s1.ID)
49+
s1, err = db.GetSession(ctx, s1.ID)
5050
require.NoError(t, err)
5151
require.Equal(t, StateCreated, s1.State)
5252

@@ -86,7 +86,7 @@ func TestBasicSessionStore(t *testing.T) {
8686
require.NoError(t, err)
8787
assertEqualSessions(t, s, session)
8888

89-
session, err = db.GetSessionByID(ctx, s.ID)
89+
session, err = db.GetSession(ctx, s.ID)
9090
require.NoError(t, err)
9191
assertEqualSessions(t, s, session)
9292
}
@@ -361,7 +361,7 @@ func TestLinkedAccount(t *testing.T) {
361361
})
362362

363363
// Make sure that a fetched session includes the account ID.
364-
s1, err = db.GetSessionByID(ctx, s1.ID)
364+
s1, err = db.GetSession(ctx, s1.ID)
365365
require.NoError(t, err)
366366
require.True(t, s1.AccountID.IsSome())
367367
s1.AccountID.WhenSome(func(id accounts.AccountID) {
@@ -453,7 +453,7 @@ func createSession(t *testing.T, db Store, label string,
453453
err = db.ShiftState(context.Background(), s.ID, StateCreated)
454454
require.NoError(t, err)
455455

456-
s, err = db.GetSessionByID(context.Background(), s.ID)
456+
s, err = db.GetSession(context.Background(), s.ID)
457457
require.NoError(t, err)
458458

459459
return s

session_rpcserver.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func (s *sessionRpcServer) AddSession(ctx context.Context,
350350

351351
// Re-fetch the session to get the latest state of it before marshaling
352352
// it.
353-
sess, err = s.cfg.db.GetSessionByID(ctx, sess.ID)
353+
sess, err = s.cfg.db.GetSession(ctx, sess.ID)
354354
if err != nil {
355355
return nil, fmt.Errorf("error fetching session: %v", err)
356356
}
@@ -882,7 +882,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
882882
copy(groupID[:], req.LinkedGroupId)
883883

884884
// Check that the group actually does exist.
885-
groupSess, err := s.cfg.db.GetSessionByID(ctx, groupID)
885+
groupSess, err := s.cfg.db.GetSession(ctx, groupID)
886886
if err != nil {
887887
return nil, err
888888
}
@@ -1269,7 +1269,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12691269

12701270
// Re-fetch the session to get the latest state of it before marshaling
12711271
// it.
1272-
sess, err = s.cfg.db.GetSessionByID(ctx, sess.ID)
1272+
sess, err = s.cfg.db.GetSession(ctx, sess.ID)
12731273
if err != nil {
12741274
return nil, fmt.Errorf("error fetching session: %v", err)
12751275
}

0 commit comments

Comments
 (0)