2021-11-21 23:05:13 -05:00
|
|
|
package gosecret
|
2021-11-21 18:07:52 -05:00
|
|
|
|
|
|
|
import (
|
2021-12-25 01:51:49 -05:00
|
|
|
"fmt"
|
|
|
|
|
2021-12-06 03:24:55 -05:00
|
|
|
"github.com/godbus/dbus/v5"
|
2021-11-21 18:07:52 -05:00
|
|
|
)
|
|
|
|
|
2021-12-06 03:24:55 -05:00
|
|
|
// I'm still not 100% certain what Sessions are used for, aside from getting Secrets from Items.
|
2021-12-04 19:38:26 -05:00
|
|
|
|
2021-12-04 02:34:45 -05:00
|
|
|
/*
|
|
|
|
NewSession returns a pointer to a new Session based on a Service and a dbus.ObjectPath.
|
2021-12-06 03:24:55 -05:00
|
|
|
You will almost always want to use Service.GetSession or Service.OpenSession instead.
|
2021-12-04 02:34:45 -05:00
|
|
|
*/
|
2021-12-08 02:34:27 -05:00
|
|
|
func NewSession(service *Service, path dbus.ObjectPath) (session *Session, err error) {
|
|
|
|
|
|
|
|
if _, err = validConnPath(service.Conn, path); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-11-21 18:07:52 -05:00
|
|
|
|
2021-12-04 02:34:45 -05:00
|
|
|
var ssn Session = Session{
|
2021-12-06 03:24:55 -05:00
|
|
|
DbusObject: &DbusObject{
|
2021-12-04 02:34:45 -05:00
|
|
|
Conn: service.Conn,
|
2021-11-30 02:33:07 -05:00
|
|
|
},
|
2021-12-06 03:24:55 -05:00
|
|
|
service: service,
|
2021-11-21 18:07:52 -05:00
|
|
|
}
|
2021-12-07 02:56:15 -05:00
|
|
|
ssn.Dbus = ssn.Conn.Object(DbusInterfaceSession, path)
|
2021-12-04 02:34:45 -05:00
|
|
|
|
|
|
|
session = &ssn
|
2021-11-21 18:07:52 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-04 02:34:45 -05:00
|
|
|
// Close cleanly closes a Session.
|
|
|
|
func (s *Session) Close() (err error) {
|
|
|
|
|
2021-12-25 01:51:49 -05:00
|
|
|
var call *dbus.Call
|
2021-12-04 02:34:45 -05:00
|
|
|
|
2021-12-25 01:51:49 -05:00
|
|
|
if call = s.Dbus.Call(
|
2021-12-04 02:34:45 -05:00
|
|
|
DbusSessionClose, 0,
|
2021-12-25 01:51:49 -05:00
|
|
|
); call.Err != nil {
|
|
|
|
/*
|
|
|
|
I... still haven't 100% figured out why this happens, but the session DOES seem to close...?
|
|
|
|
PRs or input welcome.
|
|
|
|
TODO: figure out why this error gets triggered.
|
|
|
|
*/
|
|
|
|
if call.Err.Error() != fmt.Sprintf("The name %v was not provided by any .service files", DbusInterfaceSession) {
|
|
|
|
err = call.Err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-11-21 18:07:52 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2021-12-13 04:04:03 -05:00
|
|
|
|
|
|
|
// path is a *very* thin wrapper around Session.Dbus.Path().
|
|
|
|
func (s *Session) path() (dbusPath dbus.ObjectPath) {
|
|
|
|
|
|
|
|
dbusPath = s.Dbus.Path()
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|