]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cmdSecretSetValue: Make it obvious that --file, --base64 and --interactive are exlcusive
authorPeter Krempa <pkrempa@redhat.com>
Mon, 1 Feb 2021 12:10:59 +0000 (13:10 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Feb 2021 12:07:12 +0000 (13:07 +0100)
Convert the conditions to else if so that it's obvious that only one of
the cases will ever be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tools/virsh-secret.c

index 16accc8ad295c8419ff2adb35735384d4fd475f7..5d656151e8bf3d497e0407392c0a36e9ad088b4a 100644 (file)
@@ -225,16 +225,10 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "file", &filename) < 0)
         return false;
 
-    if (!base64 && !filename && !interactive) {
-        vshError(ctl, _("Input secret value is missing"));
-        return false;
-    }
-
-    /* warn users that the --base64 option passed from command line is wrong */
-    if (base64)
+    if (base64) {
+        /* warn users that the --base64 option passed from command line is wrong */
         vshError(ctl, _("Passing secret value as command-line argument is insecure!"));
-
-    if (filename) {
+    } else if (filename) {
         ssize_t read_ret;
         if ((read_ret = virFileReadAll(filename, 1024, &file_buf)) < 0) {
             vshSaveLibvirtError();
@@ -243,9 +237,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
 
         file_len = read_ret;
         base64 = file_buf;
-    }
-
-    if (interactive) {
+    } else if (interactive) {
         vshPrint(ctl, "%s", _("Enter new value for secret:"));
         fflush(stdout);
 
@@ -255,6 +247,9 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
         }
         file_len = strlen(file_buf);
         plain = true;
+    } else {
+        vshError(ctl, _("Input secret value is missing"));
+        return false;
     }
 
     if (plain) {