s3_proxy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/lib/s3_proxy.rb +5 -0
- data/lib/s3_proxy/app.rb +94 -0
- data/lib/s3_proxy/version.rb +3 -0
- data/s3_proxy.gemspec +27 -0
- data/sample.ru +4 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec212812eb12625e1b6513fab200d497bfd8ea30
|
4
|
+
data.tar.gz: c7542c717e24e2d9cf12bf2e67222cd733c90911
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b26d2daa7e6e5e20ece00f10fab03412aa0b09cf2121644bc6e47dcfa5845411d2fa0c8f6d63745fe5ae11f4bb760d09b7f772e035b50868fa37c195a854f90d
|
7
|
+
data.tar.gz: b9c789c1e55139bd8b6769a7dac5a02a3a168a62bc7104b23564e64953f36036c3189e558abb188b8b88faf0c83c204f91c40ddf932a23cf899fefe53b7e3e1c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Shota Fukumori (sora_h)
|
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,49 @@
|
|
1
|
+
# S3Proxy - simple rack app, proxies to Amazon S3
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
- Simple Rack application that proxies GET requests to Amazon S3
|
6
|
+
- Rack Hijacking support
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 's3_proxy'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install s3_proxy
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### config.ru
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
require 's3_proxy'
|
28
|
+
run S3Proxy::App.new
|
29
|
+
```
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
# you can pass option to Aws::S3.new
|
33
|
+
run S3Proxy::App.new(credentials: Aws::InstanceProfileCredentials.new)
|
34
|
+
```
|
35
|
+
|
36
|
+
### requesting
|
37
|
+
|
38
|
+
```
|
39
|
+
$ curl http://app/foo/bar
|
40
|
+
(returns key `bar` in bucket named `foo`)
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/s3_proxy/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/s3_proxy.rb
ADDED
data/lib/s3_proxy/app.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'aws-sdk-core'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module S3Proxy
|
5
|
+
class App
|
6
|
+
def initialize(options={})
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
return Errors.method_not_allowed unless env['REQUEST_METHOD'] == 'GET'
|
12
|
+
return Errors.not_found if env['PATH_INFO'].empty?
|
13
|
+
|
14
|
+
_, bucket, key = env['PATH_INFO'].split('/', 3)
|
15
|
+
|
16
|
+
head = s3.head_object(bucket: bucket, key: key)
|
17
|
+
return Errors.not_found unless head
|
18
|
+
|
19
|
+
if env['rack.hijack?']
|
20
|
+
hijack env
|
21
|
+
else
|
22
|
+
gentle env
|
23
|
+
end
|
24
|
+
|
25
|
+
rescue Aws::S3::Errors::NoSuchKey
|
26
|
+
return Errors.not_found
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def hijack(env)
|
32
|
+
env['rack.hijack'].call
|
33
|
+
|
34
|
+
io = env['rack.hijack_io']
|
35
|
+
begin
|
36
|
+
io.write "HTTP/1.1 200 OK\r\n"
|
37
|
+
io.write "Status: 200\r\n"
|
38
|
+
io.write "Connection: close\r\n"
|
39
|
+
io.write "Content-Type: #{head.content_type}\r\n"
|
40
|
+
io.write "Content-Length: #{head.content_length}\r\n"
|
41
|
+
io.write "\r\n"
|
42
|
+
io.flush
|
43
|
+
|
44
|
+
s3.get_object({bucket: bucket, key: key}, target: io)
|
45
|
+
ensure
|
46
|
+
io.close
|
47
|
+
end
|
48
|
+
return [200, {}, ['']]
|
49
|
+
end
|
50
|
+
|
51
|
+
def gentle(env)
|
52
|
+
sio = StringIO.new('','w+')
|
53
|
+
|
54
|
+
fiber = Fiber.new do
|
55
|
+
s3.get_object(bucket: bucket, key: key) do |chunk|
|
56
|
+
Fiber.yield(chunk)
|
57
|
+
end
|
58
|
+
Fiber.yield(nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
body = Enumerator.new do |y|
|
62
|
+
while n = fiber.resume
|
63
|
+
y << n
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
[200, {'Content-Type' => head.content_type, 'Content-Length' => head.content_length.to_s}, body]
|
68
|
+
end
|
69
|
+
|
70
|
+
def s3
|
71
|
+
@s3 ||= Aws::S3.new(@options)
|
72
|
+
end
|
73
|
+
|
74
|
+
module Errors
|
75
|
+
class << self
|
76
|
+
def method_not_allowed
|
77
|
+
[405, {'Content-Type' => 'text/plain'}, ["method not allowed"]]
|
78
|
+
end
|
79
|
+
|
80
|
+
def not_found
|
81
|
+
[404, {'Content-Type' => 'text/plain'}, ["not found"]]
|
82
|
+
end
|
83
|
+
|
84
|
+
def forbidden
|
85
|
+
[403, {'Content-Type' => 'text/plain'}, ["forbidden"]]
|
86
|
+
end
|
87
|
+
|
88
|
+
def unknown(code)
|
89
|
+
[code, {'Content-Type' => 'text/plain'}, ["Error: #{code}"]]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/s3_proxy.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 's3_proxy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "s3_proxy"
|
8
|
+
spec.version = S3Proxy::VERSION
|
9
|
+
spec.authors = ["Shota Fukumori (sora_h)"]
|
10
|
+
spec.email = ["her@sorah.jp"]
|
11
|
+
spec.summary = %q{S3 reverse proxy rack app that accepts multiple buckets}
|
12
|
+
spec.description = %q{S3 reverse proxy rack app that accepts multiple buckets.}
|
13
|
+
spec.homepage = "https://github.com/sorah/s3_proxy"
|
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_runtime_dependency "rack", "~> 1.5.2"
|
22
|
+
spec.add_runtime_dependency "aws-sdk-core", "2.0.0.rc8"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "puma"
|
27
|
+
end
|
data/sample.ru
ADDED
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3_proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shota Fukumori (sora_h)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.5.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0.rc8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0.rc8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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: puma
|
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
|
+
description: S3 reverse proxy rack app that accepts multiple buckets.
|
84
|
+
email:
|
85
|
+
- her@sorah.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/s3_proxy.rb
|
96
|
+
- lib/s3_proxy/app.rb
|
97
|
+
- lib/s3_proxy/version.rb
|
98
|
+
- s3_proxy.gemspec
|
99
|
+
- sample.ru
|
100
|
+
homepage: https://github.com/sorah/s3_proxy
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.2.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: S3 reverse proxy rack app that accepts multiple buckets
|
124
|
+
test_files: []
|