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

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