Revision 90cc95ac
Added by Roberto almost 12 years ago
- ID 90cc95ac2ffba553276af362cff41711ce977529
bin/smart-proxy | ||
---|---|---|
require "dhcp_api" if SETTINGS.dhcp
|
||
require "features_api"
|
||
|
||
begin
|
||
require "facter"
|
||
require "facts_api"
|
||
rescue LoadError
|
||
warn "Facter was not found, Facts API disabled"
|
||
end
|
||
|
||
# we force webrick to allow SSL
|
||
set :server, "webrick"
|
||
set :port, SETTINGS.port if SETTINGS.port
|
lib/facts_api.rb | ||
---|---|---|
class SmartProxy < Sinatra::Base
|
||
get "/facts" do
|
||
begin
|
||
content_type :json
|
||
Facter.to_hash.to_json
|
||
rescue => e
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
get "/facts/:fact" do
|
||
begin
|
||
content_type :json
|
||
fact_value = Facter.fact(params[:fact].to_sym).value
|
||
log_halt 404, "Fact #{params[:fact]} not found" unless fact_value
|
||
{ params[:fact].to_sym => fact_value }.to_json
|
||
rescue => e
|
||
log_halt 400, e
|
||
end
|
||
end
|
||
|
||
end
|
Also available in: Unified diff
fixes #1797 - Added a REST interface for the Facts known about the proxy