main.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 := "/org/freedesktop/secrets"
  16. service := keychainlinker.NewService(dbus.ObjectPath(path))
  17. conn.Export(service, dbus.ObjectPath(path), "org.freedesktop.Secret.Service")
  18. conn.Export(service.Cache["/org/freedesktop/secrets/collection/default"], "/org/freedesktop/secrets/collection/default", "org.freedesktop.DBus.Properties")
  19. conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), dbus.ObjectPath(path),
  20. "org.freedesktop.DBus.Introspectable")
  21. <<<<<<< HEAD
  22. conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), "/org/freedesktop/secrets/collection/default", "org.freedesktop.DBus.Introspectable")
  23. reply, err := conn.RequestName("org.freedesktop.secrets",
  24. =======
  25. node := introspect.Node{
  26. Interfaces: []introspect.Interface{
  27. {
  28. Name: "org.freedesktop.secret.Service",
  29. Methods: []introspect.Method{
  30. {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"}}},
  31. {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"}}},
  32. {Name: "GetAll", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "props", Type: "a{sv}", Direction: "out"}}},
  33. },
  34. },
  35. },
  36. }
  37. conn.Export(introspect.Introspectable(introspect.NewIntrospectable(&node)), "/org/freedesktop/secret", "org.freedesktop.DBus.Introspectable")
  38. node = introspect.Node{
  39. Interfaces: []introspect.Interface{
  40. {
  41. Name: "org.freedesktop.secret.Collection",
  42. Methods: []introspect.Method{
  43. {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"}}},
  44. {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"}}},
  45. },
  46. },
  47. },
  48. }
  49. conn.Export(introspect.Introspectable(introspect.NewIntrospectable(&node)), "/org/freedesktop/secret", "org.freedesktop.DBus.IntrospectData")
  50. reply, err := conn.RequestName("dev.aetherial.git.KeychainLinker.Service",
  51. >>>>>>> 2946fa107c12a5e2d1c88f3b60f8bea802b19fd7
  52. dbus.NameFlagDoNotQueue)
  53. if err != nil {
  54. panic(err)
  55. }
  56. if reply != dbus.RequestNameReplyPrimaryOwner {
  57. fmt.Fprintln(os.Stderr, "name already taken")
  58. os.Exit(1)
  59. }
  60. fmt.Println("Listening on org.freedesktop.secrets / /org/freedesktop/secrets ...")
  61. select {}
  62. }