class Proxy::Omaha::OmahaProtocol::Handler
Attributes
foreman_client[R]
metadata_provider[R]
repository[R]
request[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 8 def initialize(options = {}) @request = options.fetch(:request) @foreman_client = options.fetch(:foreman_client) @repository = options.fetch(:repository) @metadata_provider = options.fetch(:metadata_provider) end
Public Instance Methods
handle()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 15 def handle logger.info "OmahaHandler: Received #{request.event_description} event with result: #{request.event_result}" unless request.from_coreos? logger.error "Appid does not match CoreOS. Aborting Omaha request." return Proxy::Omaha::OmahaProtocol::Eventacknowledgeresponse.new( :appid => request.appid, :base_url => request.base_url, :status => 'error-unknownApplication' ) end unless Proxy::Omaha::Track.valid?(request.track) logger.error "Unknown track requested. Aborting Omaha request." return Proxy::Omaha::OmahaProtocol::Eventacknowledgeresponse.new( :appid => request.appid, :base_url => request.base_url, :status => 'error-unknownApplication' ) end upload_facts process_report if request.event? if request.updatecheck? handle_update elsif request.event? handle_event elsif request.ping? handle_ping else logger.info "OmahaHandler: Unknown request." handle_error end rescue StandardError => e logger.error("OmahaHandler: Aw, Snap! Error: #{e}", e.backtrace) handle_error end
Private Instance Methods
handle_error()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 76 def handle_error Proxy::Omaha::OmahaProtocol::Errorinternalresponse.new( :appid => request.appid, :base_url => request.base_url, :status => 'error-internal', ) end
handle_event()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 60 def handle_event logger.info "OmahaHandler: Processing event." Proxy::Omaha::OmahaProtocol::Eventacknowledgeresponse.new( :appid => request.appid, :base_url => request.base_url ) end
handle_ping()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 68 def handle_ping logger.info "OmahaHandler: Processing ping." Proxy::Omaha::OmahaProtocol::Pingresponse.new( :appid => request.appid, :base_url => request.base_url ) end
handle_update()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 97 def handle_update latest_os = repository.latest_os(request.track, request.board) if !latest_os.nil? && latest_os.version > Gem::Version.new(request.version) logger.info "OmahaHandler: Offering update from #{request.version} to #{latest_os.version}" Proxy::Omaha::OmahaProtocol::Updateresponse.new( :appid => request.appid, :metadata => metadata_provider.get(request.track, latest_os, request.board), :board => request.board, :base_url => request.base_url, :name => latest_os.update_filename ) else logger.info "OmahaHandler: No update." Proxy::Omaha::OmahaProtocol::Noupdateresponse.new( :appid => request.appid, :base_url => request.base_url ) end end
process_report()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 84 def process_report report = { 'host' => request.hostname, 'status' => request.to_status.to_s, 'omaha_version' => request.version, 'machineid' => request.machineid, 'omaha_group' => request.track, 'oem' => request.oem, 'reported_at' => report_timestamp } foreman_client.post_report({'omaha_report' => report}.to_json) end
report_timestamp()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 117 def report_timestamp Time.now.getutc.to_s end
upload_facts()
click to toggle source
# File lib/smart_proxy_omaha/omaha_protocol/handler.rb, line 56 def upload_facts foreman_client.post_facts(request.facts_data.to_json) end