summaryrefslogtreecommitdiff
path: root/vendor/github.com/gsterjov/go-libsecret/item.go
blob: f0e6ad3cd8fa2ce98292142fd1716dc84c80d2d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package libsecret

import "github.com/godbus/dbus"


type Item struct {
  conn *dbus.Conn
  dbus  dbus.BusObject
}


func NewItem(conn *dbus.Conn, path dbus.ObjectPath) *Item {
  return &Item{
    conn: conn,
    dbus: conn.Object(DBusServiceName, path),
  }
}


func (item Item) Path() dbus.ObjectPath {
  return item.dbus.Path()
}


// READWRITE String Label;
func (item *Item) Label() (string, error) {
  val, err := item.dbus.GetProperty("org.freedesktop.Secret.Item.Label")
  if err != nil {
    return "", err
  }

  return val.Value().(string), nil
}


// READ Boolean Locked;
func (item *Item) Locked() (bool, error) {
  val, err := item.dbus.GetProperty("org.freedesktop.Secret.Item.Locked")
  if err != nil {
    return true, err
  }

  return val.Value().(bool), nil
}


// GetSecret (IN ObjectPath session, OUT Secret secret);
func (item *Item) GetSecret(session *Session) (*Secret, error) {
  secret := Secret{}

  err := item.dbus.Call("org.freedesktop.Secret.Item.GetSecret", 0, session.Path()).Store(&secret)
  if err != nil {
    return &Secret{}, err
  }

  return &secret, nil
}


// Delete (OUT ObjectPath Prompt);
func (item *Item) Delete() error {
  var prompt dbus.ObjectPath

  err := item.dbus.Call("org.freedesktop.Secret.Item.Delete", 0).Store(&prompt)
  if err != nil {
    return err
  }

  if isPrompt(prompt) {
    prompt := NewPrompt(item.conn, prompt)
    if _, err := prompt.Prompt(); err != nil {
      return err
    }
  }

  return nil
}