Uploaded image for project: 'Red Hat 3scale API Management'
  1. Red Hat 3scale API Management
  2. THREESCALE-7676

Fix database triggers that set tenant_id of some tables

XMLWordPrintable

      It looks like backend_apis table trigger to set the tenant_id is incorrect. As reported by a customer, the tenant_id is always NULL

      This also applies to log_entries and alerts tables.

       

      Creating a backend_api then checking if the object was there, the API returned a 403 instead of a 200 because of this check

      https://github.com/3scale/porta/blob/d80837b6ce6dababacdae814c01699d533f40795/app/controllers/admin/api/objects_controller.rb#L42

       

      # Backend Create

      curl -v  -X POST "https://3scale-admin.$OCP_DOMAIN/admin/api/backend_apis.json" -d "access_token=${ACCESS_TOKEN}&name=test-deletion-backend&system_name=test-deletion-backend&description=test-deletion-backend&private_endpoint=https%3A%2F%2Fdymmy-endpoint"

      # Object deletion status for objects that are deleted asynchronously
      
curl -v  -X GET "https://3scale-admin.$OCP_DOMAIN/admin/api/objects/status.json?access_token=${ACCESS_TOKEN}&object_type=backend_api&object_id=9"

      => status code: 403
      
# Backend Delete
curl -v  -X DELETE "https://3scale-admin.$OCP_DOMAIN/admin/api/backend_apis/9.json" -d "access_token=${ACCESS_TOKEN}"

      # Object deletion status for objects that are deleted asynchronously

      curl -v  -X GET "https://3scale-admin.$OCP_DOMAIN/admin/api/objects/status.json?access_token=${ACCESS_TOKEN}&object_type=backend_api&object_id=9"
      
=> status code: 404 

      Dev Notes

      The triggers in cause:

      https://github.com/3scale/porta/blob/3d9545fd101df52cd8bc652c095b21432ddcd758/lib/system/database/definitions/mysql.rb#L438

      The investigation leads to the below query is always returning empty record, as by default, the field master in the accounts table is NULL

      SELECT tenant_id FROM accounts WHERE NOT master 

      Solution:

      1. quick work-around: when creating a provider, set the field master to false. Then fix the field in the database setting it to false when it is NULL.

      2. programatically set the tenant_id for those models instead of relying on the trigger. The trigger is noop in case tenant_id is set anyway.

              Unassigned Unassigned
              hramihaj Hery Ramihajamalala (Inactive)
              Dominik Hlavac Duran Dominik Hlavac Duran
              Aleksandar Kostadinov Aleksandar Kostadinov
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: