shuck 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +36 -0
- data/Rakefile +2 -0
- data/bin/shuck +5 -0
- data/lib/shuck.rb +5 -0
- data/lib/shuck/cli.rb +18 -0
- data/lib/shuck/server.rb +87 -0
- data/lib/shuck/store.rb +76 -0
- data/lib/shuck/version.rb +3 -0
- data/shuck.gemspec +26 -0
- metadata +128 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
shuck (0.0.1)
|
5
|
+
builder
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
archive-tar-minitar (0.5.2)
|
12
|
+
builder (2.1.2)
|
13
|
+
columnize (0.3.2)
|
14
|
+
linecache19 (0.5.11)
|
15
|
+
ruby_core_source (>= 0.1.4)
|
16
|
+
ruby-debug-base19 (0.11.24)
|
17
|
+
columnize (>= 0.3.1)
|
18
|
+
linecache19 (>= 0.5.11)
|
19
|
+
ruby_core_source (>= 0.1.4)
|
20
|
+
ruby-debug19 (0.11.6)
|
21
|
+
columnize (>= 0.3.1)
|
22
|
+
linecache19 (>= 0.5.11)
|
23
|
+
ruby-debug-base19 (>= 0.11.19)
|
24
|
+
ruby_core_source (0.1.4)
|
25
|
+
archive-tar-minitar (>= 0.5.2)
|
26
|
+
thor (0.14.4)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
builder
|
33
|
+
bundler (>= 1.0.0)
|
34
|
+
ruby-debug19
|
35
|
+
shuck!
|
36
|
+
thor
|
data/Rakefile
ADDED
data/bin/shuck
ADDED
data/lib/shuck.rb
ADDED
data/lib/shuck/cli.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'shuck/server'
|
3
|
+
|
4
|
+
module Shuck
|
5
|
+
class CLI < Thor
|
6
|
+
default_task("server")
|
7
|
+
|
8
|
+
desc "server", "Run a server"
|
9
|
+
method_option :root, :type => :string, :aliases => '-r',:required => true
|
10
|
+
method_option :port, :type => :numeric, :aliases => '-p', :required => true
|
11
|
+
def server
|
12
|
+
root = File.expand_path(options[:root])
|
13
|
+
puts "Loading Shuck with #{root} on port #{options[:port]}"
|
14
|
+
server = Shuck::Server.new(options[:port],options[:root])
|
15
|
+
server.serve
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/shuck/server.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'shuck/store'
|
3
|
+
|
4
|
+
module Shuck
|
5
|
+
class Servlet < WEBrick::HTTPServlet::AbstractServlet
|
6
|
+
def initialize(server,root)
|
7
|
+
super(server)
|
8
|
+
@store = Store.new(root)
|
9
|
+
end
|
10
|
+
|
11
|
+
def do_GET(request, response)
|
12
|
+
path = request.path
|
13
|
+
path_len = path.size
|
14
|
+
|
15
|
+
if path == "/"
|
16
|
+
response.status = 200
|
17
|
+
response['Content-Type'] = 'text/xml'
|
18
|
+
response.body = @store.buckets
|
19
|
+
else
|
20
|
+
elems = path[1,path_len].split("/")
|
21
|
+
bucket = elems[0]
|
22
|
+
if elems.size == 1
|
23
|
+
bucket_list = @store.get_bucket(bucket)
|
24
|
+
response.status = 200
|
25
|
+
response.body = bucket_list
|
26
|
+
response['Content-Type'] = "text/xml"
|
27
|
+
else
|
28
|
+
object = elems[1,elems.size].join('/')
|
29
|
+
io = @store.get_object(bucket,object)
|
30
|
+
if io
|
31
|
+
response.status = 200
|
32
|
+
response['Content-Type'] = "application/octet-stream"
|
33
|
+
response.body = io
|
34
|
+
response.chunked = true
|
35
|
+
else
|
36
|
+
response.status = 404
|
37
|
+
response.body = ""
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def do_PUT(request,response)
|
44
|
+
path = request.path
|
45
|
+
path_len = path.size
|
46
|
+
if path == "/"
|
47
|
+
puts "Unsure what to do"
|
48
|
+
else
|
49
|
+
elems = path[1,path_len].split("/")
|
50
|
+
bucket = elems[0]
|
51
|
+
if elems.size == 1
|
52
|
+
@store.create_bucket(bucket)
|
53
|
+
else
|
54
|
+
object = elems[1,elems.size].join('/')
|
55
|
+
@store.store_object(bucket,object,request)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
response.status = 200
|
59
|
+
response.body = ""
|
60
|
+
response['Content-Type'] = "text/xml"
|
61
|
+
end
|
62
|
+
|
63
|
+
def do_POST(request,response)
|
64
|
+
puts "Put"
|
65
|
+
p request
|
66
|
+
end
|
67
|
+
|
68
|
+
def do_DELETE(request,response)
|
69
|
+
puts "Delete"
|
70
|
+
p request
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Server
|
75
|
+
def initialize(port,root)
|
76
|
+
@port = port
|
77
|
+
@root = root
|
78
|
+
end
|
79
|
+
|
80
|
+
def serve
|
81
|
+
@server = WEBrick::HTTPServer.new(:Port => @port)
|
82
|
+
@server.mount "/", Servlet, @root
|
83
|
+
trap "INT" do @server.shutdown end
|
84
|
+
@server.start
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/shuck/store.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Shuck
|
6
|
+
class Store
|
7
|
+
def initialize(root)
|
8
|
+
@root = root
|
9
|
+
@buckets = []
|
10
|
+
Dir[File.join(root,"*")].each do |bucket|
|
11
|
+
@buckets << File.basename(bucket)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def buckets
|
16
|
+
output = ""
|
17
|
+
xml = Builder::XmlMarkup.new(:target => output)
|
18
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
19
|
+
xml.ListAllMyBucketsResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lam|
|
20
|
+
lam.Owner { |owner|
|
21
|
+
owner.ID("123")
|
22
|
+
owner.DisplayName("Curtis Spencer")
|
23
|
+
}
|
24
|
+
lam.Buckets { |buckets|
|
25
|
+
@buckets.each do |bucket|
|
26
|
+
buckets.Bucket do |b|
|
27
|
+
b.Name(bucket)
|
28
|
+
b.CreationDate(Time.now.xmlschema)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
}
|
32
|
+
}
|
33
|
+
output
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_bucket(bucket)
|
37
|
+
output = ""
|
38
|
+
xml = Builder::XmlMarkup.new(:target => output)
|
39
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
40
|
+
xml.ListBucketResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lbr|
|
41
|
+
lbr.Name(bucket)
|
42
|
+
lbr.Prefix
|
43
|
+
lbr.Marker
|
44
|
+
lbr.MaxKeys("1000")
|
45
|
+
lbr.IsTruncated("false")
|
46
|
+
}
|
47
|
+
output
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_bucket(bucket)
|
51
|
+
FileUtils.mkdir_p(File.join(@root,bucket))
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_object(bucket,object)
|
55
|
+
begin
|
56
|
+
io = File.open(File.join(@root,bucket,object),'rb')
|
57
|
+
return io
|
58
|
+
rescue
|
59
|
+
puts $!
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def store_object(bucket,object,request)
|
65
|
+
begin
|
66
|
+
File.open(File.join(@root,bucket,object),'w') do |f|
|
67
|
+
request.body do |chunk|
|
68
|
+
f << chunk
|
69
|
+
end
|
70
|
+
end
|
71
|
+
rescue
|
72
|
+
puts $!
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/shuck.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "shuck/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "shuck"
|
7
|
+
s.version = Shuck::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Curtis Spencer"]
|
10
|
+
s.email = ["curtis@sevenforge.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Shuck is a phony S3 engine with minimal dependencies}
|
13
|
+
s.description = %q{Use Shuck to test basic S3 functionality without actually connecting to S3}
|
14
|
+
|
15
|
+
s.rubyforge_project = "shuck"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "ruby-debug19"
|
19
|
+
s.add_dependency "thor"
|
20
|
+
s.add_dependency "builder"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shuck
|
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
|
+
- Curtis Spencer
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-19 00:00:00 -08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruby-debug19
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: thor
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: builder
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :runtime
|
73
|
+
version_requirements: *id004
|
74
|
+
description: Use Shuck to test basic S3 functionality without actually connecting to S3
|
75
|
+
email:
|
76
|
+
- curtis@sevenforge.com
|
77
|
+
executables:
|
78
|
+
- shuck
|
79
|
+
extensions: []
|
80
|
+
|
81
|
+
extra_rdoc_files: []
|
82
|
+
|
83
|
+
files:
|
84
|
+
- .gitignore
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- Rakefile
|
88
|
+
- bin/shuck
|
89
|
+
- lib/shuck.rb
|
90
|
+
- lib/shuck/cli.rb
|
91
|
+
- lib/shuck/server.rb
|
92
|
+
- lib/shuck/store.rb
|
93
|
+
- lib/shuck/version.rb
|
94
|
+
- shuck.gemspec
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: ""
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project: shuck
|
123
|
+
rubygems_version: 1.3.7
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Shuck is a phony S3 engine with minimal dependencies
|
127
|
+
test_files: []
|
128
|
+
|