main.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. const (
  10. dbusName = "org.freedesktop.secrets"
  11. objPath = "/org/freedesktop/secrets/collection/default"
  12. iface = "org.freedesktop.Secret.Collection"
  13. )
  14. func main() {
  15. conn, err := dbus.ConnectSessionBus()
  16. if err != nil {
  17. panic(err)
  18. }
  19. defer conn.Close()
  20. path := "/org/freedesktop/secrets"
  21. service := keychainlinker.NewService(dbus.ObjectPath(path))
  22. conn.Export(service, dbus.ObjectPath(path), "org.freedesktop.Secret.Service")
  23. conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), dbus.ObjectPath(path),
  24. "org.freedesktop.DBus.Introspectable")
  25. /*
  26. node := introspect.Node{
  27. Interfaces: []introspect.Interface{
  28. {
  29. Name: "org.freedesktop.Secret.Service",
  30. Methods: []introspect.Method{
  31. {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"}}},
  32. {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"}}},
  33. {Name: "GetAll", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "props", Type: "a{sv}", Direction: "out"}}},
  34. },
  35. },
  36. },
  37. }
  38. */
  39. conn.Export(introspect.NewIntrospectable(&keychainlinker.ServiceNode), dbus.ObjectPath(path), "org.freedesktop.DBus.Introspectable")
  40. collection := &keychainlinker.Collection{}
  41. conn.Export(collection, objPath, iface)
  42. /*
  43. collectionNode := introspect.Node{
  44. Interfaces: []introspect.Interface{
  45. {
  46. Name: iface,
  47. Methods: []introspect.Method{
  48. {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"}}},
  49. {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"}}},
  50. {
  51. Name: "SearchItems",
  52. Args: []introspect.Arg{
  53. {Name: "attributes", Type: "a{ss}", Direction: "in"},
  54. {Name: "locked", Type: "ao", Direction: "out"},
  55. {Name: "unlocked", Type: "ao", Direction: "out"},
  56. },
  57. },
  58. },
  59. },
  60. },
  61. }
  62. */
  63. conn.Export(introspect.NewIntrospectable(&keychainlinker.CollectionNode), dbus.ObjectPath(path+"/collection/default"), "org.freedesktop.DBus.Introspectable")
  64. reply, err := conn.RequestName(dbusName,
  65. dbus.NameFlagDoNotQueue)
  66. if err != nil {
  67. panic(err)
  68. }
  69. if reply != dbus.RequestNameReplyPrimaryOwner {
  70. fmt.Fprintln(os.Stderr, "name already taken")
  71. os.Exit(1)
  72. }
  73. fmt.Println("Listening on org.freedesktop.secrets / /org/freedesktop/secrets ...")
  74. select {}
  75. }