Class: Jackal::Cfn::Event
- Inherits:
-
Jackal::Callback
- Object
- Jackal::Callback
- Jackal::Cfn::Event
- Includes:
- Utils, Utils::Http
- Defined in:
- lib/jackal-cfn/event.rb
Overview
Callback for event types
Defined Under Namespace
Modules: InheritedValidity
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
Update validity checks in subclasses.
Instance Method Summary collapse
-
#execute(message) ⇒ Object
Generate payload and drop.
-
#format_event(evt) ⇒ Smash
Format payload into proper event structure.
-
#unpack(message) ⇒ Smash
Unpack message and create payload.
-
#valid?(message) ⇒ TrueClass, FalseClass
Determine message validity.
Methods included from Utils::Http
Methods included from Utils
#snakecase, #transform_parameters
Class Method Details
.inherited(klass) ⇒ Object
Update validity checks in subclasses
34 35 36 37 38 |
# File 'lib/jackal-cfn/event.rb', line 34 def self.inherited(klass) klass.class_eval do include InheritedValidity end end |
Instance Method Details
#execute(message) ⇒ Object
Generate payload and drop
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/jackal-cfn/event.rb', line 105 def execute() data_payload = unpack() payload = new_payload( config[:name], :cfn_event => data_payload ) if(config[:reprocess]) debug "Reprocessing payload through current source (#{destination(:input, payload)})" Carnivore::Supervisor.supervisor[destination(:input, payload)].transmit(payload) .confirm! else job_completed(:jackal_cfn, payload, ) end end |
#format_event(evt) ⇒ Smash
Format payload into proper event structure
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jackal-cfn/event.rb', line 81 def format_event(evt) parts = evt.split("\n").map do |entry| chunks = entry.split('=') key = chunks.shift.strip value = chunks.join.strip.sub(/^'/, '').sub(/'$/, '').strip [key, value] end event = Smash[parts] unless(event['ResourceProperties'].to_s.empty?) begin event['ResourceProperties'] = MultiJson.load(event['ResourceProperties']) rescue MultiJson::LoadError => e error "Failed to load `ResourceProperties`: #{e.class} - #{e}" debug "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" end else event['ResourceProperties'] = {} end Smash.new(Carnivore::Utils.symbolize_hash(event)) end |
#unpack(message) ⇒ Smash
Unpack message and create payload
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jackal-cfn/event.rb', line 44 def unpack() payload = super if(self.class == Jackal::Cfn::Event) begin unless(payload.get(:data, :cfn_event)) payload = format_event(payload.fetch('Body', 'Message', payload)) payload[:origin_type] = [:message].get('Body', 'Type') payload[:origin_subject] = [:message].get('Body', 'Subject') end payload rescue Smash.new end else payload.to_smash.fetch('Body', payload.to_smash) end end |
#valid?(message) ⇒ TrueClass, FalseClass
Determine message validity
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/jackal-cfn/event.rb', line 66 def valid?() super do |payload| if(block_given?) yield payload else payload[:origin_type] == 'Notification' && payload[:origin_subject].downcase.include?('cloudformation notification') end end end |