hostnamed: expose parsed TAGS in Describe

The DBus API already exposes the parsed machine-tags list via the Tags
property but varlink clients needed to parse the raw TAGS= line from
MachineInformationData (which also required implementing tag name
validation if the tags would later be used with SetTags, to avoid
spurious errors).

So, provide the same information that DBus gets (a list of pre-parsed
tags with bad tags gracefully removed) as a new MachineTags field
returned by Describe -- this does mean that the DBus API now exposes the
same data in two ways but making Describe() consistent is more important
and mirrors the OperatingSystem* class of properties.
This commit is contained in:
Aleksa Sarai
2026-08-23 14:10:22 +01:00
committed by Luca Boccassi
parent ded83144eb
commit 44cc69769d
4 changed files with 34 additions and 0 deletions
+7
View File
@@ -2013,6 +2013,12 @@ static int build_describe_response(Context *c, bool privileged, sd_json_variant
(void) load_os_release_pairs(/* root= */ NULL, &os_release_pairs);
(void) load_env_file_pairs(/* f= */ NULL, etc_machine_info(), &machine_info_pairs);
/* Silently drop any invalid tags that might have been written into the file by hand */
_cleanup_strv_free_ char **tags = NULL;
r = machine_tags_from_string(c->data[PROP_TAGS], /* graceful= */ true, &tags);
if (r < 0)
log_warning_errno(r, "Failed to parse machine tags '%s', ignoring: %m", strnull(c->data[PROP_TAGS]));
r = sd_json_buildo(
&v,
SD_JSON_BUILD_PAIR_STRING("Hostname", hn ?: dhn),
@@ -2037,6 +2043,7 @@ static int build_describe_response(Context *c, bool privileged, sd_json_variant
SD_JSON_BUILD_PAIR_STRING("OperatingSystemImageID", c->data[PROP_OS_IMAGE_ID]),
SD_JSON_BUILD_PAIR_STRING("OperatingSystemImageVersion", c->data[PROP_OS_IMAGE_VERSION]),
SD_JSON_BUILD_PAIR("MachineInformationData", JSON_BUILD_STRV_ENV_PAIR(machine_info_pairs)),
SD_JSON_BUILD_PAIR_STRV("MachineTags", tags),
SD_JSON_BUILD_PAIR_STRING("HardwareVendor", vendor ?: c->data[PROP_HARDWARE_VENDOR]),
SD_JSON_BUILD_PAIR_STRING("HardwareModel", model ?: c->data[PROP_HARDWARE_MODEL]),
SD_JSON_BUILD_PAIR_STRING("HardwareSerial", serial),
+2
View File
@@ -50,6 +50,8 @@ static SD_VARLINK_DEFINE_METHOD(
SD_VARLINK_DEFINE_OUTPUT(OperatingSystemImageVersion, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
SD_VARLINK_FIELD_COMMENT("The full contents of /etc/machine-info, as an array of 'KEY=VALUE' strings."),
SD_VARLINK_DEFINE_OUTPUT(MachineInformationData, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY),
SD_VARLINK_FIELD_COMMENT("The machine tags, from the TAGS= field of /etc/machine-info with any invalid tags filtered out. Empty if none are configured."),
SD_VARLINK_DEFINE_OUTPUT(MachineTags, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY),
SD_VARLINK_FIELD_COMMENT("The hardware vendor of this system. Null if not known."),
SD_VARLINK_DEFINE_OUTPUT(HardwareVendor, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
SD_VARLINK_FIELD_COMMENT("The hardware model of this system. Null if not known."),