fakes3test12 1.2.0

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: df81ac57f6a43e4bf95a98f987f121cf011fe36f
4
+ data.tar.gz: c624cd804c4644225f9d5ebf33821eb6666a3d10
5
+ SHA512:
6
+ metadata.gz: 1ba43ba05c131b58623775c87b188715f4856854c0908df6b3d92d670102905f8f93a00f4432eb63673e421d750f6bbf37aa3846b9bb623dc962cb494f209dd5
7
+ data.tar.gz: d437d490c80bd8747e0b2b41ed7bbe9d528986a38389894bcee0fb73c390740605b097156341c031a7a2e051423203ca0c495d86ef9579b0214271c8fff014f5
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ tmp
5
+ test_root
6
+
7
+ # Don't check in RVM/rbenv files
8
+ .ruby-version
9
+
10
+ # RubyMine
11
+ .idea
12
+
13
+ # Don't check in the Gemfile.lock
14
+ Gemfile.lock
15
+
16
+ .DS_Store
17
+ .rvmrc
18
+ root/*
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,50 @@
1
+ ## Contributing to Fake S3
2
+
3
+ Contributions in the form of pull requests, bug reports, documentation, or anything else are welcome! We do have a few small rules to follow:
4
+
5
+ - Ensure tests pass before making a pull request. (You can read the Testing section below for how to set up your development environment and run tests)
6
+
7
+ - Please use a coding style similar to the rest of the file(s) you change. This isn't a hard rule but if it's too different, it will stand out.
8
+
9
+ - Unless your contributions fall under the trivial exemption policy (below), contributors must sign our Contributor License Agreement (CLA) to be eligible to contribute. Read more in section is below.
10
+
11
+
12
+ ## Testing
13
+
14
+ There are some prerequisites to actually being able to run the unit/integration tests.
15
+
16
+ On macOS, edit your /etc/hosts and add the following line:
17
+
18
+ 127.0.0.1 posttest.localhost
19
+
20
+ Then ensure that the following packages are installed (boto, s3cmd):
21
+
22
+ > pip install boto
23
+ > brew install s3cmd
24
+
25
+
26
+ Start the test server using:
27
+
28
+ rake test_server
29
+
30
+ Finally, in another terminal window run:
31
+
32
+ rake test
33
+
34
+
35
+ ## Signing the Contributor License agreement
36
+
37
+ We have a contributor license agreement (CLA) based off of Google and Apache's CLA. If you would feel comfortable contributing to, say, Angular.js, you should feel comfortable with this CLA.
38
+
39
+ To sign the CLA:
40
+
41
+ [Click here and fill out the form.](https://docs.google.com/forms/d/e/1FAIpQLSeKKSKNNz5ji1fd5bbu5RaGFbhD45zEaCnAjzBZPpzOaXQsvQ/viewform)
42
+
43
+ If you're interested, [this blog post](https://julien.ponge.org/blog/in-defense-of-contributor-license-agreements/) discusses why to use a CLA, and even goes over the text of the CLA we based ours on.
44
+
45
+
46
+ ## Trivial Exemption Policy
47
+
48
+ The Trivial Exemption Policy exempts contributions that would not be sufficiently robust or creative to enjoy copyright protection, and therefore do not need to sign the CLA. This would generally be changes that don't involve much creativity.
49
+
50
+ Contributions considered trivial are generally fewer than 10 lines of actual code. (It may be longer than 10 lines, for example these would often be larger: blank lines, changes in indentation, formatting, simple comments, logging messages, changes to metadata like Gemfiles or gitignore, reordering, breaking or combining files, renaming files, or other unoriginal changes)
data/DEPLOY_README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Helpful things to remember when deploying to RubyGems
2
+
3
+ Ensure the version number is updated (lib/fakes3/version.rb)
4
+
5
+ Ensure the tests pass
6
+ ```
7
+ rake test_server followed by rake test
8
+ ```
9
+
10
+ Build the Gem
11
+ ```
12
+ gem build fakes3.gemspec
13
+ ```
14
+
15
+ Push to RubyGems
16
+ ```
17
+ gem push fakes3-VERSION.gem
18
+ ```
data/Dockerfile ADDED
@@ -0,0 +1,13 @@
1
+ FROM alpine:3.4
2
+
3
+ RUN apk add --no-cache --update ruby ruby-dev ruby-bundler python py-pip git build-base libxml2-dev libxslt-dev
4
+ RUN pip install boto s3cmd
5
+
6
+ COPY fakes3.gemspec Gemfile Gemfile.lock /app/
7
+ COPY lib/fakes3/version.rb /app/lib/fakes3/
8
+
9
+ WORKDIR /app
10
+
11
+ RUN bundle install
12
+
13
+ COPY . /app/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'fakes3', :path => '.' # for dev and test, use local fakes3
3
+ # Specify your gem's dependencies in fakes3as.gemspec
4
+ gemspec
data/ISSUE_TEMPLATE.md ADDED
@@ -0,0 +1,9 @@
1
+ Thanks for the issue! We do have a few small rules to follow:
2
+
3
+ 1. Please add [Feature], [Bug], [Question], or [Other] to your title.
4
+
5
+ 2. If it is a bug, please add steps to reproduce it. More information is almost always helpful.
6
+
7
+ 3. If it is a feature, is there any pull request you should refer to? If so, please add a link to the pull request somewhere in the comments.
8
+
9
+ Thanks!
data/Makefile ADDED
@@ -0,0 +1,7 @@
1
+ .PHONY: test
2
+
3
+ build-test-container:
4
+ docker build -t fake-s3 .
5
+
6
+ test: build-test-container
7
+ docker run --rm --add-host="posttest.localhost:127.0.0.1" -e "RUBYOPT=-W0" fake-s3 sh -c "rake test_server & rake test"
@@ -0,0 +1,9 @@
1
+ Thanks for the pull request! We do have a few small rules to follow:
2
+
3
+ 1. Ensure tests pass before creating the pull request.
4
+
5
+ 2. Please use a coding style similar to the rest of the file(s) you change. This isn't a hard rule but if it's too different, it will stick out.
6
+
7
+ 3. We have a contributor license agreement (CLA) based off of Google and Apache's CLA. If you would feel comfortable contributing to, say, Angular.js, you should feel comfortable with this CLA. Unless you've previously signed, please sign at: https://docs.google.com/forms/d/e/1FAIpQLSeKKSKNNz5ji1fd5bbu5RaGFbhD45zEaCnAjzBZPpzOaXQsvQ/viewform
8
+
9
+ To read more about all three of the above, visit: https://github.com/jubos/fake-s3/blob/master/CONTRIBUTING.md
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ ![Fake S3](static/logo.png "Fake S3")
2
+
3
+ ## Introduction
4
+
5
+ Fake S3 is a lightweight server that responds to the same API of Amazon S3.
6
+
7
+ It is extremely useful for testing of S3 in a sandbox environment without actually making calls to Amazon, which not only requires a network connection, but also costs money with every use.
8
+
9
+ The goal of Fake S3 is to minimize runtime dependencies and be more of a
10
+ development tool to test S3 calls in your code rather than a production server looking to duplicate S3 functionality.
11
+
12
+ Many commands are supported, including put, get, list, copy, and make bucket.
13
+
14
+ ## Installation
15
+
16
+ gem install fakes3
17
+
18
+ ## Running
19
+
20
+ To run the server, you just specify a root and a port.
21
+
22
+ fakes3 -r /mnt/fakes3_root -p 4567
23
+
24
+ ## Licensing
25
+
26
+ As of the latest version, we are licensing with Super Source. To get a license, visit:
27
+
28
+ https://supso.org/projects/fake-s3
29
+
30
+ Depending on your company's size, the license may be free. It is also free for individuals.
31
+
32
+ ## Connecting to Fake S3
33
+
34
+ Take a look at the test cases to see client example usage. For now, Fake S3 is
35
+ mainly tested with s3cmd, aws-s3 gem, and right_aws. There are plenty more
36
+ libraries out there, and please do mention if other clients work or not.
37
+
38
+ Here is a running list of [supported clients](https://github.com/jubos/fake-s3/wiki/Supported-Clients "Supported Clients")
39
+
40
+ ## Contributing
41
+
42
+ Contributions in the form of pull requests, bug reports, documentation, or anything else are welcome! Please read the CONTRIBUTING.md file for more info: [CONTRIBUTING.md](https://github.com/jubos/fake-s3/blob/master/CONTRIBUTING.md)
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'rake/testtask'
4
+ include Rake::DSL
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "."
9
+ t.test_files =
10
+ FileList['test/*_test.rb'].exclude('test/s3_commands_test.rb')
11
+ end
12
+
13
+ desc "Run the test_server"
14
+ task :test_server do |t|
15
+ system("bundle exec bin/fakes3 --port 10453 --root test_root")
16
+ end
17
+
18
+ task :default => :test
data/bin/fakes3 ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << './lib'
4
+
5
+ require 'fakes3/cli'
6
+ FakeS3::CLI.start
data/fakes3.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'lib', 'fakes3', 'version')
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fakes3test12"
6
+ s.version = FakeS3::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Curtis Spencer"]
9
+ s.email = ["fakes3@supso.org"]
10
+ s.homepage = "https://github.com/jubos/fake-s3"
11
+ s.summary = %q{Fake S3 is a server that simulates Amazon S3 commands so you can test your S3 functionality in your projects}
12
+ s.description = %q{Use Fake S3 to test basic Amazon S3 functionality without actually connecting to AWS}
13
+ s.license = "Supported-Source"
14
+ s.post_install_message = "Fake S3: if you don't already have a license for Fake S3, you can get one at https://supso.org/projects/fake-s3"
15
+
16
+ s.add_development_dependency "bundler", ">= 1.0.0"
17
+ s.add_development_dependency "aws-s3"
18
+ s.add_development_dependency "right_aws"
19
+ s.add_development_dependency "rest-client"
20
+ s.add_development_dependency "rake"
21
+ s.add_development_dependency "aws-sdk", "~> 2"
22
+ s.add_development_dependency "aws-sdk-v1"
23
+ s.add_development_dependency "test-unit"
24
+ s.add_development_dependency "mocha"
25
+ #s.add_development_dependency "ruby-debug"
26
+ #s.add_development_dependency "debugger"
27
+ s.add_dependency "thor"
28
+ s.add_dependency "builder"
29
+ s.add_dependency "xml-simple"
30
+
31
+ s.files = `git ls-files`.split("\n")
32
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
33
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
34
+ s.require_paths = ["lib"]
35
+ end
data/lib/fakes3.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'fakes3/version'
2
+ require 'fakes3/file_store'
3
+ require 'fakes3/server'
@@ -0,0 +1,65 @@
1
+ require 'builder'
2
+ require 'thread'
3
+ require 'fakes3/s3_object'
4
+ require 'fakes3/sorted_object_list'
5
+
6
+ module FakeS3
7
+ class Bucket
8
+ attr_accessor :name,:creation_date,:objects
9
+
10
+ def initialize(name,creation_date,objects)
11
+ @name = name
12
+ @creation_date = creation_date
13
+ @objects = SortedObjectList.new
14
+ objects.each do |obj|
15
+ @objects.add(obj)
16
+ end
17
+ @mutex = Mutex.new
18
+ end
19
+
20
+ def find(object_name)
21
+ @mutex.synchronize do
22
+ @objects.find(object_name)
23
+ end
24
+ end
25
+
26
+ def add(object)
27
+ # Unfortunately have to synchronize here since the our SortedObjectList
28
+ # not thread safe. Probably can get finer granularity if performance is
29
+ # important
30
+ @mutex.synchronize do
31
+ @objects.add(object)
32
+ end
33
+ end
34
+
35
+ def remove(object)
36
+ @mutex.synchronize do
37
+ @objects.remove(object)
38
+ end
39
+ end
40
+
41
+ def query_for_range(options)
42
+ marker = options[:marker]
43
+ prefix = options[:prefix]
44
+ max_keys = options[:max_keys] || 1000
45
+ delimiter = options[:delimiter]
46
+
47
+ match_set = nil
48
+ @mutex.synchronize do
49
+ match_set = @objects.list(options)
50
+ end
51
+
52
+ bq = BucketQuery.new
53
+ bq.bucket = self
54
+ bq.marker = marker
55
+ bq.prefix = prefix
56
+ bq.max_keys = max_keys
57
+ bq.delimiter = delimiter
58
+ bq.matches = match_set.matches
59
+ bq.is_truncated = match_set.is_truncated
60
+ bq.common_prefixes = match_set.common_prefixes
61
+ return bq
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,11 @@
1
+ module FakeS3
2
+ class BucketQuery
3
+ attr_accessor :prefix,:matches,:marker,:max_keys,
4
+ :delimiter,:bucket,:is_truncated,:common_prefixes
5
+
6
+ # Syntactic sugar
7
+ def is_truncated?
8
+ @is_truncated
9
+ end
10
+ end
11
+ end
data/lib/fakes3/cli.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'thor'
2
+ require 'fakes3/server'
3
+ require 'fakes3/version'
4
+
5
+ module FakeS3
6
+ class CLI < Thor
7
+ default_task("server")
8
+
9
+ desc "server", "Run a server on a particular hostname"
10
+ method_option :root, :type => :string, :aliases => '-r', :required => true
11
+ method_option :port, :type => :numeric, :aliases => '-p', :required => true
12
+ method_option :address, :type => :string, :aliases => '-a', :required => false, :desc => "Bind to this address. Defaults to all IP addresses of the machine."
13
+ method_option :hostname, :type => :string, :aliases => '-H', :desc => "The root name of the host. Defaults to s3.amazonaws.com."
14
+ method_option :quiet, :type => :boolean, :aliases => '-q', :desc => "Quiet; do not write anything to standard output."
15
+ method_option :limit, :aliases => '-l', :type => :string, :desc => 'Rate limit for serving (ie. 50K, 1.0M)'
16
+ method_option :sslcert, :type => :string, :desc => 'Path to SSL certificate'
17
+ method_option :sslkey, :type => :string, :desc => 'Path to SSL certificate key'
18
+
19
+ def server
20
+ store = nil
21
+ if options[:root]
22
+ root = File.expand_path(options[:root])
23
+ # TODO Do some sanity checking here
24
+ store = FileStore.new(root, !!options[:quiet])
25
+ end
26
+
27
+ if store.nil?
28
+ abort "You must specify a root to use a file store (the current default)"
29
+ end
30
+
31
+ hostname = 's3.amazonaws.com'
32
+ if options[:hostname]
33
+ hostname = options[:hostname]
34
+ # In case the user has put a port on the hostname
35
+ if hostname =~ /:(\d+)/
36
+ hostname = hostname.split(":")[0]
37
+ end
38
+ end
39
+
40
+ if options[:limit]
41
+ begin
42
+ store.rate_limit = options[:limit]
43
+ rescue
44
+ abort $!.message
45
+ end
46
+ end
47
+
48
+ address = options[:address]
49
+ ssl_cert_path = options[:sslcert]
50
+ ssl_key_path = options[:sslkey]
51
+
52
+ if (ssl_cert_path.nil? && !ssl_key_path.nil?) || (!ssl_cert_path.nil? && ssl_key_path.nil?)
53
+ abort "If you specify an SSL certificate you must also specify an SSL certificate key"
54
+ end
55
+
56
+ puts "Loading FakeS3 with #{root} on port #{options[:port]} with hostname #{hostname}" unless options[:quiet]
57
+ server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path, quiet: !!options[:quiet])
58
+ server.serve
59
+ end
60
+
61
+ desc "version", "Report the current fakes3 version"
62
+ def version
63
+ puts <<"EOF"
64
+ ======================
65
+ FakeS3 #{FakeS3::VERSION}
66
+
67
+ Copyright 2012, Curtis Spencer (@jubos)
68
+ EOF
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,46 @@
1
+ module FakeS3
2
+ class FakeS3Exception < RuntimeError
3
+ attr_accessor :resource,:request_id
4
+
5
+ def self.metaclass; class << self; self; end; end
6
+
7
+ def self.traits(*arr)
8
+ return @traits if arr.empty?
9
+ attr_accessor *arr
10
+
11
+ arr.each do |a|
12
+ metaclass.instance_eval do
13
+ define_method( a ) do |val|
14
+ @traits ||= {}
15
+ @traits[a] = val
16
+ end
17
+ end
18
+ end
19
+
20
+ class_eval do
21
+ define_method( :initialize ) do
22
+ self.class.traits.each do |k,v|
23
+ instance_variable_set("@#{k}", v)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ traits :message,:http_status
30
+
31
+ def code
32
+ self.class.to_s
33
+ end
34
+ end
35
+
36
+ class NoSuchBucket < FakeS3Exception
37
+ message "The bucket you tried to delete is not empty."
38
+ http_status "404"
39
+ end
40
+
41
+ class BucketNotEmpty < FakeS3Exception
42
+ message "The bucket you tried to delete is not empty."
43
+ http_status "409"
44
+ end
45
+
46
+ end