summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/agents/events_controller.rb22
-rw-r--r--app/controllers/api/agents/files_controller.rb20
-rw-r--r--app/controllers/api/agents_controller.rb11
-rw-r--r--app/controllers/api/api_controller.rb10
4 files changed, 63 insertions, 0 deletions
diff --git a/app/controllers/api/agents/events_controller.rb b/app/controllers/api/agents/events_controller.rb
new file mode 100644
index 0000000..56b566f
--- /dev/null
+++ b/app/controllers/api/agents/events_controller.rb
@@ -0,0 +1,22 @@
+module Api
+ module Agents
+ class EventsController < ApiController
+ def create
+ @agent = Agent.find(params[:agent_id])
+ publish(EventMessage.new(
+ agent_id: @agent.id,
+ event_type: event_params[:type],
+ data: event_params[:data]
+ ))
+
+ render nothing: true
+ end
+
+ private
+
+ def event_params
+ params[:event]
+ end
+ end
+ end
+end
diff --git a/app/controllers/api/agents/files_controller.rb b/app/controllers/api/agents/files_controller.rb
new file mode 100644
index 0000000..c13eac9
--- /dev/null
+++ b/app/controllers/api/agents/files_controller.rb
@@ -0,0 +1,20 @@
+module Api
+ module Agents
+ class FilesController < ApiController
+ before_action do
+ request.format = :json
+ end
+
+ def show
+ @agent = Agent.find(params[:agent_id])
+ @fingerprint = params[:id]
+ @file = Disposition.find_by(fingerprint: params[:id])
+ publish(EventMessage.new(
+ agent_id: @agent.id,
+ event_type: :scanned,
+ data: params[:data]
+ ))
+ end
+ end
+ end
+end
diff --git a/app/controllers/api/agents_controller.rb b/app/controllers/api/agents_controller.rb
new file mode 100644
index 0000000..a7307f0
--- /dev/null
+++ b/app/controllers/api/agents_controller.rb
@@ -0,0 +1,11 @@
+module Api
+ class AgentsController < ApiController
+ def create
+ @agent = Agent.create!(agent_params)
+ end
+
+ def agent_params
+ params.require(:agent).permit(:hostname)
+ end
+ end
+end
diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb
new file mode 100644
index 0000000..6954700
--- /dev/null
+++ b/app/controllers/api/api_controller.rb
@@ -0,0 +1,10 @@
+module Api
+ class ApiController < ActionController::Base
+ protect_from_forgery with: :null_session
+ protected
+
+ def publish(message)
+ Publisher.publish(message)
+ end
+ end
+end