-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession.go
50 lines (40 loc) · 1.33 KB
/
session.go
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
// Copyright 2019 Patrick Pacher. All rights reserved. Use of
// this source code is governed by the included Simplified BSD license.
package keyring
import (
"github.com/godbus/dbus/v5"
)
const (
sessionMethodClose = SessionInterface + ".Close"
)
// Session allows to interact with the Session interface of Freedesktop.org's Secret Service API
// The session interface is defined at https://specifications.freedesktop.org/secret-service/re01.html
type Session interface {
// Path returns the object path of the session
// To get a new session use SecretService.OpenSession()
Path() dbus.ObjectPath
// Close closes the session
Close() error
}
// GetSession returns a new Session for the provided path. Note that session must be opened beforehand
// Use SecretService.OpenSession() to open a new session and return a Session client
func GetSession(conn *dbus.Conn, path dbus.ObjectPath) (Session, error) {
obj := conn.Object(SecretServiceDest, dbus.ObjectPath(path))
return &session{
path: path,
obj: obj,
}, nil
}
// session implements the Session interface
type session struct {
path dbus.ObjectPath
obj dbus.BusObject
}
// Path returns the ObjectPath of the session
func (s *session) Path() dbus.ObjectPath {
return s.path
}
// Close closes the session
func (s *session) Close() error {
return s.obj.Call(sessionMethodClose, 0).Err
}