Skip to content

Commit

Permalink
Appease "unparam" linter by removing unused ctx parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
adombeck committed Sep 25, 2024
1 parent 8db41a2 commit a8fafc4
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 27 deletions.
8 changes: 4 additions & 4 deletions internal/brokers/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type fieldValidator struct {
}

// newBroker creates a new broker object based on the provided config file. No config means local broker.
func newBroker(ctx context.Context, configFile string, bus *dbus.Conn) (b Broker, err error) {
func newBroker(configFile string, bus *dbus.Conn) (b Broker, err error) {
defer decorate.OnError(&err, "can't create broker from %q", configFile)

name := LocalBrokerName
Expand All @@ -78,7 +78,7 @@ func newBroker(ctx context.Context, configFile string, bus *dbus.Conn) (b Broker

if configFile != "" {
slog.Debug(fmt.Sprintf("Loading broker from %q", configFile))
broker, name, brandIcon, err = newDbusBroker(ctx, bus, configFile)
broker, name, brandIcon, err = newDbusBroker(bus, configFile)
if err != nil {
return Broker{}, err
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func (b *Broker) GetAuthenticationModes(ctx context.Context, sessionID string, s
sessionID = b.parseSessionID(sessionID)

b.layoutValidatorsMu.Lock()
b.layoutValidators[sessionID] = generateValidators(ctx, sessionID, supportedUILayouts)
b.layoutValidators[sessionID] = generateValidators(sessionID, supportedUILayouts)
b.layoutValidatorsMu.Unlock()

authenticationModes, err = b.brokerer.GetAuthenticationModes(ctx, sessionID, supportedUILayouts)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (b Broker) UserPreCheck(ctx context.Context, username string) (userinfo str
// }
// }
// }
func generateValidators(ctx context.Context, sessionID string, supportedUILayouts []map[string]string) map[string]layoutValidator {
func generateValidators(sessionID string, supportedUILayouts []map[string]string) map[string]layoutValidator {
validators := make(map[string]layoutValidator)
for _, layout := range supportedUILayouts {
if _, exists := layout["type"]; !exists {
Expand Down
4 changes: 2 additions & 2 deletions internal/brokers/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNewBroker(t *testing.T) {
tc.configFile = filepath.Join(configDir, tc.configFile)
}

got, err := brokers.NewBroker(context.Background(), tc.configFile, conn)
got, err := brokers.NewBroker(tc.configFile, conn)
if tc.wantErr {
require.Error(t, err, "NewBroker should return an error, but did not")
return
Expand Down Expand Up @@ -367,7 +367,7 @@ func newBrokerForTests(t *testing.T, cfgDir, brokerCfg string) (b brokers.Broker
require.NoError(t, err, "Setup: could not connect to system bus")
t.Cleanup(func() { require.NoError(t, conn.Close(), "Teardown: Failed to close the connection") })

b, err = brokers.NewBroker(context.Background(), cfgPath, conn)
b, err = brokers.NewBroker(cfgPath, conn)
require.NoError(t, err, "Setup: could not create broker")

return b
Expand Down
2 changes: 1 addition & 1 deletion internal/brokers/dbusbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type dbusBroker struct {
}

// newDbusBroker returns a dbus broker and broker attributes from its configuration file.
func newDbusBroker(ctx context.Context, bus *dbus.Conn, configFile string) (b dbusBroker, name, brandIcon string, err error) {
func newDbusBroker(bus *dbus.Conn, configFile string) (b dbusBroker, name, brandIcon string, err error) {
defer decorate.OnError(&err, "dbus broker from configuration file: %q", configFile)

slog.Debug(fmt.Sprintf("Dbus broker configuration at %q", configFile))
Expand Down
7 changes: 3 additions & 4 deletions internal/brokers/export_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package brokers

import (
"context"
"fmt"
"sort"

"github.com/godbus/dbus/v5"
)

// NewBroker exports the private newBroker function for testing purposes.
func NewBroker(ctx context.Context, configFile string, bus *dbus.Conn) (Broker, error) {
return newBroker(ctx, configFile, bus)
func NewBroker(configFile string, bus *dbus.Conn) (Broker, error) {
return newBroker(configFile, bus)
}

// SetBrokerForSession sets the broker for a given session.
Expand All @@ -26,7 +25,7 @@ func (m *Manager) SetBrokerForSession(b *Broker, sessionID string) {
func GenerateLayoutValidators(b *Broker, sessionID string, supportedUILayouts []map[string]string) {
b.layoutValidatorsMu.Lock()
defer b.layoutValidatorsMu.Unlock()
b.layoutValidators[sessionID] = generateValidators(context.Background(), sessionID, supportedUILayouts)
b.layoutValidators[sessionID] = generateValidators(sessionID, supportedUILayouts)
}

// LayoutValidatorsString returns a string representation of the layout validators.
Expand Down
6 changes: 3 additions & 3 deletions internal/brokers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Manager struct {
}

// NewManager creates a new broker manager object.
func NewManager(ctx context.Context, brokersConfPath string, configuredBrokers []string) (m *Manager, err error) {
func NewManager(brokersConfPath string, configuredBrokers []string) (m *Manager, err error) {
defer decorate.OnError(&err /*i18n.G(*/, "can't create brokers detection object") //)

slog.Debug("Building broker detection")
Expand Down Expand Up @@ -78,14 +78,14 @@ func NewManager(ctx context.Context, brokersConfPath string, configuredBrokers [
var brokersOrder []string

// First broker is always the local one.
b, err := newBroker(ctx, "", nil)
b, err := newBroker("", nil)
brokersOrder = append(brokersOrder, b.ID)
brokers[b.ID] = &b

// Load brokers configuration
for _, cfgFileName := range configuredBrokers {
configFile := filepath.Join(brokersConfPath, cfgFileName)
b, err := newBroker(ctx, configFile, bus)
b, err := newBroker(configFile, bus)
if err != nil {
slog.Warn(fmt.Sprintf("Skipping broker %q is not correctly configured: %v", cfgFileName, err))
continue
Expand Down
15 changes: 7 additions & 8 deletions internal/brokers/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package brokers_test

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -45,7 +44,7 @@ func TestNewManager(t *testing.T) {
t.Setenv("DBUS_SYSTEM_BUS_ADDRESS", "/dev/null")
}

got, err := brokers.NewManager(context.Background(), filepath.Join(brokerConfFixtures, tc.brokerConfigDir), tc.configuredBrokers)
got, err := brokers.NewManager(filepath.Join(brokerConfFixtures, tc.brokerConfigDir), tc.configuredBrokers)
if tc.wantErr {
require.Error(t, err, "NewManager should return an error, but did not")
return
Expand Down Expand Up @@ -80,7 +79,7 @@ func TestSetDefaultBrokerForUser(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

m, err := brokers.NewManager(context.Background(), filepath.Join(brokerConfFixtures, "mixed_brokers"), nil)
m, err := brokers.NewManager(filepath.Join(brokerConfFixtures, "mixed_brokers"), nil)
require.NoError(t, err, "Setup: could not create manager")

want := m.AvailableBrokers()[0]
Expand All @@ -104,7 +103,7 @@ func TestSetDefaultBrokerForUser(t *testing.T) {
func TestBrokerForUser(t *testing.T) {
t.Parallel()

m, err := brokers.NewManager(context.Background(), filepath.Join(brokerConfFixtures, "valid_brokers"), nil)
m, err := brokers.NewManager(filepath.Join(brokerConfFixtures, "valid_brokers"), nil)
require.NoError(t, err, "Setup: could not create manager")

err = m.SetDefaultBrokerForUser(brokers.LocalBrokerName, "user")
Expand Down Expand Up @@ -139,7 +138,7 @@ func TestBrokerFromSessionID(t *testing.T) {

brokersConfPath := t.TempDir()
b := newBrokerForTests(t, brokersConfPath, "")
m, err := brokers.NewManager(context.Background(), brokersConfPath, nil)
m, err := brokers.NewManager(brokersConfPath, nil)
require.NoError(t, err, "Setup: could not create manager")

if tc.sessionID == "success" {
Expand Down Expand Up @@ -214,7 +213,7 @@ func TestNewSession(t *testing.T) {
tc.configuredBrokers = nil
}

m, err := brokers.NewManager(context.Background(), brokersConfPath, tc.configuredBrokers)
m, err := brokers.NewManager(brokersConfPath, tc.configuredBrokers)
require.NoError(t, err, "Setup: could not create manager")

if tc.brokerID == "" {
Expand Down Expand Up @@ -287,7 +286,7 @@ func TestEndSession(t *testing.T) {
}
}

m, err := brokers.NewManager(context.Background(), brokersConfPath, tc.configuredBrokers)
m, err := brokers.NewManager(brokersConfPath, tc.configuredBrokers)
require.NoError(t, err, "Setup: could not create manager")

if tc.brokerID != "does not exist" {
Expand All @@ -313,7 +312,7 @@ func TestStartAndEndSession(t *testing.T) {
b1 := newBrokerForTests(t, brokersConfPath, t.Name()+"_Broker1.conf")
b2 := newBrokerForTests(t, brokersConfPath, t.Name()+"_Broker2.conf")

m, err := brokers.NewManager(context.Background(), brokersConfPath, []string{b1.Name + ".conf", b2.Name + ".conf"})
m, err := brokers.NewManager(brokersConfPath, []string{b1.Name + ".conf", b2.Name + ".conf"})
require.NoError(t, err, "Setup: could not create manager")

// Fetches the broker IDs
Expand Down
2 changes: 1 addition & 1 deletion internal/services/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewManager(ctx context.Context, cacheDir, brokersConfPath string, configure

slog.Debug("Building authd object")

brokerManager, err := brokers.NewManager(ctx, brokersConfPath, configuredBrokers)
brokerManager, err := brokers.NewManager(brokersConfPath, configuredBrokers)
if err != nil {
return m, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/services/nss/nss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestNewService(t *testing.T) {
require.NoError(t, err, "Setup: could not create user manager")
t.Cleanup(func() { _ = m.Stop() })

b, err := brokers.NewManager(context.Background(), t.TempDir(), nil)
b, err := brokers.NewManager(t.TempDir(), nil)
require.NoError(t, err, "Setup: could not create broker manager")

pm := permissions.New()
Expand Down Expand Up @@ -350,7 +350,7 @@ func newBrokersManagerForTests(t *testing.T) *brokers.Manager {
require.NoError(t, err, "Setup: could not start bus broker mock")
t.Cleanup(cleanup)

m, err := brokers.NewManager(context.Background(), filepath.Dir(cfg), nil)
m, err := brokers.NewManager(filepath.Dir(cfg), nil)
require.NoError(t, err, "Setup: could not create broker manager")
t.Cleanup(m.Stop)

Expand Down
4 changes: 2 additions & 2 deletions internal/services/pam/pam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestGetPreviousBroker(t *testing.T) {

brokerManager := globalBrokerManager
if tc.onlyLocalBroker {
brokerManager, err = brokers.NewManager(context.Background(), "", nil)
brokerManager, err = brokers.NewManager("", nil)
require.NoError(t, err, "Setup: could not create broker manager with only local broker")
}
client := newPamClient(t, m, brokerManager, &pm)
Expand Down Expand Up @@ -839,7 +839,7 @@ func TestMain(m *testing.M) {
defer cleanup()

// Get manager shared across grpc services.
globalBrokerManager, err = brokers.NewManager(context.Background(), brokersConfPath, nil)
globalBrokerManager, err = brokers.NewManager(brokersConfPath, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
Expand Down

0 comments on commit a8fafc4

Please sign in to comment.