Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merges upstream #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ test_root

# Don't check in RVM/rbenv files
.ruby-version

# RubyMine
.idea

# Don't check in the Gemfile.lock
Gemfile.lock
65 changes: 46 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
fakes3 (0.2.1)
fakes3 (0.2.4)
builder
thor

Expand All @@ -12,38 +12,65 @@ GEM
builder
mime-types
xml-simple
aws-sdk-v1 (1.59.0)
aws-sdk (2.5.10)
aws-sdk-resources (= 2.5.10)
aws-sdk-core (2.5.10)
jmespath (~> 1.0)
aws-sdk-resources (2.5.10)
aws-sdk-core (= 2.5.10)
aws-sdk-v1 (1.66.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
builder (3.2.2)
byebug (4.0.1)
columnize (= 0.9.0)
rb-readline (= 0.5.2)
columnize (0.9.0)
json (1.8.1)
mime-types (1.25)
mini_portile (0.6.1)
nokogiri (1.6.4.1)
mini_portile (~> 0.6.0)
rake (10.1.0)
rb-readline (0.5.2)
rest-client (1.6.7)
mime-types (>= 1.16)
domain_name (0.5.20160826)
unf (>= 0.0.5, < 1.0.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
jmespath (1.3.1)
json (1.8.3)
metaclass (0.0.4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
mocha (1.1.0)
metaclass (~> 0.0.1)
netrc (0.11.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
power_assert (0.3.1)
rake (11.2.2)
rest-client (2.0.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
right_aws (3.1.0)
right_http_connection (>= 1.2.5)
right_http_connection (1.4.0)
thor (0.18.1)
xml-simple (1.1.2)
right_http_connection (1.5.0)
test-unit (3.2.1)
power_assert
thor (0.19.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
xml-simple (1.1.5)

PLATFORMS
ruby

DEPENDENCIES
aws-s3
aws-sdk (~> 2)
aws-sdk-v1
bundler (>= 1.0.0)
byebug
fakes3!
mocha
rake
rest-client
right_aws
test-unit

BUNDLED WITH
1.10.2
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ It is a still a TODO to get this to be just one command
## More Information

Check out the [wiki](https://github.com/jubos/fake-s3/wiki)

[![Join the chat at https://gitter.im/jubos/fake-s3](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jubos/fake-s3?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
3 changes: 3 additions & 0 deletions fakes3.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ Gem::Specification.new do |s|
s.add_development_dependency "right_aws"
s.add_development_dependency "rest-client"
s.add_development_dependency "rake"
s.add_development_dependency "aws-sdk", "~> 2"
s.add_development_dependency "aws-sdk-v1"
s.add_development_dependency "test-unit"
s.add_development_dependency "mocha"
#s.add_development_dependency "ruby-debug"
#s.add_development_dependency "debugger"
s.add_dependency "thor"
Expand Down
5 changes: 3 additions & 2 deletions lib/fakes3/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CLI < Thor
method_option :port, :type => :numeric, :aliases => '-p', :required => true
method_option :address, :type => :string, :aliases => '-a', :required => false, :desc => "Bind to this address. Defaults to 0.0.0.0"
method_option :hostname, :type => :string, :aliases => '-H', :desc => "The root name of the host. Defaults to s3.amazonaws.com."
method_option :quiet, :type => :boolean, :aliases => '-q', :desc => "Quiet; do not write anything to standard output."
method_option :limit, :aliases => '-l', :type => :string, :desc => 'Rate limit for serving (ie. 50K, 1.0M)'
method_option :sslcert, :type => :string, :desc => 'Path to SSL certificate'
method_option :sslkey, :type => :string, :desc => 'Path to SSL certificate key'
Expand Down Expand Up @@ -52,8 +53,8 @@ def server
abort "If you specify an SSL certificate you must also specify an SSL certificate key"
end

puts "Loading FakeS3 with #{root} on port #{options[:port]} with hostname #{hostname}"
server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path)
puts "Loading FakeS3 with #{root} on port #{options[:port]} with hostname #{hostname}" unless options[:quiet]
server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path, quiet: !!options[:quiet])
server.serve
end

Expand Down
41 changes: 31 additions & 10 deletions lib/fakes3/file_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,43 @@ def do_store_object(bucket, object_name, filedata, request)
end
end

def combine_object_parts(bucket, upload_id, object_name, parts, request)
upload_path = File.join(@root, bucket.name)
base_path = File.join(upload_path, "#{upload_id}_#{object_name}")
def list_object_parts(bucket_name, object_name, upload_id)
pattern = File.join(@root, bucket_name, "#{upload_id}_#{object_name}*")
Dir.glob(pattern).map do |path|
file = File.open(File.join(path, SHUCK_METADATA_DIR, 'content'), 'rb')
part = file.read
file.close
{
part_num: path.match(/_part(\d+)$/)[1],
etag: Digest::MD5.hexdigest(part),
size: part.size,
last_mod: File.mtime(path).utc.iso8601(SUBSECOND_PRECISION)
}
end
end

def combine_object_parts(bucket_name, object_name, upload_id, parts, request)
upload_path = File.join(@root, bucket_name)
base_path = File.join(upload_path, "#{upload_id}_#{object_name}")

complete_file = ""
chunk = ""
part_paths = []

part_paths = []
parts.sort_by { |part| part[:number] }.each do |part|
part_path = "#{base_path}_part#{part[:number]}"
content_path = File.join(part_path, SHUCK_METADATA_DIR, 'content')

File.open(content_path, 'rb') { |f| chunk = f.read }
file = File.open(content_path, 'rb')
chunk = file.read
etag = Digest::MD5.hexdigest(chunk)

raise new Error "invalid file chunk" unless part[:etag] == etag
fail StandardError, "invalid part #{part[:etag]}" unless part[:etag] == etag
complete_file << chunk
part_paths << part_path
part_paths << part_path
file.close
end

bucket = get_bucket(bucket_name)
object = do_store_object(bucket, object_name, complete_file, request)

# clean up parts
Expand Down Expand Up @@ -263,14 +280,18 @@ def create_metadata(content,request)
metadata[:content_type] = request.header["content-type"].first
metadata[:size] = File.size(content)
metadata[:modified_date] = File.mtime(content).utc.iso8601(SUBSECOND_PRECISION)
metadata[:amazon_metadata] = {}
metadata[:custom_metadata] = {}

# Add custom metadata from the request header
request.header.each do |key, value|
match = /^x-amz-meta-(.*)$/.match(key)
if match && (match_key = match[1])
match = /^x-amz-([^-]+)-(.*)$/.match(key)
next unless match
if match[1].eql?('meta') && (match_key = match[2])
metadata[:custom_metadata][match_key] = value.join(', ')
next
end
metadata[:amazon_metadata][key.gsub(/^x-amz-/, '')] = value.join(', ')
end
return metadata
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fakes3/s3_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def hash
end

def eql?(object)
@name == object.name
object.is_a?(self.class) ? (@name == object.name) : false
end

# Sort by the object's name
def <=>(object)
@name <=> object.name
object.is_a?(self.class) ? (@name <=> object.name) : nil
end
end
end
Loading