Add utility to format the virSecretLookupTypeDefPtr in XML
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/virsecret.c | 23 +++++++++++++++++++++++
src/util/virsecret.h | 3 +++
src/util/virstoragefile.c | 18 ++----------------
4 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d06e754..5effca8 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2211,6 +2211,7 @@ virSecurityLabelDefNew;
# util/virsecret.h
+virSecretFormatSecretLookup;
virSecretLookupDefClear;
virSecretLookupDefCopy;
virSecretParseSecretLookup;
diff --git a/src/util/virsecret.c b/src/util/virsecret.c
index a4eb22f..532cbdc 100644
--- a/src/util/virsecret.c
+++ b/src/util/virsecret.c
@@ -99,3 +99,26 @@ virSecretParseSecretLookup(xmlNodePtr secretnode,
VIR_FREE(usage);
return ret;
}
+
+
+void
+virSecretFormatSecretLookup(virBufferPtr buf,
+ const char *secrettype,
+ virSecretLookupTypeDefPtr def)
+{
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ if (secrettype)
+ virBufferAsprintf(buf, "<secret type='%s'", secrettype);
+ else
+ virBufferAddLit(buf, "<secret");
+
+ if (def->type == VIR_SECRET_LOOKUP_TYPE_UUID) {
+ virUUIDFormat(def->u.uuid, uuidstr);
+ virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
+ } else if (def->type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
+ virBufferEscapeString(buf, " usage='%s'/>\n",
def->u.usage);
+ } else {
+ virBufferAddLit(buf, "/>\n");
+ }
+}
diff --git a/src/util/virsecret.h b/src/util/virsecret.h
index 3c22be3..50a201f 100644
--- a/src/util/virsecret.h
+++ b/src/util/virsecret.h
@@ -50,4 +50,7 @@ int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
const virSecretLookupTypeDef *src);
int virSecretParseSecretLookup(xmlNodePtr secretnode,
virSecretLookupTypeDefPtr def);
+void virSecretFormatSecretLookup(virBufferPtr buf,
+ const char *secrettype,
+ virSecretLookupTypeDefPtr def);
#endif /* __VIR_SECRET_H__ */
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 963318f..4c9323f 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1623,8 +1623,6 @@ int
virStorageAuthDefFormat(virBufferPtr buf,
virStorageAuthDefPtr authdef)
{
- char uuidstr[VIR_UUID_STRING_BUFLEN];
-
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
virBufferEscapeString(buf, "<auth username='%s'>\n",
authdef->username);
} else {
@@ -1634,20 +1632,8 @@ virStorageAuthDefFormat(virBufferPtr buf,
}
virBufferAdjustIndent(buf, 2);
- if (authdef->secrettype)
- virBufferAsprintf(buf, "<secret type='%s'",
authdef->secrettype);
- else
- virBufferAddLit(buf, "<secret");
-
- if (authdef->seclookupdef.type == VIR_SECRET_LOOKUP_TYPE_UUID) {
- virUUIDFormat(authdef->seclookupdef.u.uuid, uuidstr);
- virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr);
- } else if (authdef->seclookupdef.type == VIR_SECRET_LOOKUP_TYPE_USAGE) {
- virBufferEscapeString(buf, " usage='%s'/>\n",
- authdef->seclookupdef.u.usage);
- } else {
- virBufferAddLit(buf, "/>\n");
- }
+ virSecretFormatSecretLookup(buf, authdef->secrettype,
+ &authdef->seclookupdef);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</auth>\n");
--
2.5.5