Add VpnConnection
Update ActivateConnection to support empty Device Add ActivateConnection specific object (BREAKING CHANGE)
This commit is contained in:
parent
0369d842fa
commit
41ad7838fe
2 changed files with 69 additions and 4 deletions
|
@ -77,7 +77,7 @@ type NetworkManager interface {
|
||||||
GetDeviceByIpIface(interfaceId string) (Device, error)
|
GetDeviceByIpIface(interfaceId string) (Device, error)
|
||||||
|
|
||||||
// Activate a connection using the supplied device.
|
// Activate a connection using the supplied device.
|
||||||
ActivateConnection(connection Connection, device Device) (ActiveConnection, error)
|
ActivateConnection(connection Connection, device Device, s *dbus.Object) (ActiveConnection, error)
|
||||||
|
|
||||||
// Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device), then activate the new connection. Cannot be used for VPN connections at this time.
|
// Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device), then activate the new connection. Cannot be used for VPN connections at this time.
|
||||||
AddAndActivateConnection(connection map[string]map[string]interface{}, device Device) (ActiveConnection, error)
|
AddAndActivateConnection(connection map[string]map[string]interface{}, device Device) (ActiveConnection, error)
|
||||||
|
@ -282,9 +282,24 @@ func (nm *networkManager) GetDeviceByIpIface(interfaceId string) (device Device,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nm *networkManager) ActivateConnection(c Connection, d Device) (ac ActiveConnection, err error) {
|
func (nm *networkManager) ActivateConnection(c Connection, d Device, s *dbus.Object) (ac ActiveConnection, err error) {
|
||||||
var opath dbus.ObjectPath
|
var opath dbus.ObjectPath
|
||||||
err = nm.callWithReturn(&opath, NetworkManagerActivateConnection, c.GetPath(), d.GetPath(), dbus.ObjectPath("/"))
|
|
||||||
|
var devicePath dbus.ObjectPath
|
||||||
|
if d != nil {
|
||||||
|
devicePath = d.GetPath()
|
||||||
|
} else {
|
||||||
|
devicePath = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
var specificObjectPath dbus.ObjectPath
|
||||||
|
if s != nil {
|
||||||
|
specificObjectPath = s.Path()
|
||||||
|
} else {
|
||||||
|
specificObjectPath = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
err = nm.callWithReturn(&opath, NetworkManagerActivateConnection, c.GetPath(), devicePath, specificObjectPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -301,7 +316,12 @@ func (nm *networkManager) AddAndActivateConnection(connection map[string]map[str
|
||||||
var opath1 dbus.ObjectPath
|
var opath1 dbus.ObjectPath
|
||||||
var opath2 dbus.ObjectPath
|
var opath2 dbus.ObjectPath
|
||||||
|
|
||||||
err = nm.callWithReturn2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, d.GetPath(), dbus.ObjectPath("/"))
|
var devicePath dbus.ObjectPath
|
||||||
|
if d != nil {
|
||||||
|
devicePath = d.GetPath()
|
||||||
|
}
|
||||||
|
|
||||||
|
err = nm.callWithReturn2(&opath1, &opath2, NetworkManagerAddAndActivateConnection, connection, devicePath, dbus.ObjectPath("/"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
45
VpnConnection.go
Normal file
45
VpnConnection.go
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package gonetworkmanager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
VpnConnectionInterface = NetworkManagerInterface + ".VPN.Connection"
|
||||||
|
|
||||||
|
/* Properties */
|
||||||
|
VpnConnectionPropertyVpnState = VpnConnectionInterface + ".VpnState" // readable u
|
||||||
|
VpnConnectionPropertyBanner = VpnConnectionInterface + ".Banner" // readable s
|
||||||
|
)
|
||||||
|
|
||||||
|
type VpnConnection interface {
|
||||||
|
GetPath() dbus.ObjectPath
|
||||||
|
|
||||||
|
// The VPN-specific state of the connection.
|
||||||
|
GetPropertyVpnState() (NmVpnConnectionState, error)
|
||||||
|
|
||||||
|
// The banner string of the VPN connection.
|
||||||
|
GetPropertyBanner() (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVpnConnection(objectPath dbus.ObjectPath) (VpnConnection, error) {
|
||||||
|
var a vpnConnection
|
||||||
|
return &a, a.init(NetworkManagerInterface, objectPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
type vpnConnection struct {
|
||||||
|
dbusBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *vpnConnection) GetPath() dbus.ObjectPath {
|
||||||
|
return a.obj.Path()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *vpnConnection) GetPropertyVpnState() (NmVpnConnectionState, error) {
|
||||||
|
v, err := a.getUint32Property(VpnConnectionPropertyVpnState)
|
||||||
|
return NmVpnConnectionState(v), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *vpnConnection) GetPropertyBanner() (string, error) {
|
||||||
|
return a.getStringProperty(VpnConnectionPropertyBanner)
|
||||||
|
}
|
Reference in a new issue