From 702a47c067d5c1cd27b0c815514746dc39afb85e Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <ignatenko@redhat.com>
Date: Thu, 30 Mar 2017 18:45:19 +0200
Subject: [PATCH] utils: add support for multiple entitlement certificates
..for generation of yum repo.
We just need to go through list and find all possible repositories.
If there are duplicates, silently skip it (as sub-man does).
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
---
rhsm/rhsm-utils.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/rhsm/rhsm-utils.c b/rhsm/rhsm-utils.c
index d9bb4a2..7b6a26b 100644
--- a/rhsm/rhsm-utils.c
+++ b/rhsm/rhsm-utils.c
@@ -195,25 +195,24 @@ rhsm_utils_yum_repo_from_context (RHSMContext *ctx)
g_autoptr(GPtrArray) entitlements = rhsm_context_get_entitlement_certificates (ctx);
g_autoptr(GPtrArray) products = rhsm_context_get_product_certificates (ctx);
- if (entitlements->len > 0)
+ /* Get all available tags from each of the products */
+ g_autoptr(GHashTable) available_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ for (guint i = 0; i < products->len; i++)
{
- g_autoptr(GError) error = NULL;
- RHSMEntitlementCertificate *entitlement = g_ptr_array_index (entitlements, 0);
+ RHSMProductCertificate *product = g_ptr_array_index (products, i);
+ g_auto(GStrv) tags = g_strsplit (rhsm_product_certificate_get_tags (product), ",", -1);
+ for (GStrv tag = tags; *tag != NULL; tag++)
+ g_hash_table_add (available_tags, g_strdup (*tag));
+ }
+
+ for (guint i = 0; i < entitlements->len; i++)
+ {
+ RHSMEntitlementCertificate *entitlement = g_ptr_array_index (entitlements, i);
JsonNode *ent = rhsm_entitlement_certificate_get_entitlement (entitlement);
g_autoptr(JsonNode) contents = json_path_query ("$.products[*].content[*]", ent, NULL);
/* Even there is non-matching JsonPath, node will be empty array */
g_assert_nonnull (contents);
- /* Get all available tags from each of the products */
- g_autoptr(GHashTable) available_tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- for (guint i = 0; i < products->len; i++)
- {
- RHSMProductCertificate *product = g_ptr_array_index (products, i);
- g_auto(GStrv) tags = g_strsplit (rhsm_product_certificate_get_tags (product), ",", -1);
- for (GStrv tag = tags; *tag != NULL; tag++)
- g_hash_table_add (available_tags, g_strdup (*tag));
- }
-
g_autoptr(GList) elements = json_array_get_elements (json_node_get_array (contents));
const gchar *ctx_arch = rhsm_context_get_arch (ctx);
const gchar *ctx_baseurl = rhsm_context_get_baseurl (ctx);
@@ -252,6 +251,14 @@ rhsm_utils_yum_repo_from_context (RHSMContext *ctx)
enabled = json_object_get_boolean_member (repo, "enabled");
if (id == NULL || name == NULL || path == NULL)
continue; /* TODO: make some error reporting here */
+
+ /* Clashing repositories */
+ if (g_key_file_has_group (repofile, id))
+ {
+ g_debug ("Repository '%s' has been already added, skipping", id);
+ continue;
+ }
+
g_autofree gchar *baseurl = g_strconcat (ctx_baseurl, path, NULL);
g_key_file_set_string (repofile, id, "name", name);
g_key_file_set_string (repofile, id, "baseurl", baseurl);
--
2.12.1