firewalldb: thread contexts to FetchAllPairs

Update the FetchAllPairs method of the PrivacyMapTx interface to take a
context.
This commit is contained in:
Elle Mouton 2025-03-13 16:32:23 -05:00
parent 5b31f16446
commit ef93611489
No known key found for this signature in database
GPG key ID: D7D916376026F177
4 changed files with 12 additions and 10 deletions

View file

@ -1151,8 +1151,8 @@ func (m *mockPrivacyMapDB) RealToPseudo(_ context.Context, real string) (string,
return p, nil
}
func (m *mockPrivacyMapDB) FetchAllPairs() (*firewalldb.PrivacyMapPairs,
error) {
func (m *mockPrivacyMapDB) FetchAllPairs(_ context.Context) (
*firewalldb.PrivacyMapPairs, error) {
return firewalldb.NewPrivacyMapPairs(m.r2p), nil
}

View file

@ -83,7 +83,7 @@ type PrivacyMapTx interface {
// FetchAllPairs loads and returns the real-to-pseudo pairs in the form
// of a PrivacyMapPairs struct.
FetchAllPairs() (*PrivacyMapPairs, error)
FetchAllPairs(ctx context.Context) (*PrivacyMapPairs, error)
}
// privacyMapDB is an implementation of PrivacyMapDB.
@ -287,7 +287,9 @@ func (p *privacyMapTx) RealToPseudo(_ context.Context, real string) (string,
// FetchAllPairs loads and returns the real-to-pseudo pairs.
//
// NOTE: this is part of the PrivacyMapTx interface.
func (p *privacyMapTx) FetchAllPairs() (*PrivacyMapPairs, error) {
func (p *privacyMapTx) FetchAllPairs(_ context.Context) (*PrivacyMapPairs,
error) {
privacyBucket, err := getBucket(p.boltTx, privacyBucketKey)
if err != nil {
return nil, err

View file

@ -40,7 +40,7 @@ func TestPrivacyMapStorage(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "real", real)
pairs, err := tx.FetchAllPairs()
pairs, err := tx.FetchAllPairs(ctx)
require.NoError(t, err)
require.EqualValues(t, pairs.pairs, map[string]string{
@ -70,7 +70,7 @@ func TestPrivacyMapStorage(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "real 2", real)
pairs, err := tx.FetchAllPairs()
pairs, err := tx.FetchAllPairs(ctx)
require.NoError(t, err)
require.EqualValues(t, pairs.pairs, map[string]string{
@ -85,7 +85,7 @@ func TestPrivacyMapStorage(t *testing.T) {
_ = pdb3.Update(ctx, func(ctx context.Context, tx PrivacyMapTx) error {
// Check that calling FetchAllPairs returns an empty map if
// nothing exists in the DB yet.
m, err := tx.FetchAllPairs()
m, err := tx.FetchAllPairs(ctx)
require.NoError(t, err)
require.Empty(t, m.pairs)
@ -116,7 +116,7 @@ func TestPrivacyMapStorage(t *testing.T) {
require.NoError(t, err)
// Check that FetchAllPairs correctly returns all the pairs.
pairs, err := tx.FetchAllPairs()
pairs, err := tx.FetchAllPairs(ctx)
require.NoError(t, err)
require.EqualValues(t, pairs.pairs, map[string]string{

View file

@ -901,10 +901,10 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
linkedGroupSession = groupSess
privDB := s.cfg.privMap(groupID)
err = privDB.View(ctx, func(_ context.Context,
err = privDB.View(ctx, func(ctx context.Context,
tx firewalldb.PrivacyMapTx) error {
knownPrivMapPairs, err = tx.FetchAllPairs()
knownPrivMapPairs, err = tx.FetchAllPairs(ctx)
return err
})