-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathlocalbus.go
More file actions
34 lines (28 loc) · 790 Bytes
/
localbus.go
File metadata and controls
34 lines (28 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// TiCS: disabled // This is a helper file for tests.
//go:build withlocalbus
package dbusservice
import (
"context"
"os"
"github.com/canonical/authd/authd-oidc-brokers/internal/testutils"
"github.com/canonical/authd/log"
"github.com/godbus/dbus/v5"
)
// getBus creates the local bus and returns a connection to the bus.
// It attaches a disconnect handler to stop the local bus subprocess.
func (s *Service) getBus() (*dbus.Conn, error) {
cleanup, err := testutils.StartSystemBusMock()
if err != nil {
return nil, err
}
log.Infof(context.Background(), "Using local bus address: %s", os.Getenv("DBUS_SYSTEM_BUS_ADDRESS"))
conn, err := dbus.ConnectSystemBus()
if err != nil {
return nil, err
}
s.disconnect = func() {
conn.Close()
cleanup()
}
return conn, err
}