Repository navigation
hostnamed: add JSON output to hostnamectl - #19451
Conversation
a2ae416 to
545e8a8
Compare
| SD_BUS_PARAM(uuid), | ||
| method_get_product_uuid, | ||
| SD_BUS_VTABLE_UNPRIVILEGED), | ||
| SD_BUS_METHOD_WITH_NAMES("Describe", |
There was a problem hiding this comment.
Why Describe is method, rather than property?
Maybe, it is better to use SD_BUS_METHOD_WITH_ARGS macro.
There was a problem hiding this comment.
Three reasons:
-
Properties must be quick to query, shouldn't fail to query. This is implied by clients such as gdbus that query/cache them. However, here we actually ask Polkit for auth if the client is unprivileged, and if the auth works we'll include the product uuid in it, and if not we set
nullinstead. Doing polkit already means: you cannot expose this as property. I mean, that's why GetProductUUID() is a method and not a property, already. -
The data is quite comprehensive, and redundant. Exposing large fields as props is a bit icky, since clients query them with GetAllProperties(), under the assumption that's reasonably cheap and not redundant. But pretty much everything we expose here is already available as dbus property, hence it doesn't bring much to the table if it is a property except it's redundant as property.
-
I think philosophically Describe() is a lot like GetAllProperties(), i.e. it's an API to get a full description of the object. People should choose one, or the other way to get, but it if we'd nest one in the other, by making the JSON description a property, then they couldn't choose. i.e. we want these to be alternative ways to query the data, and not make one a primary concept and the other a secondary concept tied to it.
Does that make sense?
There was a problem hiding this comment.
Yeah, Thanks. I will also try to implement Describe() in networkd.
There was a problem hiding this comment.
I tried to use SD_BUS_METHOD_WITH_ARGS, but it doesn't work, and I don't grok C preprocessor stuff well enough to fix it. see #19468
There was a problem hiding this comment.
Hmm... OK. let's convert to SD_BUS_METHOD_WITH_ARGS after #19468 is fixed.
bluca
left a comment
There was a problem hiding this comment.
looks good to me, just a couple minor comments
|
as per usual, would be good to have integration tests for this - unfortunately there's very little coverage of hostnamed under test/, just something in test/networkd-test.py to check the hostname |
it's more corect this way, but shouldn#t change a thing binary-wise
No changes in code, just some splitting out of code we want to use elsewhere soon.
This wraps the new Describe() bus call of hostnamed.
545e8a8 to
97a7243
Compare
integration tests? what's that? ;-) |
|
Force pushed a new version, addressing the raised issues. The dbus interface docs need updating once #19468 is addressed, but I'd consider that a separate issue. Upgrading green label, since these were such minor changes. |
|
CI failures appear unrelated. |
This is inspired by various PRs that are curently pending: we probably need a nice way how we can systematically provide a parsable interface in our tool. Given we have structured data to output I figure this should be JSON.
Now, we could convert to JSON client side, but that's always lossy, and means we'd propagate D-Bus semantics into JSON. Moreover if we add varlink interfaces later on anyway, it makes sense to generate the data in JSON right-away.
So this is more than just a specific implementation of this idea for hostnamed: it's a proposal that all across the board we should add a "Describe" method like here to all objects we maintain, that return a comprehensive JSON description of the object in question. The tools should then retrieve this data and output it, possibly prettified. Users can pick out individual fields with "jq" then.
many of our tools that do not involve a D-Bus service already output JSON natively. This is an attempt to open this up for D-Bus daemons too, i.e. to marry the D-Bus world and the JSON world a bit.