Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect return type for NetworkManager.GetPropertyPrimaryConnection #21

Closed
ijc opened this issue Apr 28, 2021 · 0 comments
Closed

Incorrect return type for NetworkManager.GetPropertyPrimaryConnection #21

ijc opened this issue Apr 28, 2021 · 0 comments

Comments

@ijc
Copy link

ijc commented Apr 28, 2021

The NetworkManager.PrimaryConnect property contains:

The object path of the "primary" active connection being used to access the network.

However the NetworkManager.GetPropertyPrimaryConnection binding is:

	GetPropertyPrimaryConnection() (Connection, error)

Which is incorrect, it should be ActiveConnection I believe.

Example code

package main

import (
	"fmt"

	nm "github.com/Wifx/gonetworkmanager"
)

func main() {
	// https://pkg.go.dev/github.com/Wifx/gonetworkmanager#NetworkManager
	nmManager, err := nm.NewNetworkManager()
	if err != nil {
		panic(err)
	}

	// Returns https://pkg.go.dev/github.com/Wifx/gonetworkmanager#Connection
	p, err := nmManager.GetPropertyPrimaryConnection()
	if err != nil {
		panic(err)
	}

	// This fails with "No such interface" because the underlying object is an "ActiveConnection" but we try to treat it as a "Connection"
	if s, err := p.GetSettings(); err != nil {
		// No such interface “org.freedesktop.NetworkManager.Settings.Connection” on object at path /org/freedesktop/NetworkManager/ActiveConnection/330
		fmt.Printf("GetSettings: %v\n", err)
	} else {
		fmt.Printf("GetSettings: settings has %d keys\n", len(s))
	}

	// Convert to a https://pkg.go.dev/github.com/Wifx/gonetworkmanager#ActiveConnection
	ac, err := nm.NewActiveConnection(p.GetPath())
	if err != nil {
		panic(err)
	}

	if t, err := ac.GetPropertyType(); err != nil {
		panic(err)
	} else {
		fmt.Printf("GetPropertyType: %v\n", t)
	}

	p, err = ac.GetPropertyConnection()
	if err != nil {
		panic(err)
	}

	if s, err := p.GetSettings(); err != nil {
		// No such interface “org.freedesktop.NetworkManager.Settings.Connection” on object at path /org/freedesktop/NetworkManager/ActiveConnection/330
		fmt.Printf("GetSettings: %v\n", err)
	} else {
		fmt.Printf("GetSettings: settings has %d keys\n", len(s))
	}
}

The output is:

$ go run ./
GetSettings: No such interface “org.freedesktop.NetworkManager.Settings.Connection” on object at path /org/freedesktop/NetworkManager/ActiveConnection/330
GetPropertyType: 802-3-ethernet
GetSettings: settings has 5 keys

The first p.GetSettings() (line 23) fails with "No such interface" but after conversion to a ActiveConnection methods work and we can then obtain an actual connection from it and the second p.GetSettings() (line 47) on the right object type works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants