2021-11-21 23:05:13 -05:00
|
|
|
package gosecret
|
2021-11-21 18:07:52 -05:00
|
|
|
|
|
|
|
import (
|
2021-12-06 03:24:55 -05:00
|
|
|
`github.com/godbus/dbus/v5`
|
2021-11-21 18:07:52 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewPrompt returns a pointer to a new Prompt based on a Dbus connection and a Dbus path.
|
|
|
|
func NewPrompt(conn *dbus.Conn, path dbus.ObjectPath) (prompt *Prompt) {
|
|
|
|
|
|
|
|
prompt = &Prompt{
|
2021-12-06 03:24:55 -05:00
|
|
|
DbusObject: &DbusObject{
|
|
|
|
Conn: conn,
|
|
|
|
Dbus: conn.Object(DbusService, path),
|
|
|
|
},
|
2021-11-21 18:07:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt issues/waits for a prompt for unlocking a Locked Collection or Secret / Item.
|
|
|
|
func (p *Prompt) Prompt() (promptValue *dbus.Variant, err error) {
|
|
|
|
|
|
|
|
var c chan *dbus.Signal
|
|
|
|
var result *dbus.Signal
|
|
|
|
|
2021-12-10 02:50:30 -05:00
|
|
|
promptValue = new(dbus.Variant)
|
|
|
|
|
2021-11-21 18:07:52 -05:00
|
|
|
// Prompts are asynchronous; we connect to the signal and block with a channel until we get a response.
|
|
|
|
c = make(chan *dbus.Signal, 10)
|
|
|
|
defer close(c)
|
|
|
|
|
|
|
|
p.Conn.Signal(c)
|
|
|
|
defer p.Conn.RemoveSignal(c)
|
|
|
|
|
2021-12-06 03:24:55 -05:00
|
|
|
if err = p.Dbus.Call(
|
2021-12-10 02:50:30 -05:00
|
|
|
DbusPrompterInterface, 0, "GoSecret.Prompt", // TODO: This last argument, the string, is for "window ID". I'm unclear what for.
|
2021-12-06 03:24:55 -05:00
|
|
|
).Store(); err != nil {
|
2021-11-21 18:07:52 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2021-12-06 03:24:55 -05:00
|
|
|
if result = <-c; result.Path == p.Dbus.Path() {
|
2021-11-21 18:07:52 -05:00
|
|
|
*promptValue = result.Body[1].(dbus.Variant)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|