]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add secretObjFromSecret
authorJohn Ferlan <jferlan@redhat.com>
Mon, 29 Feb 2016 22:15:26 +0000 (17:15 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 7 Mar 2016 20:52:21 +0000 (15:52 -0500)
Signed-off-by: John Ferlan <jferlan@redhat.com>
src/secret/secret_driver.c

index 36e28b9ba2c41bf132cbd06e55ef98c9c40fc70c..4d157973d4df0bbb1406b4b3752134e0bb028cce 100644 (file)
@@ -184,6 +184,23 @@ secretAssignDef(virSecretObjPtr *list,
     return secret;
 }
 
+
+static virSecretObjPtr
+secretObjFromSecret(virSecretPtr secret)
+{
+    virSecretObjPtr obj;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    if (!(obj = secretFindByUUID(secret->uuid))) {
+        virUUIDFormat(secret->uuid, uuidstr);
+        virReportError(VIR_ERR_NO_SECRET,
+                       _("no secret with matching uuid '%s'"), uuidstr);
+        return NULL;
+    }
+    return obj;
+}
+
+
 /* Permament secret storage */
 
 /* Secrets are stored in virSecretDriverStatePtr->configDir.  Each secret
@@ -858,13 +875,8 @@ secretGetXMLDesc(virSecretPtr obj,
 
     secretDriverLock();
 
-    if (!(secret = secretFindByUUID(obj->uuid))) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(obj->uuid, uuidstr);
-        virReportError(VIR_ERR_NO_SECRET,
-                       _("no secret with matching uuid '%s'"), uuidstr);
+    if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
-    }
 
     if (virSecretGetXMLDescEnsureACL(obj->conn, secret->def) < 0)
         goto cleanup;
@@ -895,13 +907,8 @@ secretSetValue(virSecretPtr obj,
 
     secretDriverLock();
 
-    if (!(secret = secretFindByUUID(obj->uuid))) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(obj->uuid, uuidstr);
-        virReportError(VIR_ERR_NO_SECRET,
-                       _("no secret with matching uuid '%s'"), uuidstr);
+    if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
-    }
 
     if (virSecretSetValueEnsureACL(obj->conn, secret->def) < 0)
         goto cleanup;
@@ -953,13 +960,8 @@ secretGetValue(virSecretPtr obj,
 
     secretDriverLock();
 
-    if (!(secret = secretFindByUUID(obj->uuid))) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(obj->uuid, uuidstr);
-        virReportError(VIR_ERR_NO_SECRET,
-                       _("no secret with matching uuid '%s'"), uuidstr);
+    if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
-    }
 
     if (virSecretGetValueEnsureACL(obj->conn, secret->def) < 0)
         goto cleanup;
@@ -998,13 +1000,8 @@ secretUndefine(virSecretPtr obj)
 
     secretDriverLock();
 
-    if (!(secret = secretFindByUUID(obj->uuid))) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(obj->uuid, uuidstr);
-        virReportError(VIR_ERR_NO_SECRET,
-                       _("no secret with matching uuid '%s'"), uuidstr);
+    if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
-    }
 
     if (virSecretUndefineEnsureACL(obj->conn, secret->def) < 0)
         goto cleanup;