multi: rename GetSessionByID to GetSession

By default, we fetch records by an ID.
This commit is contained in:
Elle Mouton 2025-03-04 17:34:31 +02:00
parent 1ba381cead
commit 190d3dc828
No known key found for this signature in database
GPG key ID: D7D916376026F177
8 changed files with 23 additions and 25 deletions

View file

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

View file

@ -386,7 +386,7 @@ func (r *RuleEnforcer) initRule(ctx context.Context, reqID uint64, name string,
return nil, err
}
session, err := r.sessionDB.GetSessionByID(ctx, sessionID)
session, err := r.sessionDB.GetSession(ctx, sessionID)
if err != nil {
return nil, err
}

View file

@ -11,6 +11,6 @@ import (
type SessionDB interface {
session.IDToGroupIndex
// GetSessionByID returns the session for a specific id.
GetSessionByID(context.Context, session.ID) (*session.Session, error)
// GetSession returns the session for a specific id.
GetSession(context.Context, session.ID) (*session.Session, error)
}

View file

@ -58,16 +58,16 @@ func (m *mockSessionDB) GetSessionIDs(_ context.Context, groupID session.ID) (
return ids, nil
}
// GetSessionByID returns the session for a specific id.
func (m *mockSessionDB) GetSessionByID(_ context.Context,
sessionID session.ID) (*session.Session, error) {
// GetSession returns the session for a specific id.
func (m *mockSessionDB) GetSession(_ context.Context,
id session.ID) (*session.Session, error) {
s, ok := m.sessionToGroupID[sessionID]
s, ok := m.sessionToGroupID[id]
if !ok {
return nil, fmt.Errorf("no session found for session ID")
}
f, ok := m.privacyFlags[sessionID]
f, ok := m.privacyFlags[id]
if !ok {
return nil, fmt.Errorf("no privacy flags found for session ID")
}

View file

@ -315,8 +315,8 @@ type Store interface {
UpdateSessionRemotePubKey(ctx context.Context, localPubKey,
remotePubKey *btcec.PublicKey) error
// GetSessionByID fetches the session with the given ID.
GetSessionByID(ctx context.Context, id ID) (*Session, error)
// GetSession fetches the session with the given ID.
GetSession(ctx context.Context, id ID) (*Session, error)
// DeleteReservedSessions deletes all sessions that are in the
// StateReserved state.

View file

@ -575,12 +575,10 @@ func (db *BoltStore) ShiftState(_ context.Context, id ID, dest State) error {
})
}
// GetSessionByID fetches the session with the given ID.
// GetSession fetches the session with the given ID.
//
// NOTE: this is part of the Store interface.
func (db *BoltStore) GetSessionByID(_ context.Context, id ID) (*Session,
error) {
func (db *BoltStore) GetSession(_ context.Context, id ID) (*Session, error) {
var session *Session
err := db.View(func(tx *bbolt.Tx) error {
sessionBucket, err := getBucket(tx, sessionBucketKey)

View file

@ -29,7 +29,7 @@ func TestBasicSessionStore(t *testing.T) {
db := NewTestDB(t, clock)
// Try fetch a session that doesn't exist yet.
_, err := db.GetSessionByID(ctx, ID{1, 3, 4, 4})
_, err := db.GetSession(ctx, ID{1, 3, 4, 4})
require.ErrorIs(t, err, ErrSessionNotFound)
// Reserve a session. This should succeed.
@ -37,7 +37,7 @@ func TestBasicSessionStore(t *testing.T) {
require.NoError(t, err)
// Show that the session starts in the reserved state.
s1, err = db.GetSessionByID(ctx, s1.ID)
s1, err = db.GetSession(ctx, s1.ID)
require.NoError(t, err)
require.Equal(t, StateReserved, s1.State)
@ -46,7 +46,7 @@ func TestBasicSessionStore(t *testing.T) {
require.NoError(t, err)
// Show that the session is now in the created state.
s1, err = db.GetSessionByID(ctx, s1.ID)
s1, err = db.GetSession(ctx, s1.ID)
require.NoError(t, err)
require.Equal(t, StateCreated, s1.State)
@ -86,7 +86,7 @@ func TestBasicSessionStore(t *testing.T) {
require.NoError(t, err)
assertEqualSessions(t, s, session)
session, err = db.GetSessionByID(ctx, s.ID)
session, err = db.GetSession(ctx, s.ID)
require.NoError(t, err)
assertEqualSessions(t, s, session)
}
@ -361,7 +361,7 @@ func TestLinkedAccount(t *testing.T) {
})
// Make sure that a fetched session includes the account ID.
s1, err = db.GetSessionByID(ctx, s1.ID)
s1, err = db.GetSession(ctx, s1.ID)
require.NoError(t, err)
require.True(t, s1.AccountID.IsSome())
s1.AccountID.WhenSome(func(id accounts.AccountID) {
@ -453,7 +453,7 @@ func createSession(t *testing.T, db Store, label string,
err = db.ShiftState(context.Background(), s.ID, StateCreated)
require.NoError(t, err)
s, err = db.GetSessionByID(context.Background(), s.ID)
s, err = db.GetSession(context.Background(), s.ID)
require.NoError(t, err)
return s

View file

@ -350,7 +350,7 @@ func (s *sessionRpcServer) AddSession(ctx context.Context,
// Re-fetch the session to get the latest state of it before marshaling
// it.
sess, err = s.cfg.db.GetSessionByID(ctx, sess.ID)
sess, err = s.cfg.db.GetSession(ctx, sess.ID)
if err != nil {
return nil, fmt.Errorf("error fetching session: %v", err)
}
@ -882,7 +882,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
copy(groupID[:], req.LinkedGroupId)
// Check that the group actually does exist.
groupSess, err := s.cfg.db.GetSessionByID(ctx, groupID)
groupSess, err := s.cfg.db.GetSession(ctx, groupID)
if err != nil {
return nil, err
}
@ -1269,7 +1269,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
// Re-fetch the session to get the latest state of it before marshaling
// it.
sess, err = s.cfg.db.GetSessionByID(ctx, sess.ID)
sess, err = s.cfg.db.GetSession(ctx, sess.ID)
if err != nil {
return nil, fmt.Errorf("error fetching session: %v", err)
}