main.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. keychainlinker "git.aetherial.dev/aeth/keychain-linker/pkg"
  6. "github.com/godbus/dbus/v5"
  7. "github.com/godbus/dbus/v5/introspect"
  8. )
  9. func main() {
  10. conn, err := dbus.ConnectSessionBus()
  11. if err != nil {
  12. panic(err)
  13. }
  14. defer conn.Close()
  15. path := "/dev/aetherial/KeychainLinker"
  16. session := &keychainlinker.Service{SessionBase: "/dev/aetherial/KeychainLinker/session/",
  17. CollectionBase: "/dev/aetherial/KeychainLinker/collection/",
  18. Collections: []dbus.ObjectPath{}}
  19. conn.Export(session, dbus.ObjectPath(path), "dev.aetherial.git.KeychainLinker.Service")
  20. conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), dbus.ObjectPath(path),
  21. "org.freedesktop.DBus.Introspectable")
  22. conn.Export(introspect.Introspectable(introspect.Node{
  23. Interfaces: []introspect.Interface{
  24. introspect.Interface{
  25. Name: "org.freedesktop.secret.Servic",
  26. Methods: []introspect.Method{
  27. {Name: "Get", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "property_name", Type: "s", Direction: "in"}, {Name: "value", Type: "v", Direction: "out"}}},
  28. {Name: "Set", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "property_name", Type: "s", Direction: "in"}, {Name: "value", Type: "v", Direction: "in"}}},
  29. {Name: "GetAll", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "props", Type: "a{sv}", Direction: "out"}}},
  30. },
  31. },
  32. },
  33. }), "/org/freedesktop/secret", "org.freedesktop.DBus.Introspectable")
  34. reply, err := conn.RequestName("dev.aetherial.git.KeychainLinker.Service",
  35. dbus.NameFlagDoNotQueue)
  36. if err != nil {
  37. panic(err)
  38. }
  39. if reply != dbus.RequestNameReplyPrimaryOwner {
  40. fmt.Fprintln(os.Stderr, "name already taken")
  41. os.Exit(1)
  42. }
  43. fmt.Println("Listening on dev.aetherial.git.KeychainLinker.Service / /dev/aetherial/git/KeychainLinker/Service ...")
  44. select {}
  45. }