]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Introduce virSecretLookupFormatSecret
authorJohn Ferlan <jferlan@redhat.com>
Mon, 13 Jun 2016 23:40:34 +0000 (19:40 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 23 Jun 2016 16:30:28 +0000 (12:30 -0400)
Add utility to format the virSecretLookupTypeDefPtr in XML

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/libvirt_private.syms
src/util/virsecret.c
src/util/virsecret.h
src/util/virstoragefile.c

index 528b2047a0d255b514c241ed25413704836fe66e..b118d1e3d730f4f1d50deacc2e1fa1d06ce30e48 100644 (file)
@@ -2221,6 +2221,7 @@ virSecurityLabelDefNew;
 # util/virsecret.h
 virSecretLookupDefClear;
 virSecretLookupDefCopy;
+virSecretLookupFormatSecret;
 virSecretLookupParseSecret;
 
 
index 7fdb0ae2daa68463bfa942f42d9c7dcd085d7b6b..aded8028b9cd1767fc0ba0f9dde1cea81c70066e 100644 (file)
@@ -99,3 +99,26 @@ virSecretLookupParseSecret(xmlNodePtr secretnode,
     VIR_FREE(usage);
     return ret;
 }
+
+
+void
+virSecretLookupFormatSecret(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");
+    }
+}
index eee863f92211d2a80641dccae6a87b1a7424377f..4506fb36eb5e4287b8355fae5c8aa060f0f397c3 100644 (file)
@@ -50,4 +50,7 @@ int virSecretLookupDefCopy(virSecretLookupTypeDefPtr dst,
                            const virSecretLookupTypeDef *src);
 int virSecretLookupParseSecret(xmlNodePtr secretnode,
                                virSecretLookupTypeDefPtr def);
+void virSecretLookupFormatSecret(virBufferPtr buf,
+                                 const char *secrettype,
+                                 virSecretLookupTypeDefPtr def);
 #endif /* __VIR_SECRET_H__ */
index 0863c4fe99cda75f58faf9ea07a34bcde5c0fb3a..de4955b7d098af471f57774779b65af8baf8a8a5 100644 (file)
@@ -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");
-    }
+    virSecretLookupFormatSecret(buf, authdef->secrettype,
+                                &authdef->seclookupdef);
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</auth>\n");