Last active
December 23, 2015 22:59
-
-
Save arnobroekhof/6707350 to your computer and use it in GitHub Desktop.
simple rest api for printing all facts from facter in json format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'facter' | |
| require 'json' | |
| require 'sinatra' | |
| ipaddress="172.16.132.2" | |
| # sinatra specific settings | |
| set :sessions, false | |
| set :logging, false | |
| set :dump_errors, false | |
| set :some_custom_option, false | |
| # Print everything if they didn't ask for specific facts. | |
| facts ||= Facter.to_hash | |
| error 403 do | |
| "Access forbidden" | |
| end | |
| get '/api/facts', :provides => 'json' do | |
| if request.ip == ipaddress | |
| content_type :json | |
| JSON.dump(facts) | |
| else | |
| 403 | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment