Sha256: 4bd53255d1c9bb7d53922a4893202a5fd0527a036542a9b726dbb00b86af5a43

Contents?: true

Size: 1.96 KB

Versions: 124

Compression:

Stored size: 1.96 KB

Contents

module Katello
  class Api::V2::RootController < Api::V2::ApiController
    skip_before_action :authorize # ok - only shows URLs available

    resource_description do
      api_version 'v2'
      api_base_url "/katello/api"
    end

    def resource_list
      all_routes = Engine.routes.routes
      all_routes = all_routes.collect { |r| r.path.spec.to_s }

      api_root_routes = all_routes.select do |path|
        path =~ %r{^/katello/api(\(/:api_version\))?/[^/]+/:id\(\.:format\)$}
      end
      api_root_routes = api_root_routes.collect do |path|
        path = path.sub("(/:api_version)", "")
        path[0..-(":id(.:format)".length + 1)]
      end

      api_root_routes.collect! { |r| { :rel => r["/katello/api/".size..-2], :href => r } }

      respond_for_index :collection => api_root_routes
    end

    def rhsm_resource_list
      # The RHSM resource list is required to interact with RHSM on the client.
      # When requested, it will return a list of the resources (href & rel) defined by katello
      # for the /rhsm namespace.  The rel values are used by RHSM to determine if the server
      # supports a particular resource (e.g. environments, guestids, organizations..etc)

      all_routes = Engine.routes.routes.collect { |r| r.path.spec.to_s }

      api_routes = all_routes.select do |path|
        # obtain only the rhsm routes
        path =~ %r{^/rhsm/.+$}
      end

      api_routes = api_routes.collect do |path|
        # drop the trailing :format
        path = path.sub("(.:format)", "")

        # drop the trailing ids
        path_elements = path.split("/")
        if path_elements.last.start_with?(':') && path_elements.last.end_with?('id')
          path_elements.delete_at(-1)
          path_elements.join('/')
        else
          path
        end
      end

      api_routes.uniq!
      api_routes.collect! { |r| { :rel => r.split('/').last, :href => r } }

      respond_for_index :collection => api_routes, :template => 'resource_list'
    end
  end
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
katello-4.2.2 app/controllers/katello/api/v2/root_controller.rb
katello-4.3.0.rc1 app/controllers/katello/api/v2/root_controller.rb
katello-4.2.1 app/controllers/katello/api/v2/root_controller.rb
katello-4.2.0.1 app/controllers/katello/api/v2/root_controller.rb
katello-4.1.4 app/controllers/katello/api/v2/root_controller.rb
katello-4.0.3 app/controllers/katello/api/v2/root_controller.rb
katello-4.2.0.1.rc3 app/controllers/katello/api/v2/root_controller.rb
katello-3.18.5 app/controllers/katello/api/v2/root_controller.rb
katello-4.2.0.1.rc2 app/controllers/katello/api/v2/root_controller.rb
katello-4.2.0.rc2 app/controllers/katello/api/v2/root_controller.rb
katello-4.1.3 app/controllers/katello/api/v2/root_controller.rb
katello-4.2.0.rc1 app/controllers/katello/api/v2/root_controller.rb
katello-4.0.2.1 app/controllers/katello/api/v2/root_controller.rb
katello-4.1.2.1 app/controllers/katello/api/v2/root_controller.rb
katello-4.0.2 app/controllers/katello/api/v2/root_controller.rb
katello-4.1.2 app/controllers/katello/api/v2/root_controller.rb
katello-3.18.4 app/controllers/katello/api/v2/root_controller.rb
katello-4.1.1 app/controllers/katello/api/v2/root_controller.rb
katello-4.1.0 app/controllers/katello/api/v2/root_controller.rb
katello-4.0.1.2 app/controllers/katello/api/v2/root_controller.rb