sss 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +0 -0
  2. data/bin/sss +56 -0
  3. data/lib/sss.rb +64 -0
  4. data/test/sss_test.rb +0 -0
  5. metadata +105 -0
data/README ADDED
File without changes
data/bin/sss ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ help = <<-EOS
4
+ SSS(1)
5
+
6
+ NAME
7
+ sss -- Copy files to your S3 buckets.
8
+
9
+ SYNOPSIS
10
+ sss -f file -k key bucket1 [bucket2 ...]
11
+
12
+ DESCRIPTION
13
+ Sss is a simple command line Ruby utility that allows you to copy
14
+ file to your Amazon S3 buckets.
15
+
16
+ The following options are available:
17
+
18
+ -f file
19
+ Specify a file to be copied.
20
+
21
+ -k key
22
+ Specify the key to be used for storing in S3. By default it uses
23
+ the file's basename, so if you have the file /foo/bar/baz.tgz, the
24
+ key is baz.tgz.
25
+
26
+ USAGE
27
+ To send a single file `/tmp/filename.tgz` to a single bucket `mybucket`:
28
+
29
+ $ sss -f /tmp/filename.tgz mybucket
30
+
31
+ If you wish to send multiple files to a single bucket:
32
+
33
+ $ sss -f /tmp/file1.tgz /tmp/file2.tgz mybucket
34
+
35
+ If you wish to send to multiple buckets in one go:
36
+
37
+ $ sss -f /tmp/file1.tgz mybucket1 mybucket2
38
+
39
+ EOS
40
+
41
+ require "clap"
42
+ require File.expand_path("../lib/sss", File.dirname(__FILE__))
43
+
44
+ begin
45
+ sss = Sss.new
46
+
47
+ buckets = Clap.run ARGV,
48
+ "-f" => sss.method(:add_file),
49
+ "-k" => sss.method(:use_key),
50
+ "--access" => sss.method(:access),
51
+ "--cache-control" => sss.method(:cache_control)
52
+
53
+ sss.upload(buckets)
54
+ rescue Sss::NoBuckets, Sss::NoFiles
55
+ puts help
56
+ end
@@ -0,0 +1,64 @@
1
+ class Sss
2
+ VERSION = "0.0.1"
3
+
4
+ NoBuckets = Class.new(StandardError)
5
+ NoFiles = Class.new(StandardError)
6
+
7
+ attr :files
8
+
9
+ def initialize
10
+ @files = []
11
+
12
+ @access_key_id = ENV["AMAZON_ACCESS_KEY_ID"]
13
+ @secret_access_key = ENV["AMAZON_SECRET_ACCESS_KEY"]
14
+ end
15
+
16
+ def add_file(file)
17
+ files << [file, File.basename(file)]
18
+ end
19
+
20
+ def use_key(key)
21
+ files.last[1] = key if files.any?
22
+ end
23
+
24
+ def upload(buckets)
25
+ raise NoBuckets if buckets.empty?
26
+ raise NoFiles if files.empty?
27
+
28
+ connect
29
+
30
+ buckets.each do |bucket|
31
+ puts "-----> Copying to #{bucket}"
32
+
33
+ files.each do |file, key|
34
+ AWS::S3::S3Object.store(key, File.open(file), bucket, options)
35
+ puts " #{key} -> #{file} (#{options.inspect})"
36
+ end
37
+ end
38
+ end
39
+
40
+ def access(access)
41
+ @access = access
42
+ end
43
+
44
+ def cache_control(cache_control)
45
+ @cache_control = cache_control
46
+ end
47
+
48
+ private
49
+ def connect
50
+ require "aws/s3"
51
+
52
+ AWS::S3::Base.establish_connection!(
53
+ access_key_id: @access_key_id,
54
+ secret_access_key: @secret_access_key
55
+ )
56
+ end
57
+
58
+ def options
59
+ {}.tap do |ret|
60
+ ret[:access] = @access.to_sym if defined?(@access)
61
+ ret["Cache-Control"] = @cache_control if defined?(@cache_control)
62
+ end
63
+ end
64
+ end
File without changes
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sss
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Cyril David
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-22 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: clap
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: aws-s3
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: cutest
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id003
59
+ description:
60
+ email: cyx@pipetodevnull.com
61
+ executables:
62
+ - sss
63
+ extensions: []
64
+
65
+ extra_rdoc_files: []
66
+
67
+ files:
68
+ - lib/sss.rb
69
+ - README
70
+ - test/sss_test.rb
71
+ - bin/sss
72
+ has_rdoc: true
73
+ homepage: http://github.com/cyx/sss
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.7
101
+ signing_key:
102
+ specification_version: 2
103
+ summary: Simple CLI interface for copying files to S3.
104
+ test_files: []
105
+