[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 02/10] Add secretObjFromSecret



Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/secret/secret_driver.c | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index b07cc6f..8c1f79a 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -173,6 +173,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
@@ -847,13 +864,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;
@@ -884,13 +896,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;
@@ -942,13 +949,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;
@@ -987,13 +989,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;
-- 
2.5.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]