summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/agents/events_controller.rb8
-rw-r--r--app/controllers/api/agents/events_controller.rb9
-rw-r--r--app/controllers/api/agents/files_controller.rb7
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--app/controllers/dispositions_controller.rb11
5 files changed, 28 insertions, 13 deletions
diff --git a/app/controllers/agents/events_controller.rb b/app/controllers/agents/events_controller.rb
index 6827938..30ca295 100644
--- a/app/controllers/agents/events_controller.rb
+++ b/app/controllers/agents/events_controller.rb
@@ -11,9 +11,11 @@ module Agents
end
def create
- message = event_params.merge({agent_id: @agent.id})
- routing_key = "events.#{event_params[:type]}.#{@agent.id}"
- Publisher.publish(routing_key, message)
+ publish(EventMessage.new(
+ agent_id: @agent.id,
+ event_type: event_params[:event_type],
+ data: event_params[:data]
+ ))
redirect_to agent_events_url, notice: 'Event was successfully created.'
end
diff --git a/app/controllers/api/agents/events_controller.rb b/app/controllers/api/agents/events_controller.rb
index 255a5bc..ca9b829 100644
--- a/app/controllers/api/agents/events_controller.rb
+++ b/app/controllers/api/agents/events_controller.rb
@@ -3,9 +3,12 @@ module Api
class EventsController < ApplicationController
def create
@agent = Agent.find(params[:agent_id])
- message = event_params.merge({agent_id: @agent.id})
- routing_key = "events.#{event_params[:type]}.#{@agent.id}"
- Publisher.publish(routing_key, message)
+ publish(EventMessage.new(
+ agent_id: @agent.id,
+ event_type: event_params[:event_type],
+ data: event_params[:data]
+ ))
+
render nothing: true
end
diff --git a/app/controllers/api/agents/files_controller.rb b/app/controllers/api/agents/files_controller.rb
index 1329d04..b111048 100644
--- a/app/controllers/api/agents/files_controller.rb
+++ b/app/controllers/api/agents/files_controller.rb
@@ -9,12 +9,11 @@ module Api
@agent = Agent.find(params[:agent_id])
@fingerprint = params[:id]
@file = Disposition.find_by(fingerprint: params[:id])
- message = {
+ publish(EventMessage.new(
agent_id: @agent.id,
- type: :lookup,
+ event_type: :scanned,
data: params[:data]
- }
- Publisher.publish("events.scanned.#{@agent.id}", message)
+ ))
end
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 84e9c93..8ce68a5 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -3,4 +3,10 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
#protect_from_forgery with: :exception
protect_from_forgery with: :null_session
+
+ protected
+
+ def publish(message)
+ Publisher.publish(message)
+ end
end
diff --git a/app/controllers/dispositions_controller.rb b/app/controllers/dispositions_controller.rb
index 17f8657..e63f696 100644
--- a/app/controllers/dispositions_controller.rb
+++ b/app/controllers/dispositions_controller.rb
@@ -18,14 +18,19 @@ class DispositionsController < ApplicationController
end
def create
- fingerprint = disposition_params[:fingerprint]
- Publisher.publish("commands.poke.#{fingerprint}", disposition_params)
+ publish(PokeMessage.new(
+ fingerprint: disposition_params[:fingerprint],
+ state: disposition_params[:state],
+ ))
redirect_to dispositions_path, notice: 'Disposition was successfully created.'
end
def update
- Publisher.publish("poke", disposition_params)
+ publish(PokeMessage.new(
+ fingerprint: disposition_params[:fingerprint],
+ state: disposition_params[:state],
+ ))
redirect_to dispositions_path, notice: 'Disposition was successfully updated.'
end