Wifx / gonetworkmanager

Go D-Bus bindings for NetworkManager
Other
96 stars 42 forks source link

Settings.GetConnectionByUuid() method not yet implemented #12

Closed paulburlumi closed 4 years ago

paulburlumi commented 4 years ago

The GetConnectionByUuid method appears not be implemented yet.

As a workaround I wrote:

func getConnection(wantedUUID string) (gonetworkmanager.Connection, error) {
    settings, err := gonetworkmanager.NewSettings()
    if err != nil {
        return nil, fmt.Errorf("NewSettings failed: %v", err)
    }

    connections, err := settings.ListConnections()
    for _, c := range connections {
        settings, err := c.GetSettings()
        if err != nil {
            return nil, fmt.Errorf("GetSettings failed: %v", err)
        }

        uuid, ok := settings["connection"]["uuid"].(string)
        if !ok {
            return nil, fmt.Errorf("got data of type %T, but wanted string", uuid)
        }

        if uuid == wantedUUID {
            return c, nil
        }
    }

    return nil, fmt.Errorf("connection with uuid: %s not found, exiting", wantedUUID)
}
mullerch commented 4 years ago

Hi Paul,

Can you please make a pull request so you I can test and merge this and credits are made accordingly?

Thanks