Browse Source

merging with upstream

aeth 2 weeks ago
parent
commit
a29564f47e
3 changed files with 113 additions and 31 deletions
  1. 30 0
      main.go
  2. 40 31
      pkg/collection.go
  3. 43 0
      pkg/service.go

+ 30 - 0
main.go

@@ -24,8 +24,38 @@ func main() {
 
 	conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), dbus.ObjectPath(path),
 		"org.freedesktop.DBus.Introspectable")
+<<<<<<< HEAD
 	conn.Export(introspect.Introspectable(keychainlinker.DbusAdv), "/org/freedesktop/secrets/collection/default", "org.freedesktop.DBus.Introspectable")
 	reply, err := conn.RequestName("org.freedesktop.secrets",
+=======
+	node := introspect.Node{
+		Interfaces: []introspect.Interface{
+			{
+				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"}}},
+					{Name: "GetAll", Args: []introspect.Arg{{Name: "interface_name", Type: "s", Direction: "in"}, {Name: "props", Type: "a{sv}", Direction: "out"}}},
+				},
+			},
+		},
+	}
+	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",
+>>>>>>> 2946fa107c12a5e2d1c88f3b60f8bea802b19fd7
 		dbus.NameFlagDoNotQueue)
 	if err != nil {
 		panic(err)

+ 40 - 31
pkg/collection.go

@@ -29,37 +29,6 @@ type Collection struct {
 	Modified  uint64 //  The unix time when the collection was last modified.
 }
 
-func (c *Collection) Get(iface, property string) (dbus.Variant, *dbus.Error) {
-	if iface != "org.freedesktop.Secret.Collection" {
-		return dbus.Variant{}, dbus.MakeFailedError(fmt.Errorf("no such property"))
-	}
-	switch property {
-	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
-	case "Items":
-		return dbus.MakeVariant(c.Items), nil
-	}
-	return dbus.Variant{}, dbus.MakeFailedError(fmt.Errorf("no such property"))
-
-}
-
-func (c *Collection) Set(iface, property string, value dbus.Variant) *dbus.Error {
-	if iface == "org.freedesktop.Secret.Collection" && property == "Label" {
-		if label, ok := value.Value().(string); ok {
-			c.Label = label
-			return nil
-		}
-		return dbus.MakeFailedError(fmt.Errorf("invalid type"))
-	}
-	return dbus.MakeFailedError(fmt.Errorf("no such property"))
-}
-
 func (c *Collection) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error) {
 	if iface == "org.freedesktop.Secret.Collection" {
 		return map[string]dbus.Variant{
@@ -148,3 +117,43 @@ func (c *Collection) CreateItem(props map[string]dbus.Variant, secret SecretStru
 
 	return path, 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)
+	}
+
+}

+ 43 - 0
pkg/service.go

@@ -28,6 +28,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
+}
+
 /*
 implementing the properties interface
 func (s *Service) Get(iface, property string) (dbus.Variant, *dbus.Error) {