diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index c6c8c30ba9..966536599e 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -195,39 +195,34 @@ static int
virSecretDefFormatUsage(virBuffer *buf,
const virSecretDef *def)
{
- const char *type;
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+
+ virBufferAsprintf(&attrBuf, " type='%s'",
+ virSecretUsageTypeToString(def->usage_type));
- type = virSecretUsageTypeToString(def->usage_type);
- if (type == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected secret usage type %1$d"),
- def->usage_type);
- return -1;
- }
- virBufferAsprintf(buf, "\n", type);
- virBufferAdjustIndent(buf, 2);
switch (def->usage_type) {
case VIR_SECRET_USAGE_TYPE_NONE:
break;
case VIR_SECRET_USAGE_TYPE_VOLUME:
- virBufferEscapeString(buf, "%s\n", def->usage_id);
+ virBufferEscapeString(&childBuf, "%s\n", def->usage_id);
break;
case VIR_SECRET_USAGE_TYPE_CEPH:
- virBufferEscapeString(buf, "%s\n", def->usage_id);
+ virBufferEscapeString(&childBuf, "%s\n", def->usage_id);
break;
case VIR_SECRET_USAGE_TYPE_ISCSI:
- virBufferEscapeString(buf, "%s\n", def->usage_id);
+ virBufferEscapeString(&childBuf, "%s\n", def->usage_id);
break;
case VIR_SECRET_USAGE_TYPE_TLS:
- virBufferEscapeString(buf, "%s\n", def->usage_id);
+ virBufferEscapeString(&childBuf, "%s\n", def->usage_id);
break;
case VIR_SECRET_USAGE_TYPE_VTPM:
- virBufferEscapeString(buf, "%s\n", def->usage_id);
+ virBufferEscapeString(&childBuf, "%s\n", def->usage_id);
break;
default:
@@ -235,8 +230,8 @@ virSecretDefFormatUsage(virBuffer *buf,
virReportEnumRangeError(virSecretUsageType, def->usage_type);
return -1;
}
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "\n");
+
+ virXMLFormatElement(buf, "usage", &attrBuf, &childBuf);
return 0;
}
@@ -245,25 +240,23 @@ char *
virSecretDefFormat(const virSecretDef *def)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- const unsigned char *uuid;
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(&buf);
char uuidstr[VIR_UUID_STRING_BUFLEN];
- virBufferAsprintf(&buf, "\n",
+ virBufferAsprintf(&attrBuf, " ephemeral='%s' private='%s'",
def->isephemeral ? "yes" : "no",
def->isprivate ? "yes" : "no");
- uuid = def->uuid;
- virUUIDFormat(uuid, uuidstr);
- virBufferAdjustIndent(&buf, 2);
- virBufferEscapeString(&buf, "%s\n", uuidstr);
+ virUUIDFormat(def->uuid, uuidstr);
+ virBufferEscapeString(&childBuf, "%s\n", uuidstr);
if (def->description != NULL)
- virBufferEscapeString(&buf, "%s\n",
+ virBufferEscapeString(&childBuf, "%s\n",
def->description);
if (def->usage_type != VIR_SECRET_USAGE_TYPE_NONE &&
- virSecretDefFormatUsage(&buf, def) < 0)
+ virSecretDefFormatUsage(&childBuf, def) < 0)
return NULL;
- virBufferAdjustIndent(&buf, -2);
- virBufferAddLit(&buf, "\n");
+ virXMLFormatElement(&buf, "secret", &attrBuf, &childBuf);
return virBufferContentAndReset(&buf);
}