Ver código fonte

non functioning atm, working on the properties of the session interface

aeth 2 semanas atrás
pai
commit
5d61f6f2f1
2 arquivos alterados com 55 adições e 0 exclusões
  1. 12 0
      main.go
  2. 43 0
      pkg/service.go

+ 12 - 0
main.go

@@ -24,6 +24,18 @@ func main() {
 	conn.Export(session, dbus.ObjectPath(path), "dev.aetherial.git.KeychainLinker.Service")
 	conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), dbus.ObjectPath(path),
 		"org.freedesktop.DBus.Introspectable")
+	conn.Export(introspect.Introspectable(introspect.Node{
+		Interfaces: []introspect.Interface{
+			introspect.Interface{
+				Name: "org.freedesktop.secret.Servic",
+				Methods: []introspect.Method{
+					{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"}}},
+					{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"}}},
+					{Name: "GetAll", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "props", Type: "a{sv}", Direction: "out"}}},
+				},
+			},
+		},
+	}), "/org/freedesktop/secret", "org.freedesktop.DBus.Introspectable")
 
 	reply, err := conn.RequestName("dev.aetherial.git.KeychainLinker.Service",
 		dbus.NameFlagDoNotQueue)

+ 43 - 0
pkg/service.go

@@ -17,6 +17,49 @@ type Service struct {
 	CollectionBase string // e.g. "/org/freedesktop/secrets/collection/"
 }
 
+// implementing method to read the object property
+func (s *Service) Get(iface, property string) (dbus.Variant, *dbus.Error) {
+	if iface != "org/freedesktop/secret/service" {
+		return dbus.Variant{}, dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
+	}
+	switch property {
+	case "Collections":
+		return dbus.MakeVariant(s.Collections), nil
+	default:
+		return dbus.Variant{}, dbus.MakeFailedError(dbus.ErrMsgUnknownMethod)
+	}
+}
+
+// implementing method to read the object property
+func (s *Service) Set(iface, property string, value dbus.Variant) *dbus.Error {
+	if iface != "org/freedesktop/secret/service" {
+		return dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
+	}
+	switch property {
+	case "Collections":
+		collections, ok := value.Value().([]dbus.ObjectPath)
+		if !ok {
+			return dbus.MakeFailedError(dbus.ErrMsgInvalidArg)
+		}
+		s.Collections = collections
+		return nil
+	default:
+		return dbus.MakeFailedError(dbus.ErrMsgUnknownMethod)
+	}
+
+}
+
+// implementing the get all method for the dbus interface
+func (s *Service) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error) {
+	if iface != "org.freedesktop.secret.Service" {
+		return nil, dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
+	}
+
+	return map[string]dbus.Variant{
+		"Collections": dbus.MakeVariant(s.Collections),
+	}, nil
+}
+
 /*
 Opens a session for the Secret Service Interface