Bug 1257588

Summary: [RFE] API routes for repositories in consistent with filter on per product and per organization
Product: Red Hat Satellite Reporter: Peter Vreman <peter.vreman>
Component: APIAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED ERRATA QA Contact: Jitendra Yejare <jyejare>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.1.0CC: bbuckingham, bkearney, brubisch, jcallaha, jyejare, rjerrido, xdmoon
Target Milestone: UnspecifiedKeywords: FutureFeature, Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-02-21 12:30:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 260381, 1122832    

Description Peter Vreman 2015-08-27 12:12:56 UTC
Description of problem:
The API routes for repositories are inconsistent there is no URL path to filter per organization and per product.

See below the difference in routes for repositories, content_views and products:
- The repositories does not have a /organizations/ route
- The repositories does not have a /products/

  api :GET, "/repositories", N_("List of enabled repositories")
  api :GET, "/content_views/:id/repositories", N_("List of repositories for a content view")
  param :organization_id, :number, :required => true, :desc => N_("ID of an organization to show repositories in")
  param :product_id, :number, :desc => N_("ID of a product to show repositories of")


For example the content_views has a route with /organizations/

    api :GET, "/organizations/:organization_id/content_views", N_("List content views")
    api :GET, "/content_views", N_("List content views")
    param :organization_id, :number, :desc => N_("organization identifier"), :required => true

And products has even more routes:

    api :GET, "/products", N_("List products")
    api :GET, "/subscriptions/:subscription_id/products", N_("List of subscription products in a subscription")
    api :GET, "/activation_keys/:activation_key_id/products", N_("List of subscription products in an activation key")
    api :GET, "/organizations/:organization_id/products", N_("List of products in an organization")
    param :organization_id, :number, :desc => N_("Filter products by organization"), :required => true


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. API Call "/organizations/:organization_id/repositories"
2. API Call "/products/:product_id/repositories"
3.

Actual results:
Error

Expected results:
Return list of repositories

Additional info:
Followup from BZ1127589 that did not address the inconsistency in the API

Comment 1 Bryan Kearney 2016-07-08 20:47:43 UTC
Per 6.3 planning, moving out non acked bugs to the backlog

Comment 3 Peter Vreman 2016-07-11 12:40:28 UTC
This is fixed in 6.2.0Beta2. The repositories controller contains already more routes:

[crash] root@li-lc-1578:/opt/theforeman/tfm/root/usr/share/gems/gems/katello-3.0.0.47/app# grep 'GET.*/repositories' controllers/katello/api/v2/repositories_controller.rb                                           api :GET, "/repositories", N_("List of enabled repositories")
    api :GET, "/content_views/:id/repositories", N_("List of repositories for a content view")
    api :GET, "/organizations/:organization_id/environments/:environment_id/repositories", _("List repositories in the environment")
    api :GET, "/products/:product_id/repositories", N_("List of repositories for a product")
    api :GET, "/environments/:environment_id/products/:product_id/repositories", N_("List of repositories belonging to a product in an environment")
    api :GET, "/repositories/repository_types", N_("Show the available repository types")
    api :GET, "/repositories/:id", N_("Show a repository")
    api :GET, "/repositories/:id/gpg_key_content", N_("Return the content of a repo gpg key, used directly by yum")

Comment 4 Peter Vreman 2016-08-08 13:55:59 UTC
Correction, this is not fully fixed in Sat6.2.0 GA.

It still requires https://github.com/Katello/katello/pull/5999

Comment 6 Peter Vreman 2017-10-04 08:04:37 UTC
In 6.2.12 the PR 5999 is still missing even that https://projects.theforeman.org/issues/14825 has release katello 3.0.0.

I think the PR5999 is also included in 6.3

Comment 7 Bryan Kearney 2017-11-28 18:08:38 UTC
Per Peter's comment, moving to 6.3 for verification. Jake, can you ack this please?

Comment 9 Peter Vreman 2017-11-29 15:32:52 UTC
I verified it, it was still broken, below is the patch

--- controllers/katello/api/v2/repositories_controller.rb.171129-1      2017-11-28 13:59:07.795809864 +0000
+++ controllers/katello/api/v2/repositories_controller.rb       2017-11-29 15:19:46.639184122 +0000
@@ -394,6 +394,7 @@

     def find_product
       @product = Product.find(params[:product_id]) if params[:product_id]
+      find_organization_from_product if @organization.nil? && @product
     end

     def find_product_for_create


Peter

Comment 10 Bryan Kearney 2017-11-29 16:12:45 UTC
Thanks.. I will send this off ot the triage group

Comment 12 Peter Vreman 2017-11-30 08:23:09 UTC
Sorry, my failure. I mixed up with remove/apply my custom patches.
The patch in comment 9 is not needed.

For verification test 'GET /products/:product_id/repositories' of is enough to make sure the PR 5999 is applied.

Peter

Comment 13 Brad Buckingham 2017-12-07 21:06:24 UTC
Moving to ON_QA for verification.

Comment 17 errata-xmlrpc 2018-02-21 12:30:53 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:0336