[PATCH 2/6] secret: util: Refactor virSecretGetSecretString

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

 



Call the internal driver callbacks rather than the public APIs to avoid
calling unnecessarily the error dispatching code and don't overwrite
the error messages provided by the APIs. They are good enough to
describe which secret is missing either by UUID or the usage (basically
name).
---
 po/POTFILES.in           |  1 -
 src/libxl/libxl_conf.c   |  3 ---
 src/qemu/qemu_domain.c   |  4 +---
 src/secret/secret_util.c | 39 +++++++--------------------------------
 src/secret/secret_util.h |  1 -
 5 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 506d535..0d92448 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -153,7 +153,6 @@ src/rpc/virnetsocket.c
 src/rpc/virnetsshsession.c
 src/rpc/virnettlscontext.c
 src/secret/secret_driver.c
-src/secret/secret_util.c
 src/security/security_apparmor.c
 src/security/security_dac.c
 src/security/security_driver.c
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index d927b37..b08ee14 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1024,14 +1024,11 @@ libxlMakeNetworkDiskSrc(virStorageSourcePtr src, char **srcstr)

     *srcstr = NULL;
     if (src->auth && src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) {
-        const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
-
         username = src->auth->username;
         if (!(conn = virConnectOpen("xen:///system")))
             goto cleanup;

         if (!(secret = virSecretGetSecretString(conn,
-                                                protocol,
                                                 true,
                                                 src->auth,
                                                 VIR_SECRET_USAGE_TYPE_CEPH)))
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 39a50e6..87f0dbd 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -872,7 +872,6 @@ qemuDomainSecretPlainSetup(virConnectPtr conn,
 {
     bool encode = false;
     int secretType = VIR_SECRET_USAGE_TYPE_ISCSI;
-    const char *protocolstr = virStorageNetProtocolTypeToString(protocol);

     secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN;
     if (VIR_STRDUP(secinfo->s.plain.username, authdef->username) < 0)
@@ -885,8 +884,7 @@ qemuDomainSecretPlainSetup(virConnectPtr conn,
     }

     if (!(secinfo->s.plain.secret =
-          virSecretGetSecretString(conn, protocolstr, encode,
-                                   authdef, secretType)))
+          virSecretGetSecretString(conn, encode, authdef, secretType)))
         return -1;

     return 0;
diff --git a/src/secret/secret_util.c b/src/secret/secret_util.c
index 217584f..d69f7ba 100644
--- a/src/secret/secret_util.c
+++ b/src/secret/secret_util.c
@@ -37,7 +37,6 @@ VIR_LOG_INIT("secret.secret_util");

 /* virSecretGetSecretString:
  * @conn: Pointer to the connection driver to make secret driver call
- * @scheme: Unique enough string for error message to help determine cause
  * @encoded: Whether the returned secret needs to be base64 encoded
  * @authdef: Pointer to the disk storage authentication
  * @secretUsageType: Type of secret usage for authdef lookup
@@ -50,7 +49,6 @@ VIR_LOG_INIT("secret.secret_util");
  */
 char *
 virSecretGetSecretString(virConnectPtr conn,
-                         const char *scheme,
                          bool encoded,
                          virStorageAuthDefPtr authdef,
                          virSecretUsageType secretUsageType)
@@ -58,49 +56,26 @@ virSecretGetSecretString(virConnectPtr conn,
     size_t secret_size;
     virSecretPtr sec = NULL;
     char *secret = NULL;
-    char uuidStr[VIR_UUID_STRING_BUFLEN];

-    /* look up secret */
     switch (authdef->secretType) {
     case VIR_STORAGE_SECRET_TYPE_UUID:
-        sec = virSecretLookupByUUID(conn, authdef->secret.uuid);
-        virUUIDFormat(authdef->secret.uuid, uuidStr);
+        sec = conn->secretDriver->secretLookupByUUID(conn, authdef->secret.uuid);
         break;
+
     case VIR_STORAGE_SECRET_TYPE_USAGE:
-        sec = virSecretLookupByUsage(conn, secretUsageType,
-                                     authdef->secret.usage);
+        sec = conn->secretDriver->secretLookupByUsage(conn, secretUsageType,
+                                                      authdef->secret.usage);
         break;
     }

-    if (!sec) {
-        if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-            virReportError(VIR_ERR_NO_SECRET,
-                           _("%s no secret matches uuid '%s'"),
-                           scheme, uuidStr);
-        } else {
-            virReportError(VIR_ERR_NO_SECRET,
-                           _("%s no secret matches usage value '%s'"),
-                           scheme, authdef->secret.usage);
-        }
+    if (!sec)
         goto cleanup;
-    }

     secret = (char *)conn->secretDriver->secretGetValue(sec, &secret_size, 0,
                                                         VIR_SECRET_GET_VALUE_INTERNAL_CALL);
-    if (!secret) {
-        if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("could not get value of the secret for "
-                             "username '%s' using uuid '%s'"),
-                           authdef->username, uuidStr);
-        } else {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("could not get value of the secret for "
-                             "username '%s' using usage value '%s'"),
-                           authdef->username, authdef->secret.usage);
-        }
+
+    if (!secret)
         goto cleanup;
-    }

     if (encoded) {
         char *base64 = NULL;
diff --git a/src/secret/secret_util.h b/src/secret/secret_util.h
index c707599..adc6c31 100644
--- a/src/secret/secret_util.h
+++ b/src/secret/secret_util.h
@@ -26,7 +26,6 @@
 # include "virstoragefile.h"

 char *virSecretGetSecretString(virConnectPtr conn,
-                               const char *scheme,
                                bool encoded,
                                virStorageAuthDefPtr authdef,
                                virSecretUsageType secretUsageType)
-- 
2.8.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]