[gnome-settings-daemon/rhel/account-and-subman-plugins: 21/23] subman: Improve subscription status handling




commit 0eee8c405687f4c9ee8ea0ae61d9823998689f02
Author: Ray Strode <rstrode redhat com>
Date:   Sun Jan 24 11:34:03 2021 -0500

    subman: Improve subscription status handling
    
    This commit improves how subscription-manager status is
    parsed to give more detailed information about subscription
    state.

 plugins/subman/gsd-subscription-manager.c | 33 ++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
index 705f8b11..6d80bfa9 100644
--- a/plugins/subman/gsd-subscription-manager.c
+++ b/plugins/subman/gsd-subscription-manager.c
@@ -289,6 +289,11 @@ _client_subscription_status_update (GsdSubscriptionManager *manager, GError **er
 
        g_variant_get (uuid, "(&s)", &uuid_txt);
 
+       if (uuid_txt[0] == '\0') {
+               priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
+               goto out;
+       }
+
        status = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
                                         "GetStatus",
                                         g_variant_new ("(ss)",
@@ -304,6 +309,13 @@ _client_subscription_status_update (GsdSubscriptionManager *manager, GError **er
                return FALSE;
        json_root = json_parser_get_root (json_parser);
        json_obj = json_node_get_object (json_root);
+
+       const gchar *status_id = NULL;
+
+       if (json_object_has_member (json_obj, "status_id")) {
+               status_id = json_object_get_string_member (json_obj, "status_id");
+       }
+
        if (!json_object_has_member (json_obj, "valid")) {
                g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
                             "no Entitlement.GetStatus valid in %s", json_txt);
@@ -312,16 +324,27 @@ _client_subscription_status_update (GsdSubscriptionManager *manager, GError **er
 
        gboolean is_valid = json_object_get_boolean_member (json_obj, "valid");
 
-       if (uuid_txt[0] != '\0') {
-               if (is_valid) {
+       if (is_valid) {
+               if (g_strcmp0 (status_id, "disabled") != 0) {
                        priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
                } else {
-                       priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
+                       priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED;
+               }
+               goto out;
+       }
+
+       for (guint i = 0; i < priv->installed_products->len; i++) {
+               ProductData *product = g_ptr_array_index (priv->installed_products, i);
+
+               if (g_strcmp0 (product->status, "subscribed") == 0) {
+                       priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID;
+                       goto out;
                }
-       } else {
-               priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
        }
 
+       priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
+
+out:
        /* emit notification for g-c-c */
        if (priv->subscription_status != priv->subscription_status_last) {
                _emit_property_changed (manager, "SubscriptionStatus",


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