s3_signed_url 0.1.2

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: e89d7163d358dadabdb1ec032ca482bfe42e4d17
4
+ data.tar.gz: 859da70891af6af7131d6cd942639f90de7dbb11
5
+ SHA512:
6
+ metadata.gz: 3ba85983786c2efd8fdb676910a4460cac86e76c11770b1dee400d924df706ad5307daaa60ac007aa35a09822b7c8876a5886ea09fc6ac3a1cd5f81656de0de1
7
+ data.tar.gz: 4c9935f0136c2991ae60b54a208392d79457e67566cc7e1780715f347b0905556580582f3b65ec69a86048dda917284066549fc8ffd0cae8a92119319b460c69
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in s3_signed_url.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # s3_signed_url
2
+
3
+ s3_signed_url generates signed URLs to get S3 objects.
4
+
5
+ Our backend is described in [official documetns](http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 's3_signed_url'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install s3_signed_url
22
+
23
+ Ands 3_signed_url requires `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_REGION`.
24
+ So you should get them from AWS IAM, and set in `~/.aws/credentials` or environment variables.
25
+
26
+ ## Usage
27
+
28
+
29
+ Generate URL for s3://examplebucket/test.txt:
30
+
31
+ $ s3_signed_url s3://examplebucket/test.txt
32
+ https://s3.amazonaws.com/examplebucket/test.txt?...
33
+
34
+ The generated uses HTTPS by default. To use HTTP, append `--no-secure` option:
35
+
36
+ $ s3_signed_url s3://examplebucket/test.txt --no-secure
37
+ http://s3.amazonaws.com/examplebucket/test.txt?...
38
+
39
+ And generated URLs expires in 15 minutes by default. If you want to set it manually, append `--expire` option with the number of seconds:
40
+
41
+ $ s3_signed_url s3://examplebucket/test.txt --expire 1800
42
+ https://s3.amazonaws.com/examplebucket/test.txt?...
43
+
44
+ If you want to upload a new file and generated a signed url for it, append `--upload` option with the path to file:
45
+
46
+ $ s3_signed_url s3://examplebucket/test.txt --upload /path/to/test.txt
47
+ https://s3.amazonaws.com/examplebucket/test.txt?...
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/a2ikm/s3_signed_url/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "s3_signed_url"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/s3_signed_url ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "s3_signed_url"
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |op|
9
+ op.version = S3SignedUrl::VERSION
10
+ op.banner = "Usage: s3_signed_url URL [--upload FILE]"
11
+
12
+ op.on "-e", "--expire SECONDS", "The number of seconds before the presigned URL expires. Defaults: 900 (15 min)" do |v|
13
+ options[:expire] = v
14
+ end
15
+
16
+ op.on "-u", "--upload FILE", "Upload the file for the URL" do |v|
17
+ options[:upload] = v
18
+ end
19
+
20
+ op.on "-s", "--[no-]secure", "Use HTTPS or not. Default: true" do |v|
21
+ options[:secure] = v
22
+ end
23
+ end.parse!(ARGV)
24
+
25
+ url = ARGV[0]
26
+ S3SignedUrl::Cli.new(url, options).run
@@ -0,0 +1,63 @@
1
+ require "uri"
2
+ require "aws-sdk"
3
+
4
+ module S3SignedUrl
5
+ class Cli
6
+ attr_reader :s3_uri, :options
7
+
8
+ def initialize(s3_url, options = {})
9
+ @s3_uri = URI(s3_url)
10
+ @options = options
11
+ end
12
+
13
+ def run
14
+ upload
15
+ presigned_url = generate_presigned_url
16
+
17
+ puts presigned_url
18
+ end
19
+
20
+ private
21
+
22
+ def upload
23
+ return unless options.key?(:upload)
24
+
25
+ path = options[:upload]
26
+ object_body = File.read(File.expand_path(path))
27
+
28
+ client.put_object(
29
+ bucket: bucket_name,
30
+ body: object_body,
31
+ key: object_key
32
+ )
33
+ end
34
+
35
+ def generate_presigned_url
36
+ opts = {
37
+ bucket: bucket_name,
38
+ key: object_key,
39
+ secure: options[:secure]
40
+ }
41
+
42
+ opts[:expires_in] = options[:expire].to_i if options.key?(:expire)
43
+
44
+ signer.presigned_url(:get_object, opts)
45
+ end
46
+
47
+ def signer
48
+ @signer ||= Aws::S3::Presigner.new(client: client)
49
+ end
50
+
51
+ def client
52
+ @client ||= Aws::S3::Client.new
53
+ end
54
+
55
+ def bucket_name
56
+ @s3_uri.host
57
+ end
58
+
59
+ def object_key
60
+ @s3_uri.path.sub(%r{\A/}, "")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module S3SignedUrl
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "s3_signed_url/version"
2
+ require "s3_signed_url/cli"
3
+
4
+ module S3SignedUrl
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 's3_signed_url/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "s3_signed_url"
8
+ spec.version = S3SignedUrl::VERSION
9
+ spec.authors = ["Masato Ikeda"]
10
+ spec.email = ["masato.ikeda@gmail.com"]
11
+
12
+ spec.summary = %q{Generate signed URLs to get S3 objects.}
13
+ spec.description = %q{Generate signed URLs to get S3 objects.}
14
+ spec.homepage = "https://github.com/a2ikm/s3_signed_url"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aws-sdk", "~> 2"
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3_signed_url
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Masato Ikeda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Generate signed URLs to get S3 objects.
56
+ email:
57
+ - masato.ikeda@gmail.com
58
+ executables:
59
+ - s3_signed_url
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - exe/s3_signed_url
71
+ - lib/s3_signed_url.rb
72
+ - lib/s3_signed_url/cli.rb
73
+ - lib/s3_signed_url/version.rb
74
+ - s3_signed_url.gemspec
75
+ homepage: https://github.com/a2ikm/s3_signed_url
76
+ licenses: []
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Generate signed URLs to get S3 objects.
98
+ test_files: []
99
+ has_rdoc: