فهرست منبع

working through publishing the interface properly

aeth 2 هفته پیش
والد
کامیت
057ce25175
3فایلهای تغییر یافته به همراه180 افزوده شده و 10 حذف شده
  1. 58 4
      pkg/collection.go
  2. 116 4
      pkg/service.go
  3. 6 2
      pkg/xml.go

+ 58 - 4
pkg/collection.go

@@ -5,6 +5,7 @@ import (
 	"strconv"
 
 	"github.com/godbus/dbus/v5"
+	"github.com/godbus/dbus/v5/introspect"
 )
 
 type CacheItem struct {
@@ -61,19 +62,19 @@ Searches the collection for matching items
 	:param attr: the attributes to attempt to match to a key in the collection
 */
 func (c *Collection) SearchItems(attr map[string]string) ([]dbus.ObjectPath, *dbus.Error) {
+	fmt.Println("recv call for SearchItems")
 	matched := []dbus.ObjectPath{}
 	for path, sec := range c.Cache {
 		secretAttr := sec.LookupProps
 		var passedLookup bool
-		passedLookup = true
+		passedLookup = false
 		for k, v := range attr {
 			got, ok := secretAttr[k]
 			if !ok {
-				passedLookup = false
 				continue
 			}
-			if got != v {
-				passedLookup = false
+			if got == v {
+				passedLookup = true
 				continue
 			}
 		}
@@ -157,3 +158,56 @@ func (c *Collection) Set(iface, property string, value dbus.Variant) *dbus.Error
 	}
 
 }
+
+var CollectionNode = introspect.Node{
+	Name: "/org/freedesktop/secrets/collection/default", // or your collection path
+	Interfaces: []introspect.Interface{
+		{
+			Name: "org.freedesktop.Secret.Collection",
+			Methods: []introspect.Method{
+				{
+					Name: "CreateItem",
+					Args: []introspect.Arg{
+						{Name: "properties", Type: "a{sv}", Direction: "in"},
+						{Name: "secret", Type: "v", Direction: "in"},
+						{Name: "replace", Type: "b", Direction: "in"},
+						{Name: "item", Type: "o", Direction: "out"},
+						{Name: "prompt", Type: "o", Direction: "out"},
+					},
+				},
+				{
+					Name: "SearchItems",
+					Args: []introspect.Arg{
+						{Name: "attributes", Type: "a{ss}", Direction: "in"},
+						{Name: "unlocked", Type: "ao", Direction: "out"},
+						{Name: "locked", Type: "ao", Direction: "out"},
+					},
+				},
+				{
+					Name: "Delete",
+					Args: []introspect.Arg{
+						{Name: "prompt", Type: "o", Direction: "out"},
+					},
+				},
+			},
+			Properties: []introspect.Property{
+				{Name: "Items", Type: "ao", Access: "read"},
+				{Name: "Label", Type: "s", Access: "readwrite"},
+				{Name: "Locked", Type: "b", Access: "read"},
+				{Name: "Created", Type: "t", Access: "read"},
+				{Name: "Modified", Type: "t", Access: "read"},
+			},
+		},
+		{
+			Name: "org.freedesktop.DBus.Introspectable",
+			Methods: []introspect.Method{
+				{
+					Name: "Introspect",
+					Args: []introspect.Arg{
+						{Name: "data", Type: "s", Direction: "out"},
+					},
+				},
+			},
+		},
+	},
+}

+ 116 - 4
pkg/service.go

@@ -7,9 +7,10 @@ import (
 	"time"
 
 	"github.com/godbus/dbus/v5"
+	"github.com/godbus/dbus/v5/introspect"
 )
 
-const DEFAULT_COLLECTION = "/org/freedesktop/secrets/aliases/default"
+const DEFAULT_COLLECTION = "/org/freedesktop/secrets/collections/default"
 
 type Cache struct {
 	Collections map[dbus.ObjectPath]Collection
@@ -30,7 +31,7 @@ type Service struct {
 
 // implementing method to read the object property
 func (s *Service) Get(iface, property string) (dbus.Variant, *dbus.Error) {
-	if iface != "org/freedesktop/secret/service" {
+	if iface != "/org/freedesktop/secrets/service" {
 		return dbus.Variant{}, dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
 	}
 	switch property {
@@ -43,7 +44,7 @@ func (s *Service) Get(iface, property string) (dbus.Variant, *dbus.Error) {
 
 // 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" {
+	if iface != "/org/freedesktop/secrets/service" {
 		return dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
 	}
 	switch property {
@@ -62,7 +63,7 @@ func (s *Service) Set(iface, property string, value dbus.Variant) *dbus.Error {
 
 // 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" {
+	if iface != "/org/freedesktop/secrets/service" {
 		return nil, dbus.MakeFailedError(dbus.ErrMsgUnknownInterface)
 	}
 
@@ -143,6 +144,7 @@ Creates a collection with the Service object
 	:param alias: the shortname of the collection
 */
 func (s *Service) CreateCollection(properties map[string]dbus.Variant, alias string) (dbus.ObjectPath, dbus.ObjectPath, *dbus.Error) {
+	fmt.Printf("CreateCollection called with: %+v (alias: %s)\n", properties, alias)
 	collPath := dbus.ObjectPath(path.Join(s.CollectionBase, strconv.Itoa(s.PathCount+1)))
 	s.Collections = append(s.Collections, collPath)
 	s.PathCount = s.PathCount + 1
@@ -222,3 +224,113 @@ func (s *Service) SetAlias(name string, collection dbus.ObjectPath) *dbus.Error
 	return nil
 
 }
+
+var ServiceNode = introspect.Node{
+	Interfaces: []introspect.Interface{
+		{
+			Name: "org.freedesktop.Secret.Service",
+			Methods: []introspect.Method{
+				{
+					Name: "OpenSession",
+					Args: []introspect.Arg{
+						{Name: "algorithm", Type: "s", Direction: "in"},
+						{Name: "input", Type: "v", Direction: "in"},
+						{Name: "output", Type: "(sv)", Direction: "out"},
+						{Name: "session_path", Type: "o", Direction: "out"},
+					},
+				},
+				{
+					Name: "CreateCollection",
+					Args: []introspect.Arg{
+						{Name: "properties", Type: "a{sv}", Direction: "in"},
+						{Name: "alias", Type: "s", Direction: "in"},
+						{Name: "collection", Type: "o", Direction: "out"},
+						{Name: "prompt", Type: "o", Direction: "out"},
+					},
+				},
+				{
+					Name: "SearchItems",
+					Args: []introspect.Arg{
+						{Name: "attributes", Type: "a{ss}", Direction: "in"},
+						{Name: "locked", Type: "ao", Direction: "out"},
+						{Name: "unlocked", Type: "ao", Direction: "out"},
+					},
+				},
+				{
+					Name: "Unlock",
+					Args: []introspect.Arg{
+						{Name: "objects", Type: "ao", Direction: "in"},
+						{Name: "unlocked", Type: "ao", Direction: "out"},
+						{Name: "prompt", Type: "o", Direction: "out"},
+					},
+				},
+				{
+					Name: "Lock",
+					Args: []introspect.Arg{
+						{Name: "objects", Type: "ao", Direction: "in"},
+						{Name: "locked", Type: "ao", Direction: "out"},
+						{Name: "prompt", Type: "o", Direction: "out"},
+					},
+				},
+				{
+					Name: "GetSecrets",
+					Args: []introspect.Arg{
+						{Name: "items", Type: "ao", Direction: "in"},
+						{Name: "session", Type: "o", Direction: "in"},
+						{Name: "secrets", Type: "a{oa(yays)}", Direction: "out"},
+					},
+				},
+				{
+					Name: "ReadAlias",
+					Args: []introspect.Arg{
+						{Name: "name", Type: "s", Direction: "in"},
+						{Name: "collection", Type: "o", Direction: "out"},
+					},
+				},
+				{
+					Name: "SetAlias",
+					Args: []introspect.Arg{
+						{Name: "name", Type: "s", Direction: "in"},
+						{Name: "collection", Type: "o", Direction: "in"},
+					},
+				},
+			},
+			Properties: []introspect.Property{
+				{
+					Name:   "Collections",
+					Type:   "ao",
+					Access: "read",
+				},
+			},
+		},
+		{
+			Name: "org.freedesktop.DBus.Properties",
+			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"},
+					},
+				},
+			},
+		},
+		introspect.IntrospectData,
+	},
+}

+ 6 - 2
pkg/xml.go

@@ -4,8 +4,8 @@ import (
 	"github.com/godbus/dbus/v5/introspect"
 )
 
-const DbusAdv = `
-<node>
+const CollectionAdv = `
+
 	  <interface name="org.freedesktop.Secret.Collection">
 
 		<property name="Label" type="s" access="readwrite"/>
@@ -44,6 +44,10 @@ const DbusAdv = `
 		  <arg name="item" type="o"/>
 		</signal>
 	</interface>
+`
+
+const DbusAdv = `
+<node>
 
 	<interface name="org.freedesktop.Secret.Service">
 		<method name="OpenSession">