Class: Proxy::HostReports::Api
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Proxy::HostReports::Api
- Includes:
- Log, Util
- Defined in:
- lib/smart_proxy_host_reports/host_reports_api.rb
Constant Summary collapse
- EXTS =
{ puppet: "yaml", ansible: "json", }.freeze
Instance Method Summary collapse
Instance Method Details
#check_content_type(format) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/smart_proxy_host_reports/host_reports_api.rb', line 18 def check_content_type(format) request_type = request.env["CONTENT_TYPE"] if format == "puppet" log_halt(415, "Content type must be application/x-yaml, was: #{request_type}") unless request_type.start_with?("application/x-yaml") elsif format == "ansible" log_halt(415, "Content type must be application/json, was: #{request_type}") unless request_type.start_with?("application/json") else log_halt(415, "Unknown format: #{format}") end end |
#save_payload(input, format) ⇒ Object
34 35 36 37 |
# File 'lib/smart_proxy_host_reports/host_reports_api.rb', line 34 def save_payload(input, format) filename = File.join(Proxy::HostReports::Plugin.settings.incoming_save_dir, "#{format}-#{Time.now.to_i}.#{EXTS[format.to_sym]}") File.open(filename, "w") { |f| f.write(input) } end |