s3tatistic 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1a280d4769e8428c710252ddf3ef1dbc952e3f5
4
+ data.tar.gz: 9c04845ad85429683d3e28443446bf6201bdf048
5
+ SHA512:
6
+ metadata.gz: 5e92c81951296796e8d7fdcc86a43270579bc805bb0dcb4d6aa006869ae3b364e2835977e9821444d01741253d4c4e5ee7b90004d9226f0c95d141eca259f775
7
+ data.tar.gz: ed87bb2c998caf171e41ea017d932f6994a634a6321642b7626d19ef5495e1f7325832deda51d32213a2dded8ce7cb89a03210e78fe7602805c405d580c196c4
data/bin/s3tatistic ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 's3tatistic'
5
+ require 'commander/import'
6
+
7
+ program :name, 's3tatistic'
8
+ program :version, '0.1.0'
9
+ program :description, 'Show statistics for your S3 buckets!'
10
+
11
+ command :buckets do |c|
12
+ c.syntax = 's3tatistic buckets [options]'
13
+ c.summary = 'list all buckets names'
14
+ c.description = 'Shows a list of all the buckets avaliable'
15
+ # c.example 'description', 'command example'
16
+ c.option '--block SIZE', 'Shows the file size in (k/m/g/t)'
17
+ c.action do |args, options|
18
+ options.default \
19
+ block: 'k'
20
+ $VERBOSE = nil # temp fix until better formatter
21
+ buckets = S3tatistic::AmazonS3.buckets
22
+
23
+ puts S3tatistic::Formatter.format_buckets(buckets, options)
24
+ end
25
+ end
26
+
27
+ command :info do |c|
28
+ c.syntax = 's3tatistic info [options]'
29
+ c.summary = ''
30
+ c.description = ''
31
+ c.action do |args, options|
32
+ # Do something or c.when_called S3tatistic::Commands::Creation,
33
+ puts 'oh no, not yet implemented'
34
+ end
35
+ end
36
+
@@ -0,0 +1,43 @@
1
+ require 'aws-sdk'
2
+
3
+ class S3tatistic::AmazonS3
4
+ class << self
5
+ def ss3 # static s3
6
+ @@s3 ||= Aws::S3::Resource.new
7
+ end
8
+
9
+ def buckets
10
+ ss3.buckets.map(&:name).map {|b| info(b) rescue next}.select{|b| !b.nil?}
11
+ end
12
+
13
+ def info(bucket_name)
14
+ bucket = find_bucket(bucket_name)
15
+ objects = eager_objects(bucket) # AWS don't yield it correctly, so we get eager
16
+ {
17
+ name: bucket.name,
18
+ created_at: bucket.creation_date,
19
+ files_count: objects.count,
20
+ files_size: files_size(objects),
21
+ last_modified: last_modified(objects)
22
+ }
23
+ end
24
+
25
+ def find_bucket(name)
26
+ ss3.bucket(name)
27
+ end
28
+
29
+ def eager_objects(bucket)
30
+ eager_load = []
31
+ bucket.objects.each { |o| eager_load << o }
32
+ eager_load
33
+ end
34
+
35
+ def files_size(objects)
36
+ objects.map(&:size).reduce(&:+) # yay, functional ruby
37
+ end
38
+
39
+ def last_modified(objects)
40
+ objects.sort_by(&:last_modified).reverse.first.key
41
+ end
42
+ end
43
+ end
data/lib/s3tatistic.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'tty-table'
2
+
3
+ class S3tatistic
4
+ end
5
+
6
+ require 's3tatistic/amazon_s3'
7
+ require 's3tatistic/formatter'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3tatistic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julien Lucca
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: julienlucca@gmail.com
15
+ executables:
16
+ - s3tatistic
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/s3tatistic
21
+ - lib/s3tatistic.rb
22
+ - lib/s3tatistic/amazon_s3.rb
23
+ homepage:
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.10
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Show statistics for your S3 buckets!
47
+ test_files: []