s3_reproxy_download 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5ff4ce5fd844b67cabb765d0ebb67c6d0720267
4
+ data.tar.gz: c60c134531b3a2552689b2dfb544b2efbc6d1360
5
+ SHA512:
6
+ metadata.gz: e614a8eca49af4cc2fbed2db74007afdf0d08babddc0a55ff82a979f6113ddd2f31db6fc1c5bee98b017f04dadadb7da9a79db9e1a818ec258e3bb456c001188
7
+ data.tar.gz: 8fcf3d646806faa75f9281a61188343103a904b8bf71f5a6e4ecb23ea0fc026d81a88c939c0b35d63e977a70f5bb89c3e1735dab55e2d68c742804d83f7a1d94
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in s3_reproxy_download.gemspec
4
+ gemspec
@@ -0,0 +1,63 @@
1
+ # S3ReproxyDownload
2
+
3
+ Provide helper method that S3 file downloade use X-REPROXY-URL
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 's3_reproxy_download'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install s3_reproxy_download
20
+
21
+ ## Usage
22
+
23
+ First, include `S3ReproxyDownload::Helper` module to your controller.
24
+
25
+ ```ruby
26
+ class YourController
27
+ include S3ReproxyDownload::Helper
28
+ end
29
+ ```
30
+
31
+ Call `send_s3_file` method.
32
+
33
+ ```ruby
34
+ class YourController
35
+ include S3ReproxyDownload
36
+
37
+ def show
38
+ send_s3_file :your_bucket, :file_key
39
+ end
40
+ end
41
+ ```
42
+
43
+ If you want to set custom headers, you should use `headers` option.
44
+
45
+ ```ruby
46
+ class YourController
47
+ include S3ReproxyDownload
48
+
49
+ def show
50
+ send_s3_file :your_bucket, :file_key, headers: {'X-CUSTOM-HEADER' => 'custom'}
51
+ end
52
+ end
53
+ ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/esminc/s3_reproxy_download.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "s3_reproxy_download"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ require 's3_reproxy_download/version'
2
+ require 'action_controller'
3
+ require 'aws-sdk'
4
+
5
+ module S3ReproxyDownload
6
+ def self.reproxy_path=(path)
7
+ @reproxy_path = path
8
+ end
9
+
10
+ def self.reproxy_path
11
+ @reproxy_path || '/reproxy'
12
+ end
13
+
14
+ module Helper
15
+ def send_s3_file(bucket_name, path, headers: {})
16
+ s3_object = S3ReproxyDownload::S3Object.new(bucket_name, path)
17
+
18
+ response.headers['X-Accel-Redirect'] = S3ReproxyDownload.reproxy_path
19
+ response.headers['X-Reproxy-URL'] = s3_object.presigned_url
20
+ response.headers['Content-Disposition'] = "attachment; filename=\"#{s3_object.filename}\""
21
+
22
+ headers.each do |header, value|
23
+ response.headers[header] = value
24
+ end
25
+
26
+ head :ok
27
+ end
28
+ end
29
+
30
+ class S3Object
31
+ def initialize(bucket_name, path)
32
+ @bucket = Aws::S3::Resource.new.bucket(bucket_name)
33
+ @path = path
34
+ end
35
+
36
+ def presigned_url
37
+ @bucket.object(@path).presigned_url(:get, @path)
38
+ end
39
+
40
+ def filename
41
+ File.basename(@path)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module S3ReproxyDownload
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 's3_reproxy_download/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "s3_reproxy_download"
8
+ spec.version = S3ReproxyDownload::VERSION
9
+ spec.authors = ["takkanm", "hide_nba", "hrysd"]
10
+ spec.email = ["takkanm@gmail.com"]
11
+
12
+ spec.summary = %q{provide helper method that S3 file downloade use X-REPROXY-URL}
13
+ spec.description = %q{provide helper method that S3 file downloade use X-REPROXY-URL}
14
+ spec.homepage = "https://github.com/esminc/s3_reproxy_download"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'actionpack'
24
+ spec.add_dependency 'aws-sdk'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: s3_reproxy_download
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - takkanm
8
+ - hide_nba
9
+ - hrysd
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2017-03-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionpack
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: aws-sdk
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: bundler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.13'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.13'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '10.0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '10.0'
71
+ description: provide helper method that S3 file downloade use X-REPROXY-URL
72
+ email:
73
+ - takkanm@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/s3_reproxy_download.rb
85
+ - lib/s3_reproxy_download/version.rb
86
+ - s3_reploxy_download.gemspec
87
+ homepage: https://github.com/esminc/s3_reproxy_download
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: provide helper method that S3 file downloade use X-REPROXY-URL
110
+ test_files: []