summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-02-03 22:14:00 -0700
committermo khan <mo@mokhan.ca>2015-02-03 22:14:00 -0700
commit3371919560ef37fac3f59c95ad4cf2f6a472ef57 (patch)
treef158207e234353b33298e640bac0510a9782a3bd /app
parent4827894034d47962bfc6c51472c9ed2617ebf3a9 (diff)
add endpoint for cloud lookup.
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/files.coffee3
-rw-r--r--app/assets/stylesheets/files.scss3
-rw-r--r--app/controllers/agents/files_controller.rb25
-rw-r--r--app/helpers/files_helper.rb2
-rw-r--r--app/views/agents/files/index.json.jbuilder4
-rw-r--r--app/views/agents/files/show.json.jbuilder3
-rw-r--r--app/views/agents/index.html.erb3
7 files changed, 42 insertions, 1 deletions
diff --git a/app/assets/javascripts/files.coffee b/app/assets/javascripts/files.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/files.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/files.scss b/app/assets/stylesheets/files.scss
new file mode 100644
index 0000000..febd8a7
--- /dev/null
+++ b/app/assets/stylesheets/files.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the files controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/agents/files_controller.rb b/app/controllers/agents/files_controller.rb
new file mode 100644
index 0000000..9afd766
--- /dev/null
+++ b/app/controllers/agents/files_controller.rb
@@ -0,0 +1,25 @@
+module Agents
+ class FilesController < ApplicationController
+ before_action :load_agent
+ before_action do
+ request.format = :json
+ end
+
+ def index
+ end
+
+ def show
+ @file = Disposition.find_by(fingerprint: params[:id])
+ Publisher.publish("queries", {
+ fingerprint: params[:id],
+ data: params
+ })
+ end
+
+ private
+
+ def load_agent
+ Agent.find(params[:agent_id])
+ end
+ end
+end
diff --git a/app/helpers/files_helper.rb b/app/helpers/files_helper.rb
new file mode 100644
index 0000000..e9da4f6
--- /dev/null
+++ b/app/helpers/files_helper.rb
@@ -0,0 +1,2 @@
+module FilesHelper
+end
diff --git a/app/views/agents/files/index.json.jbuilder b/app/views/agents/files/index.json.jbuilder
new file mode 100644
index 0000000..6551a44
--- /dev/null
+++ b/app/views/agents/files/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@files) do |file|
+ json.extract! agent, :fingerprint, :state
+ json.url agent_file_url([agent, file], format: :json)
+end
diff --git a/app/views/agents/files/show.json.jbuilder b/app/views/agents/files/show.json.jbuilder
new file mode 100644
index 0000000..88011e6
--- /dev/null
+++ b/app/views/agents/files/show.json.jbuilder
@@ -0,0 +1,3 @@
+if @file
+ json.extract! @file, :fingerprint, :state
+end
diff --git a/app/views/agents/index.html.erb b/app/views/agents/index.html.erb
index 3a6b738..a1021ed 100644
--- a/app/views/agents/index.html.erb
+++ b/app/views/agents/index.html.erb
@@ -9,7 +9,7 @@
<thead>
<tr>
<th>Hostname</th>
- <th colspan="4"></th>
+ <th colspan="5"></th>
</tr>
</thead>
<tbody>
@@ -17,6 +17,7 @@
<tr>
<td><%= agent.hostname %></td>
<td><%= link_to 'Events', agent_events_path(agent) %></td>
+ <td><%= link_to 'Files', agent_files_path(agent) %></td>
<td><%= link_to 'Show', agent %></td>
<td><%= link_to 'Edit', edit_agent_path(agent) %></td>
<td><%= link_to 'Destroy', agent, method: :delete, data: { confirm: 'Are you sure?' } %></td>