[PATCH/foreman 1/1] FEATURE #982 API call to get fact keys

Signed-off-by: Corey Osman <corey@logicminds.biz>

··· --- app/controllers/facts_controller.rb | 35 ++++++++++++++++++++++++++++++ config/routes.rb | 1 + test/functional/facts_controller_test.rb | 20 +++++++++++++++++ 3 files changed, 56 insertions(+), 0 deletions(-) create mode 100644 app/controllers/facts_controller.rb create mode 100644 test/functional/facts_controller_test.rb

diff --git a/app/controllers/facts_controller.rb b/app/controllers/facts_controller.rb
new file mode 100644
index 0000000…61724c2
— /dev/null
+++ b/app/controllers/facts_controller.rb
@@ -0,0 +1,35 @@
+class FactsController < ApplicationController
+

  • Shortcut

  • FactName = Puppet::Rails::FactName
  • #TODO: Create view templates for “just the facts” in the html branch.
  • def index
  • begin
  •  values = FactName.all(:select => "name", :conditions => ["fact_names.name <> ?","--- !ruby/sym _timestamp"])
    
  • rescue
  •  values = []
    
  • end
  • respond_to do |format|
  •  format.html { return not_found }
    
  •  format.json { render :json => values }
    
  • end
  • end
  • def show
  • return not_found if params[:id].blank?
  • begin
  •  values = FactName.find_by_name(params[:id]).fact_values
    
  • rescue
  •  values = []
    
  • end
  • respond_to do |format|
  •  format.html { return not_found  }
    
  •  format.json { render :json => values }
    
  • end
  • end

+end
diff --git a/config/routes.rb b/config/routes.rb
index 5a4df90…78a1daa 100644
— a/config/routes.rb
+++ b/config/routes.rb
@@ -42,6 +42,7 @@ ActionController::Routing::Routes.draw do |map|
map.resources :common_parameters, :collection => {:auto_complete_search => :get}
map.resources :environments, :collection => {:import_environments => :get, :obsolete_and_new => :post, :auto_complete_search => :get}
map.resources :fact_values, :only => [:create, :index], :collection => { :auto_complete_search => :get }

  • map.resources :facts, :only => [:index, :show]
    map.resources :ptables, :collection => {:auto_complete_search => :get}
    map.resources :roles, :collection => {:report => [:get, :post], :auto_complete_search => :get}
    map.resources :auth_source_ldaps
    diff --git a/test/functional/facts_controller_test.rb b/test/functional/facts_controller_test.rb
    new file mode 100644
    index 0000000…1190e6b
    — /dev/null
    +++ b/test/functional/facts_controller_test.rb
    @@ -0,0 +1,20 @@
    +require ‘test_helper’

+class FactsControllerTest < ActionController::TestCase
+

  • def test_index_json
  • get :index, {:format => “json”}, set_session_user
  • facts = ActiveSupport::JSON.decode(@response.body)
  • assert facts.is_a?(Array)
  • assert_response :success
  • end
  • def test_show_json
  • get :show, {:format => “json”, :id => “kernelversion”}, set_session_user
  • factvalues = ActiveSupport::JSON.decode(@response.body)
  • assert factvalues.is_a?(Array)
  • assert_response :success
  • end

+end
+

1.7.4.1