Blame SOURCES/0013-subman-Improve-subscription-status-handling.patch

6486b0
From d9eb6331efa92cd28a8ba3ccc1665c3744296465 Mon Sep 17 00:00:00 2001
6486b0
From: Ray Strode <rstrode@redhat.com>
6486b0
Date: Sun, 24 Jan 2021 11:34:03 -0500
6486b0
Subject: [PATCH 13/15] subman: Improve subscription status handling
6486b0
6486b0
This commit improves how subscription-manager status is
6486b0
parsed to give more detailed information about subscription
6486b0
state.
6486b0
---
6486b0
 plugins/subman/gsd-subscription-manager.c | 33 +++++++++++++++++++----
6486b0
 1 file changed, 28 insertions(+), 5 deletions(-)
6486b0
6486b0
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
6486b0
index 705f8b11..6d80bfa9 100644
6486b0
--- a/plugins/subman/gsd-subscription-manager.c
6486b0
+++ b/plugins/subman/gsd-subscription-manager.c
6486b0
@@ -262,93 +262,116 @@ _client_subscription_status_update (GsdSubscriptionManager *manager, GError **er
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	g_autoptr(GVariant) uuid = NULL;
6486b0
 	const gchar *uuid_txt = NULL;
6486b0
 	JsonNode *json_root;
6486b0
 	JsonObject *json_obj;
6486b0
 	const gchar *json_txt = NULL;
6486b0
 	g_autoptr(GVariant) status = NULL;
6486b0
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
6486b0
 
6486b0
 	/* save old value */
6486b0
 	priv->subscription_status_last = priv->subscription_status;
6486b0
 	if (!_client_installed_products_update (manager, error))
6486b0
 		goto out;
6486b0
 
6486b0
 	if (priv->installed_products->len == 0) {
6486b0
 		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_NO_INSTALLED_PRODUCTS;
6486b0
 		goto out;
6486b0
 	}
6486b0
 
6486b0
 	uuid = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONSUMER],
6486b0
 				       "GetUuid",
6486b0
 				       g_variant_new ("(s)",
6486b0
 				                      "C.UTF-8"),
6486b0
 				       G_DBUS_CALL_FLAGS_NONE,
6486b0
 				       -1, NULL, error);
6486b0
 	if (uuid == NULL)
6486b0
 		return FALSE;
6486b0
 
6486b0
 	g_variant_get (uuid, "(&s)", &uuid_txt);
6486b0
 
6486b0
+	if (uuid_txt[0] == '\0') {
6486b0
+		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
6486b0
+		goto out;
6486b0
+	}
6486b0
+
6486b0
 	status = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
6486b0
 				         "GetStatus",
6486b0
 				         g_variant_new ("(ss)",
6486b0
 						        "", /* assumed as 'now' */
6486b0
 						        "C.UTF-8"),
6486b0
 				         G_DBUS_CALL_FLAGS_NONE,
6486b0
 				         -1, NULL, error);
6486b0
 	if (status == NULL)
6486b0
 		return FALSE;
6486b0
 	g_variant_get (status, "(&s)", &json_txt);
6486b0
 	g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
6486b0
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
6486b0
 		return FALSE;
6486b0
 	json_root = json_parser_get_root (json_parser);
6486b0
 	json_obj = json_node_get_object (json_root);
6486b0
+
6486b0
+	const gchar *status_id = NULL;
6486b0
+
6486b0
+	if (json_object_has_member (json_obj, "status_id")) {
6486b0
+		status_id = json_object_get_string_member (json_obj, "status_id");
6486b0
+	}
6486b0
+
6486b0
 	if (!json_object_has_member (json_obj, "valid")) {
6486b0
 		g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
6486b0
 			     "no Entitlement.GetStatus valid in %s", json_txt);
6486b0
 		return FALSE;
6486b0
 	}
6486b0
 
6486b0
 	gboolean is_valid = json_object_get_boolean_member (json_obj, "valid");
6486b0
 
6486b0
-	if (uuid_txt[0] != '\0') {
6486b0
-		if (is_valid) {
6486b0
+	if (is_valid) {
6486b0
+		if (g_strcmp0 (status_id, "disabled") != 0) {
6486b0
 			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
6486b0
 		} else {
6486b0
-			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
6486b0
+			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED;
6486b0
+		}
6486b0
+		goto out;
6486b0
+	}
6486b0
+
6486b0
+	for (guint i = 0; i < priv->installed_products->len; i++) {
6486b0
+		ProductData *product = g_ptr_array_index (priv->installed_products, i);
6486b0
+
6486b0
+		if (g_strcmp0 (product->status, "subscribed") == 0) {
6486b0
+			priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID;
6486b0
+			goto out;
6486b0
 		}
6486b0
-	} else {
6486b0
-		priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
6486b0
 	}
6486b0
 
6486b0
+	priv->subscription_status = GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
6486b0
+
6486b0
+out:
6486b0
 	/* emit notification for g-c-c */
6486b0
 	if (priv->subscription_status != priv->subscription_status_last) {
6486b0
 		_emit_property_changed (manager, "SubscriptionStatus",
6486b0
 				       g_variant_new_uint32 (priv->subscription_status));
6486b0
 	}
6486b0
 
6486b0
 	return TRUE;
6486b0
 }
6486b0
 
6486b0
 static gboolean
6486b0
 _client_syspurpose_update (GsdSubscriptionManager *manager, GError **error)
6486b0
 {
6486b0
 	GsdSubscriptionManagerPrivate *priv = manager->priv;
6486b0
 	JsonNode *json_root;
6486b0
 	JsonObject *json_obj;
6486b0
 	const gchar *json_txt = NULL;
6486b0
 	g_autoptr(GVariant) val = NULL;
6486b0
 	g_autoptr(JsonParser) json_parser = json_parser_new ();
6486b0
 
6486b0
 	val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_SYSPURPOSE],
6486b0
 				      "GetSyspurpose",
6486b0
 				      g_variant_new ("(s)", "C.UTF-8"),
6486b0
 				      G_DBUS_CALL_FLAGS_NONE,
6486b0
 				      -1, NULL, error);
6486b0
 	if (val == NULL)
6486b0
 		return FALSE;
6486b0
 	g_variant_get (val, "(&s)", &json_txt);
6486b0
 	g_debug ("Syspurpose.GetSyspurpose JSON: %s", json_txt);
6486b0
 	if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
6486b0
 		return FALSE;
6486b0
-- 
6486b0
2.30.0
6486b0