Sha256: 225b4ec8a3cc5818a5bf43bf2f18a215f4157b605a1357028a779df4d3dd2cd9

Contents?: true

Size: 2 KB

Versions: 19

Compression:

Stored size: 2 KB

Contents

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

    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

19 entries across 19 versions & 1 rubygems

Version Path
katello-3.1.0.1 app/controllers/katello/api/v2/root_controller.rb
katello-3.1.0 app/controllers/katello/api/v2/root_controller.rb
katello-3.1.0.rc2.1 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.2 app/controllers/katello/api/v2/root_controller.rb
katello-2.4.5 app/controllers/katello/api/v2/root_controller.rb
katello-3.1.0.rc1 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.1 app/controllers/katello/api/v2/root_controller.rb
katello-2.4.4 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0 app/controllers/katello/api/v2/root_controller.rb
katello-2.4.3 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0.rc7 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0.rc5 app/controllers/katello/api/v2/root_controller.rb
katello-2.4.2 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0.rc4 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0.rc3 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0.rc2 app/controllers/katello/api/v2/root_controller.rb
katello-3.0.0.rc1 app/controllers/katello/api/v2/root_controller.rb
katello-2.4.1 app/controllers/katello/api/v2/root_controller.rb
katello-2.4.0 app/controllers/katello/api/v2/root_controller.rb