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

Jonathon Jongsma jjongsma at redhat.com
Wed Mar 18 19:48:58 UTC 2015


So, did you investigate whether it would be possible to modify
libgovirt / librest to return a 'CANCELLED' error status (or similar)
from ovirt_proxy_fetch_api() so that we don't need to track this
ourselves with an extra struct? That seems like a cleaner long-term
solution. 

But this patch is fine for the current behavior. ACK.

Jonathon

On Wed, 2015-03-18 at 17:49 +0100, Pavel Grunt wrote:
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1201604
> ---
> v3: similar approach to https://www.redhat.com/archives/virt-tools-list/2015-March/msg00095.html
> ---
>  src/remote-viewer.c | 21 +++++++++++++++++++--
>  1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/src/remote-viewer.c b/src/remote-viewer.c
> index 5b67f51..a9de5e7 100644
> --- a/src/remote-viewer.c
> +++ b/src/remote-viewer.c
> @@ -703,6 +703,11 @@ parse_ovirt_uri(const gchar *uri_str, char **rest_uri, char **name, char **usern
>      return TRUE;
>  }
>  
> +typedef struct {
> +    VirtViewerApp *app;
> +    gboolean dialog_cancelled;
> +} AuthenticateInfo;
> +
>  static gboolean
>  authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
>                  G_GNUC_UNUSED gboolean retrying, gpointer user_data)
> @@ -711,6 +716,7 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
>      gchar *password = NULL;
>      VirtViewerWindow *window;
>      gboolean success = FALSE;
> +    AuthenticateInfo *authenticate_info = user_data;
>  
>      g_object_get(proxy,
>                   "username", &username,
> @@ -719,11 +725,12 @@ authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
>      if (username == NULL || *username == '\0')
>          username = g_strdup(g_get_user_name());
>  
> -    window = virt_viewer_app_get_main_window(VIRT_VIEWER_APP(user_data));
> +    window = virt_viewer_app_get_main_window(authenticate_info->app);
>      success = virt_viewer_auth_collect_credentials(virt_viewer_window_get_window(window),
>                                                     "oVirt",
>                                                     NULL,
>                                                     &username, &password);
> +    authenticate_info->dialog_cancelled = !success;
>      if (success) {
>          g_object_set(G_OBJECT(proxy),
>                       "username", username,
> @@ -843,6 +850,10 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
>      gchar *ticket = NULL;
>      gchar *host_subject = NULL;
>      gchar *guid = NULL;
> +    AuthenticateInfo authenticate_info  = {
> +        .app = app,
> +        .dialog_cancelled = FALSE,
> +    };
>  
>      g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);
>  
> @@ -858,11 +869,17 @@ create_ovirt_session(VirtViewerApp *app, const char *uri, GError **err)
>                   NULL);
>      ovirt_set_proxy_options(proxy);
>      g_signal_connect(G_OBJECT(proxy), "authenticate",
> -                     G_CALLBACK(authenticate_cb), app);
> +                     G_CALLBACK(authenticate_cb), &authenticate_info);
>  
>      api = ovirt_proxy_fetch_api(proxy, &error);
>      if (error != NULL) {
>          g_debug("failed to get oVirt 'api' collection: %s", error->message);
> +        if (authenticate_info.dialog_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);





More information about the virt-tools-list mailing list