For a feature I’m working on, I needed to check whether a particular named snap was plugged into a particular interface type, which means hitting the /v2/interfaces
REST API.
Looking at the code, this endpoint can produce two forms of data:
- the
getLegacyConnections
mode where it produces information about every connected interface on the system. This is whatsnap interfaces
uses. - the
getInterfaces
mode, which produces information in a slightly different format and supports filtering the data. This is whatsnap interface
uses.
Minimising the data I need to parse and filter seemed like a good idea, and looking at the Go client’s InterfaceOptions
struct, it looked like I’d want to pass the following query parameters:
-
names=$type
to restrict the output to the particular interface type I’m interested in. -
plugs=true
to return plugs associated with the selected interface type(s). -
select=connected
to restrict the output to connected interfaces.
However, this last option didn’t quite do what I expected. I had hoped that it would limit the output to connected plugs/slots. But it seems that if an interface type has at least one connected plug/slot, then all associated plugs/slots are returned with no way to distinguish the state.
For example, using the current stable release (2.33.1):
$ curl --unix-socket /run/snapd.socket 'http://foo/v2/interfaces?names=removable-media&plugs=true&select=connected' | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 329 100 329 0 0 321k 0 --:--:-- --:--:-- --:--:-- 321k
{
"type": "sync",
"status-code": 200,
"status": "OK",
"result": [
{
"name": "removable-media",
"summary": "allows access to mounted removable storage",
"plugs": [
{
"snap": "firefox",
"plug": "removable-media"
},
{
"snap": "hugo",
"plug": "removable-media"
},
{
"snap": "keepassxc",
"plug": "removable-media"
},
{
"snap": "libreoffice",
"plug": "removable-media"
}
]
}
]
}
… only keepassxc
and libreoffice
are connected with the other two disconnected.
Is this intended behaviour? I can’t think of a case where this behaviour would be particularly useful, but maybe I’m not imaginative enough
Also, if one output mode is referred to as getLegacyConnections
, should it be considered a bug that you can’t get the equivalent information from the non-legacy interface?