presigner 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd5bde556dc86fa8d6e946e1cd9c423e7cd29cf1
4
+ data.tar.gz: df74d7f9af9bfd23812b94426ae090cc41b20697
5
+ SHA512:
6
+ metadata.gz: 952044ea5da7766be47a7557694dbdfeca4ae7d363ef59a5f72b00ab1008d6a1a5594fb3f7bdfa0034fe001de55249d956102d663db67d158ec3330de534c86f
7
+ data.tar.gz: b3c192704a994e667b770575a6a6931a4eb5aac038ee30a006c810639d17aa8153abed69b257e972bf836bd95302725727ade19e3e8a237c33067f9a95902615
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ Guardfile
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in presigner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Masao Mochizuki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Presigner
2
+
3
+ Presigner is a CLI tool to generate Pre-Signed URL for Amazon S3.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'presigner'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install presigner
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ $ presigner --bucket foobucket --key bar.txt --duration 3600 --profile default
25
+ ```
26
+
27
+ - Currently, You can provide duration only in seconds.
28
+ - ``--profile`` option is the value for ~/.aws/credentials. You should write your credentials in the file. ref: http://blogs.aws.amazon.com/security/post/Tx3D6U6WSFGOK2H/A-New-and-Standardized-Way-to-Manage-Credentials-in-the-AWS-SDKs
29
+
30
+ ## TODO
31
+
32
+ - Support another credential provider
33
+ - ``--expires`` option. It might contain time in a word (e.g. '1h' or '30min')
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/presigner/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+
6
+ desc 'Run test_unit based test'
7
+ Rake::TestTask.new do |t|
8
+ # To run test for only one file (or file path pattern)
9
+ # $ bundle exec rake test TEST=test/test_specified_path.rb
10
+ t.libs << "test"
11
+ t.test_files = Dir["test/**/test_*.rb"]
12
+ # t.verbose = true
13
+ end
data/bin/presigner ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'presigner'
4
+ require 'thor'
5
+
6
+ class PresignerCLI < Thor
7
+ option :bucket, :required => true
8
+ option :key, :required => true
9
+ option :profile
10
+ option :duration
11
+ desc "generate", "generate S3 presigned URL"
12
+
13
+ def generate
14
+ presigner= Presigner.new(options)
15
+ url = presigner.generate
16
+ $stdout.puts url
17
+ end
18
+ end
19
+
20
+ PresignerCLI::start()
data/lib/presigner.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "presigner/version"
2
+
3
+ require 'aws-sdk-v1'
4
+ require 'pry'
5
+
6
+ class Presigner
7
+
8
+ DEFAULT_DURATION = 60 * 30
9
+
10
+ def initialize(options)
11
+ prov = AWS::Core::CredentialProviders::
12
+ SharedCredentialFileProvider.new(profile_name: options[:profile])
13
+ AWS.config(credential_provider: prov)
14
+ @bucket = options[:bucket]
15
+ @key = options[:key]
16
+ @duration = options[:duration].nil? ? DEFAULT_DURATION : options[:duration].to_i
17
+ @base = Time.now.to_i
18
+ end
19
+
20
+ attr_reader :duration, :base, :bucket, :key
21
+
22
+ def generate
23
+
24
+ s3 = AWS::S3.new
25
+ # check if specified bucket and key exist.
26
+ target_obj = s3.buckets[bucket].objects[key]
27
+ if !target_obj.exists?
28
+ $stderr.puts "Specified bucket or key does not exist."
29
+ exit 1
30
+ end
31
+
32
+ presigner = AWS::S3::PresignV4.new(target_obj)
33
+ expires = calc_duration
34
+
35
+ url = presigner.presign(:get, expires: expires, secure: true)
36
+ url
37
+ end
38
+
39
+ def calc_duration
40
+ base + duration
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ class Presigner
2
+ VERSION = "0.0.1"
3
+ end
data/presigner.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'presigner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "presigner"
8
+ spec.version = Presigner::VERSION
9
+ spec.authors = ["Masao Mochizuki"]
10
+ spec.email = ["mochizukimasao.030@gmail.com"]
11
+ spec.summary = %q{CLI Tool to generate Pre-Signed URL for Amazon S3}
12
+ spec.description = %q{Presigner is a CLI tool to simple generate Pre-Signed URL for Amazon S3}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "test-unit", "~> 3.0"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-shell"
26
+
27
+ spec.add_dependency "thor"
28
+ spec.add_dependency "aws-sdk-v1"
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'presigner'
4
+
5
+ class PresignerTest < Test::Unit::TestCase
6
+ class << self
7
+ def startup
8
+ end
9
+
10
+ def shutdown
11
+ end
12
+ end
13
+
14
+ def setup
15
+ options = {
16
+ :bucket => 'foobucket',
17
+ :key => 'barkey'
18
+ }
19
+ @presigner = Presigner.new(options)
20
+ end
21
+
22
+ def cleanup
23
+ end
24
+
25
+ def teardown
26
+ end
27
+
28
+ test "check if duration calculation is correct" do
29
+ actual = @presigner.calc_duration
30
+ assert_equal(actual, @presigner.base + Presigner::DEFAULT_DURATION)
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: presigner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masao Mochizuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-shell
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aws-sdk-v1
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Presigner is a CLI tool to simple generate Pre-Signed URL for Amazon
112
+ S3
113
+ email:
114
+ - mochizukimasao.030@gmail.com
115
+ executables:
116
+ - presigner
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/presigner
128
+ - lib/presigner.rb
129
+ - lib/presigner/version.rb
130
+ - presigner.gemspec
131
+ - test/test_presigner.rb
132
+ homepage: ''
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: CLI Tool to generate Pre-Signed URL for Amazon S3
156
+ test_files:
157
+ - test/test_presigner.rb
158
+ has_rdoc: