Browse Source

S3 bucket display as well

Chris Mague 6 years ago
parent
commit
9cba723c76
4 changed files with 35 additions and 1 deletions
  1. 26 0
      lib/neoinfra/graph.rb
  2. 7 0
      web/controllers/graph.rb
  3. 1 0
      web/views/base_layout.erb
  4. 1 1
      web/views/graphview.erb

+ 26 - 0
lib/neoinfra/graph.rb

@@ -7,6 +7,8 @@ require 'fog-aws'
 require 'neo4j'
 require 'csv'
 require 'sinatra'
+require 's3'
+
 
 # NeoInfra Account information
 module NeoInfra
@@ -40,6 +42,30 @@ module NeoInfra
       end
       return csv_string.gsub('"', '')
     end
+ 
+    def graph_buckets
+      csv_string = CSV.generate(force_quotes: false ) do |csv|
+        csv << ['id,value']
+        csv << ['aws,']
+        @cfg = NeoInfra::Config.new
+        @cfg.accounts.each do |account|
+          csv << ["aws.#{account[:name]},"]
+
+          Bucket.all.select{|x| x.owner.name == account[:name]}.collect{|y| y.region.region}.uniq.each do |region|
+            csv << ["aws.#{account[:name]}.#{region},"]
+          end
+
+          Bucket.all.each do |bucket|
+            if bucket.owner.name == account[:name]
+              csv << ["aws.#{account[:name]}.#{bucket.region.region}.#{bucket.name.gsub("\.", ':')},1"]
+            end
+          end
+
+        end
+      end
+      return csv_string.gsub('"', '')
+    end
+       ##
 
   end
 end

+ 7 - 0
web/controllers/graph.rb

@@ -20,4 +20,11 @@ class Graph < Sinatra::Base
     g = NeoInfra::Graph.new
     g.graph_vpcs
   end
+
+  get '/buckets' do
+    headers('Content-Type' => "text/csv")
+    g = NeoInfra::Graph.new
+    g.graph_buckets
+  end
+
 end

+ 1 - 0
web/views/base_layout.erb

@@ -46,6 +46,7 @@
             <a class="nav-link dropdown-toggle" id="dropdown02" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Graphs</a>
             <div class="dropdown-menu" aria-labelledby="dropdown02">
               <a class="dropdown-item" href="/view/graph/vpcs">VPCs</a>
+              <a class="dropdown-item" href="/view/graph/buckets">S3 Buckets</a>
             </div>
           </li>
         </ul>

+ 1 - 1
web/views/graphview.erb

@@ -1,5 +1,5 @@
 <center><h3> <%= graph_type %></h3>
-<svg width="900" height="600"></svg></center>
+<svg width="1200" height="900"></svg></center>
 <script src="http://d3js.org/d3.v4.min.js"></script>
 <script>