[virt-tools-list] [PATCH virt-viewer v3 2/2] ovirt: Allow to cancel authentication without showing error dialog

Pavel Grunt pgrunt at redhat.com
Fri Mar 20 17:03:32 UTC 2015


Hi,

> 
> I commented in the bug that you filed for that:
> https://bugzilla.gnome.org/show_bug.cgi?id=746455
> « I think it could sometimes be valid to try to authenticate with no
> username/password?
> Maybe introducing rest_proxy_auth_cancel() in the public API would be
> better? »
> 

With the rest_proxy_auth_cancel() https://bugzilla.gnome.org/show_bug.cgi?id=746537
and new libgovirt CANCELLED error https://bugzilla.gnome.org/show_bug.cgi?id=746539
the patch for virt-viewer can look like this (+using some version checks for libgovirt and librest):

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 4110b1e..1d6fb63 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -704,7 +704,7 @@ parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name, char **usern
 }
 
 static gboolean
-authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
+authenticate_cb(RestProxy *proxy, RestProxyAuth *auth,
                 G_GNUC_UNUSED gboolean retrying, gpointer user_data)
 {
     gchar *username = NULL;
@@ -729,6 +729,8 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
                      "username", username,
                      "password", password,
                      NULL);
+    } else {
+        rest_proxy_auth_cancel(auth);
     }
 
     g_free(username);
@@ -863,6 +865,12 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
     api = ovirt_proxy_fetch_api(proxy, &error);
     if (error != NULL) {
         g_debug("failed to get oVirt 'api' collection: %s", error->message);
+        if (g_error_matches(error, OVIRT_REST_CALL_ERROR, OVIRT_REST_CALL_ERROR_CANCELLED))
+            g_clear_error(&error);
+            g_set_error_literal(&error,
+                                VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED,
+                                _("Authentication was cancelled"));
+        }
         goto error;
     }
     vms = ovirt_api_get_vms(api);




Thanks,

Pavel




More information about the virt-tools-list mailing list