Class: Proxy::Omaha::OmahaProtocol::Handler

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/smart_proxy_omaha/omaha_protocol/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Handler

Returns a new instance of Handler.



8
9
10
11
12
13
# 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

Instance Attribute Details

#foreman_clientObject (readonly)

Returns the value of attribute foreman_client.



6
7
8
# File 'lib/smart_proxy_omaha/omaha_protocol/handler.rb', line 6

def foreman_client
  @foreman_client
end

#metadata_providerObject (readonly)

Returns the value of attribute metadata_provider.



6
7
8
# File 'lib/smart_proxy_omaha/omaha_protocol/handler.rb', line 6

def 
  @metadata_provider
end

#repositoryObject (readonly)

Returns the value of attribute repository.



6
7
8
# File 'lib/smart_proxy_omaha/omaha_protocol/handler.rb', line 6

def repository
  @repository
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/smart_proxy_omaha/omaha_protocol/handler.rb', line 6

def request
  @request
end

Instance Method Details

#handleObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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