This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Connection.go
71 lines (51 loc) · 1.54 KB
/
Connection.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gonetworkmanager
import (
"encoding/json"
"github.com/godbus/dbus"
)
const (
ConnectionInterface = SettingsInterface + ".Connection"
ConnectionGetSettings = ConnectionInterface + ".GetSettings"
ConnectionDelete = ConnectionInterface + ".Delete"
)
//type ConnectionSettings map[string]map[string]interface{}
type ConnectionSettings map[string]map[string]interface{}
type Connection interface {
GetPath() dbus.ObjectPath
// GetSettings gets the settings maps describing this network configuration.
// This will never include any secrets required for connection to the
// network, as those are often protected. Secrets must be requested
// separately using the GetSecrets() call.
GetSettings() ConnectionSettings
// Delete will delete the connection
Delete()
MarshalJSON() ([]byte, error)
}
func NewConnection(objectPath dbus.ObjectPath) (Connection, error) {
var c connection
return &c, c.init(NetworkManagerInterface, objectPath)
}
type connection struct {
dbusBase
}
func (c *connection) GetPath() dbus.ObjectPath {
return c.obj.Path()
}
func (c *connection) GetSettings() ConnectionSettings {
var settings map[string]map[string]dbus.Variant
c.call(&settings, ConnectionGetSettings)
rv := make(ConnectionSettings)
for k1, v1 := range settings {
rv[k1] = make(map[string]interface{})
for k2, v2 := range v1 {
rv[k1][k2] = v2.Value()
}
}
return rv
}
func (c *connection) Delete() {
c.call(c.GetPath(), ConnectionDelete)
}
func (c *connection) MarshalJSON() ([]byte, error) {
return json.Marshal(c.GetSettings())
}