]> xenbits.xensource.com Git - libvirt.git/commitdiff
secret: util: Refactor virSecretGetSecretString
authorPeter Krempa <pkrempa@redhat.com>
Fri, 13 May 2016 11:32:48 +0000 (13:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 May 2016 10:58:48 +0000 (12:58 +0200)
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
src/libxl/libxl_conf.c
src/qemu/qemu_domain.c
src/secret/secret_util.c
src/secret/secret_util.h

index 506d5352e15fc72cfb3470044e17937c9c679221..0d924487f0a3ae56355803df7fc9d677c4c72fc0 100644 (file)
@@ -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
index 3c388c7796d93d59a9c3d0183a3949db77cd9ea7..6583afb27c3a6127759ec6685c09c6afa7f15ea9 100644 (file)
@@ -1027,14 +1027,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)))
index b0eb3b6632a0a013989796728fbd9ca63ef6a039..63075e6a75d005d00d06776a379bf3a7e596dfcb 100644 (file)
@@ -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;
index 217584f8c4a378eef49aac957861259cef4b3ecb..d69f7ba9e0757bca4c8b53801fcfaf67039410d4 100644 (file)
@@ -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;
index c707599f9a13accfbc84b86276e03642ec008503..00864493a3646af20cbe37820ae1ee448d3df17f 100644 (file)
 # include "virstoragefile.h"
 
 char *virSecretGetSecretString(virConnectPtr conn,
-                               const char *scheme,
                                bool encoded,
                                virStorageAuthDefPtr authdef,
                                virSecretUsageType secretUsageType)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4)
-    ATTRIBUTE_RETURN_CHECK;
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
 #endif /* __VIR_SECRET_H__ */