Browse Source

working on interface properties

aeth 2 weeks ago
parent
commit
2946fa107c
2 changed files with 57 additions and 4 deletions
  1. 17 4
      main.go
  2. 40 0
      pkg/collection.go

+ 17 - 4
main.go

@@ -24,10 +24,10 @@ 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{
+	node := introspect.Node{
 		Interfaces: []introspect.Interface{
-			introspect.Interface{
-				Name: "org.freedesktop.secret.Servic",
+			{
+				Name: "org.freedesktop.secret.Service",
 				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"}}},
@@ -35,7 +35,20 @@ func main() {
 				},
 			},
 		},
-	}), "/org/freedesktop/secret", "org.freedesktop.DBus.Introspectable")
+	}
+	conn.Export(introspect.Introspectable(introspect.NewIntrospectable(&node)), "/org/freedesktop/secret", "org.freedesktop.DBus.Introspectable")
+	node = introspect.Node{
+		Interfaces: []introspect.Interface{
+			{
+				Name: "org.freedesktop.secret.Collection",
+				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"}}},
+				},
+			},
+		},
+	}
+	conn.Export(introspect.Introspectable(introspect.NewIntrospectable(&node)), "/org/freedesktop/secret", "org.freedesktop.DBus.IntrospectData")
 
 	reply, err := conn.RequestName("dev.aetherial.git.KeychainLinker.Service",
 		dbus.NameFlagDoNotQueue)

+ 40 - 0
pkg/collection.go

@@ -41,3 +41,43 @@ Returns the items dbus object path, as well as a path to a dbus prompt incase it
 func (c *Collection) CreateItem(fields map[string]dbus.Variant, secret SecretStruct, replace bool) (dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
 	return dbus.ObjectPath("/"), dbus.ObjectPath("/"), nil
 }
+
+// implementing method to read the object property
+func (c *Collection) Get(iface, property string) (dbus.Variant, *dbus.Error) {
+	if iface != "org/freedesktop/secret/service" {
+		return dbus.Variant{}, dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
+	}
+	switch property {
+	case "Items":
+		return dbus.MakeVariant(c.Items), nil
+	case "Label":
+		return dbus.MakeVariant(c.Label), nil
+	case "Locked":
+		return dbus.MakeVariant(c.Locked), nil
+	case "Created":
+		return dbus.MakeVariant(c.Created), nil
+	case "Modified":
+		return dbus.MakeVariant(c.Modified), nil
+	default:
+		return dbus.Variant{}, dbus.MakeFailedError(dbus.ErrMsgUnknownMethod)
+	}
+}
+
+// implementing method to read the object property
+func (c *Collection) Set(iface, property string, value dbus.Variant) *dbus.Error {
+	if iface != "org/freedesktop/secret/service" {
+		return dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
+	}
+	switch property {
+	case "Label":
+		label, ok := value.Value().(string)
+		if !ok {
+			return dbus.MakeFailedError(dbus.ErrMsgInvalidArg)
+		}
+		c.Label = label
+		return nil
+	default:
+		return dbus.MakeFailedError(dbus.ErrMsgUnknownMethod)
+	}
+
+}