checking in some new funcs for Service

This commit is contained in:
brent s. 2021-12-04 02:34:45 -05:00
parent 1d9145bcf2
commit c0a1e4a281
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
3 changed files with 82 additions and 15 deletions

View File

@ -21,6 +21,7 @@ const (
/* /*
DbusServiceChangeLock has some references in the SecretService Dbus API but DbusServiceChangeLock has some references in the SecretService Dbus API but
it seems to be obsolete - undocumented, at the least. it seems to be obsolete - undocumented, at the least.
So we don't implement it.
*/ */
// DbusServiceChangeLock string = DbusInterfaceService + ".ChangeLock" // DbusServiceChangeLock string = DbusInterfaceService + ".ChangeLock"


@ -33,7 +34,7 @@ const (
// DbusServiceLock is used by Service.Lock. // DbusServiceLock is used by Service.Lock.
DbusServiceLock string = DbusInterfaceService + ".Lock" DbusServiceLock string = DbusInterfaceService + ".Lock"


// DbusServiceLockService is [FUNCTION UNKNOWN/UNDOCUMENTED; TODO.] // DbusServiceLockService is [FUNCTION UNKNOWN/UNDOCUMENTED; TODO? NOT IMPLEMENTED.]
DbusServiceLockService string = DbusInterfaceService + ".LockService" DbusServiceLockService string = DbusInterfaceService + ".LockService"


// DbusServiceOpenSession is used by Service.Open. // DbusServiceOpenSession is used by Service.Open.
@ -48,12 +49,12 @@ const (
// DbusServiceSetAlias is used by Service.SetAlias to set an alias for a Collection. // DbusServiceSetAlias is used by Service.SetAlias to set an alias for a Collection.
DbusServiceSetAlias string = DbusInterfaceService + ".SetAlias" DbusServiceSetAlias string = DbusInterfaceService + ".SetAlias"


// DbusServiceUnlock is used to unlock a Service. // DbusServiceUnlock is used by Service.Unlock.
DbusServiceUnlock string = DbusInterfaceService + ".Unlock" DbusServiceUnlock string = DbusInterfaceService + ".Unlock"


// Properties // Properties


// DbusServiceCollections is used to get a Dbus array of Collection items. // DbusServiceCollections is used to get a Dbus array of Collection items (Service.Collections).
DbusServiceCollections string = DbusInterfaceService + ".Collections" DbusServiceCollections string = DbusInterfaceService + ".Collections"
) )



View File

@ -23,6 +23,14 @@ func NewService() (service *Service, err error) {
return return
} }


// Close cleanly closes a Service and all its underlying connections (e.g. Service.Session).
func (s *Service) Close() (err error) {

err = s.Session.Close()

return
}

// Collections returns a slice of Collection items accessible to this Service. // Collections returns a slice of Collection items accessible to this Service.
func (s *Service) Collections() (collections []Collection, err error) { func (s *Service) Collections() (collections []Collection, err error) {


@ -99,6 +107,20 @@ func (s *Service) CreateCollection(label string) (collection *Collection, err er
return return
} }


/*
GetAlias allows one to fetch a Collection dbus.ObjectPath based on an alias name.
If the alias does not exist, objectPath will be dbus.ObjectPath("/").
TODO: return a Collection instead of a dbus.ObjectPath.
*/
func (s *Service) GetAlias(alias string) (objectPath dbus.ObjectPath, err error) {

err = s.Dbus.Call(
DbusServiceReadAlias, 0, alias,
).Store(&objectPath)

return
}

/* /*
GetSecrets allows you to fetch values (Secret) from multiple Item object paths using this Service's Session. GetSecrets allows you to fetch values (Secret) from multiple Item object paths using this Service's Session.
An ErrMissingPaths will be returned for err if itemPaths is nil or empty. An ErrMissingPaths will be returned for err if itemPaths is nil or empty.
@ -169,7 +191,10 @@ func (s *Service) Lock(objectPaths ...dbus.ObjectPath) (err error) {
return return
} }


// Open returns a pointer to a Session from the Service. /*
Open returns a pointer to a Session from the Service.
It's a convenience function around NewSession.
*/
func (s *Service) Open() (session *Session, output dbus.Variant, err error) { func (s *Service) Open() (session *Session, output dbus.Variant, err error) {


var path dbus.ObjectPath var path dbus.ObjectPath
@ -179,12 +204,43 @@ func (s *Service) Open() (session *Session, output dbus.Variant, err error) {
// Possible flags are dbus.Flags consts: https://pkg.go.dev/github.com/godbus/dbus#Flags // Possible flags are dbus.Flags consts: https://pkg.go.dev/github.com/godbus/dbus#Flags
// Oddly, there is no "None" flag. So it's explicitly specified as a null byte. // Oddly, there is no "None" flag. So it's explicitly specified as a null byte.
if err = s.Dbus.Call( if err = s.Dbus.Call(
DbusServiceOpenSession, 0x0, "plain", dbus.MakeVariant(""), DbusServiceOpenSession, 0, "plain", dbus.MakeVariant(""),
).Store(&output, &path); err != nil { ).Store(&output, &path); err != nil {
return return
} }


session = NewSession(s.Conn, path) session = NewSession(s, path)

return
}

/*
SearchItems searches all Collection objects and returns all matches based on the map of attributes.
TODO: return arrays of Items instead of dbus.ObjectPaths.
TODO: check attributes for empty/nil.
*/
func (s *Service) SearchItems(attributes map[string]string) (unlockedItems []dbus.ObjectPath, lockedItems []dbus.ObjectPath, err error) {

err = s.Dbus.Call(
DbusServiceSearchItems, 0, attributes,
).Store(&unlockedItems, &lockedItems)

return
}

/*
SetAlias sets an alias for an existing Collection.
To remove an alias, set objectPath to dbus.ObjectPath("/").
*/
func (s *Service) SetAlias(alias string, objectPath dbus.ObjectPath) (err error) {

var c *dbus.Call

c = s.Dbus.Call(
DbusServiceSetAlias, 0, alias, objectPath,
)

_ = c


return return
} }

View File

@ -4,24 +4,34 @@ import (
"github.com/godbus/dbus" "github.com/godbus/dbus"
) )


// NewSession returns a pointer to a new Session based on a Dbus connection and a Dbus path. /*
func NewSession(conn *dbus.Conn, path dbus.ObjectPath) (session *Session) { NewSession returns a pointer to a new Session based on a Service and a dbus.ObjectPath.
If path is empty (""), the default
*/
func NewSession(service *Service, path dbus.ObjectPath) (session *Session) {


session = &Session{ var ssn Session = Session{
&DbusObject{ &DbusObject{
Conn: conn, Conn: service.Conn,
Dbus: conn.Object(DbusService, path),
}, },
} }
session.Dbus = session.Conn.Object(DbusInterfaceSession, path)

session = &ssn


return return
} }


// Path returns the path of the underlying Dbus connection. // Close cleanly closes a Session.
func (s Session) Path() (path dbus.ObjectPath) { func (s *Session) Close() (err error) {


// Remove this method in V1. It's bloat since we now have an exported Dbus. var c *dbus.Call
path = s.Dbus.Path()
c = s.Dbus.Call(
DbusSessionClose, 0,
)

_ = c


return return
} }