sauberia-aws-s3 0.6.2.1254423624

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/CHANGELOG +107 -0
  2. data/COPYING +19 -0
  3. data/INSTALL +55 -0
  4. data/README.erb +58 -0
  5. data/Rakefile +334 -0
  6. data/TODO +26 -0
  7. data/aws-s3.gemspec +42 -0
  8. data/bin/s3sh +6 -0
  9. data/bin/setup.rb +10 -0
  10. data/lib/aws/s3.rb +60 -0
  11. data/lib/aws/s3/acl.rb +636 -0
  12. data/lib/aws/s3/authentication.rb +222 -0
  13. data/lib/aws/s3/base.rb +270 -0
  14. data/lib/aws/s3/bittorrent.rb +58 -0
  15. data/lib/aws/s3/bucket.rb +372 -0
  16. data/lib/aws/s3/connection.rb +288 -0
  17. data/lib/aws/s3/error.rb +69 -0
  18. data/lib/aws/s3/exceptions.rb +133 -0
  19. data/lib/aws/s3/extensions.rb +342 -0
  20. data/lib/aws/s3/logging.rb +317 -0
  21. data/lib/aws/s3/object.rb +626 -0
  22. data/lib/aws/s3/owner.rb +46 -0
  23. data/lib/aws/s3/parsing.rb +99 -0
  24. data/lib/aws/s3/response.rb +180 -0
  25. data/lib/aws/s3/service.rb +51 -0
  26. data/lib/aws/s3/version.rb +12 -0
  27. data/site/index.erb +41 -0
  28. data/site/public/images/box-and-gem.gif +0 -0
  29. data/site/public/images/favicon.ico +0 -0
  30. data/site/public/ruby.css +18 -0
  31. data/site/public/screen.css +99 -0
  32. data/support/faster-xml-simple/COPYING +18 -0
  33. data/support/faster-xml-simple/README +8 -0
  34. data/support/faster-xml-simple/Rakefile +54 -0
  35. data/support/faster-xml-simple/lib/faster_xml_simple.rb +190 -0
  36. data/support/faster-xml-simple/test/fixtures/test-1.rails.yml +4 -0
  37. data/support/faster-xml-simple/test/fixtures/test-1.xml +3 -0
  38. data/support/faster-xml-simple/test/fixtures/test-1.yml +4 -0
  39. data/support/faster-xml-simple/test/fixtures/test-2.rails.yml +6 -0
  40. data/support/faster-xml-simple/test/fixtures/test-2.xml +3 -0
  41. data/support/faster-xml-simple/test/fixtures/test-2.yml +6 -0
  42. data/support/faster-xml-simple/test/fixtures/test-3.rails.yml +6 -0
  43. data/support/faster-xml-simple/test/fixtures/test-3.xml +5 -0
  44. data/support/faster-xml-simple/test/fixtures/test-3.yml +6 -0
  45. data/support/faster-xml-simple/test/fixtures/test-4.rails.yml +5 -0
  46. data/support/faster-xml-simple/test/fixtures/test-4.xml +7 -0
  47. data/support/faster-xml-simple/test/fixtures/test-4.yml +5 -0
  48. data/support/faster-xml-simple/test/fixtures/test-5.rails.yml +8 -0
  49. data/support/faster-xml-simple/test/fixtures/test-5.xml +7 -0
  50. data/support/faster-xml-simple/test/fixtures/test-5.yml +8 -0
  51. data/support/faster-xml-simple/test/fixtures/test-6.rails.yml +43 -0
  52. data/support/faster-xml-simple/test/fixtures/test-6.xml +29 -0
  53. data/support/faster-xml-simple/test/fixtures/test-6.yml +41 -0
  54. data/support/faster-xml-simple/test/fixtures/test-7.rails.yml +23 -0
  55. data/support/faster-xml-simple/test/fixtures/test-7.xml +22 -0
  56. data/support/faster-xml-simple/test/fixtures/test-7.yml +22 -0
  57. data/support/faster-xml-simple/test/fixtures/test-8.rails.yml +14 -0
  58. data/support/faster-xml-simple/test/fixtures/test-8.xml +8 -0
  59. data/support/faster-xml-simple/test/fixtures/test-8.yml +11 -0
  60. data/support/faster-xml-simple/test/regression_test.rb +47 -0
  61. data/support/faster-xml-simple/test/test_helper.rb +17 -0
  62. data/support/faster-xml-simple/test/xml_simple_comparison_test.rb +46 -0
  63. data/support/rdoc/code_info.rb +211 -0
  64. data/test/acl_test.rb +254 -0
  65. data/test/authentication_test.rb +118 -0
  66. data/test/base_test.rb +136 -0
  67. data/test/bucket_test.rb +74 -0
  68. data/test/connection_test.rb +216 -0
  69. data/test/error_test.rb +70 -0
  70. data/test/extensions_test.rb +340 -0
  71. data/test/fixtures.rb +89 -0
  72. data/test/fixtures/buckets.yml +133 -0
  73. data/test/fixtures/errors.yml +34 -0
  74. data/test/fixtures/headers.yml +3 -0
  75. data/test/fixtures/logging.yml +15 -0
  76. data/test/fixtures/loglines.yml +5 -0
  77. data/test/fixtures/logs.yml +7 -0
  78. data/test/fixtures/policies.yml +16 -0
  79. data/test/logging_test.rb +89 -0
  80. data/test/mocks/fake_response.rb +26 -0
  81. data/test/object_test.rb +205 -0
  82. data/test/parsing_test.rb +66 -0
  83. data/test/remote/acl_test.rb +116 -0
  84. data/test/remote/bittorrent_test.rb +45 -0
  85. data/test/remote/bucket_test.rb +146 -0
  86. data/test/remote/logging_test.rb +82 -0
  87. data/test/remote/object_test.rb +379 -0
  88. data/test/remote/test_file.data +0 -0
  89. data/test/remote/test_helper.rb +33 -0
  90. data/test/response_test.rb +68 -0
  91. data/test/service_test.rb +23 -0
  92. data/test/test_helper.rb +118 -0
  93. metadata +221 -0
@@ -0,0 +1,46 @@
1
+ module AWS
2
+ module S3
3
+ # Entities in S3 have an associated owner (the person who created them). The owner is a canonical representation of an
4
+ # entity in the S3 system. It has an <tt>id</tt> and a <tt>display_name</tt>.
5
+ #
6
+ # These attributes can be used when specifying a ACL::Grantee for an ACL::Grant.
7
+ #
8
+ # You can retrieve the owner of the current account by calling Owner.current.
9
+ class Owner
10
+ undef_method :id if method_defined?(:id) # Get rid of Object#id
11
+ include SelectiveAttributeProxy
12
+
13
+ class << self
14
+ # The owner of the current account.
15
+ def current
16
+ response = Service.get('/')
17
+ # new(response.parsed['owner']) if response.parsed['owner']
18
+ #TODO: This is a pretty hackish way to get the current account owner.
19
+ response.parsed['contents'][0]['owner'] if (response.parsed['contents'] && response.parsed['contents'][0])
20
+ end
21
+ memoized :current
22
+ end
23
+
24
+ def initialize(attributes = {}) #:nodoc:
25
+ @attributes = attributes
26
+ end
27
+
28
+ def ==(other_owner) #:nodoc:
29
+ hash == other_owner.hash
30
+ end
31
+
32
+ def hash #:nodoc
33
+ [id, display_name].join.hash
34
+ end
35
+
36
+ private
37
+ def proxiable_attribute?(name)
38
+ valid_attributes.include?(name)
39
+ end
40
+
41
+ def valid_attributes
42
+ %w(id display_name)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,99 @@
1
+ #:stopdoc:
2
+ module AWS
3
+ module S3
4
+ module Parsing
5
+ class << self
6
+ def parser=(parsing_library)
7
+ XmlParser.parsing_library = parsing_library
8
+ end
9
+
10
+ def parser
11
+ XmlParser.parsing_library
12
+ end
13
+ end
14
+
15
+ module Typecasting
16
+ def typecast(object)
17
+ case object
18
+ when Hash
19
+ typecast_hash(object)
20
+ when Array
21
+ object.map {|element| typecast(element)}
22
+ when String
23
+ CoercibleString.coerce(object)
24
+ else
25
+ object
26
+ end
27
+ end
28
+
29
+ def typecast_hash(hash)
30
+ if content = hash['__content__']
31
+ typecast(content)
32
+ else
33
+ keys = hash.keys.map {|key| key.underscore}
34
+ values = hash.values.map {|value| typecast(value)}
35
+ keys.inject({}) do |new_hash, key|
36
+ new_hash[key] = values.slice!(0)
37
+ new_hash
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ class XmlParser < Hash
44
+ include Typecasting
45
+
46
+ class << self
47
+ attr_accessor :parsing_library
48
+ end
49
+
50
+ attr_reader :body, :xml_in, :root
51
+
52
+ def initialize(body)
53
+ @body = body
54
+ unless body.strip.empty?
55
+ parse
56
+ set_root
57
+ typecast_xml_in
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def parse
64
+ @xml_in = self.class.parsing_library.xml_in(body, parsing_options)
65
+ end
66
+
67
+ def parsing_options
68
+ {
69
+ # Includes the enclosing tag as the top level key
70
+ 'keeproot' => true,
71
+ # Makes tag value available via the '__content__' key
72
+ 'contentkey' => '__content__',
73
+ # Always parse tags into a hash, even when there are no attributes
74
+ # (unless there is also no value, in which case it is nil)
75
+ 'forcecontent' => true,
76
+ # If a tag is empty, makes its content nil
77
+ 'suppressempty' => nil,
78
+ # Force nested elements to be put into an array, even if there is only one of them
79
+ 'forcearray' => ['Contents', 'Bucket', 'Grant', 'CommonPrefixes']
80
+ }
81
+ end
82
+
83
+ def set_root
84
+ @root = @xml_in.keys.first.underscore
85
+ end
86
+
87
+ def typecast_xml_in
88
+ typecast_xml = {}
89
+ @xml_in.dup.each do |key, value| # Some typecasting is destructive so we dup
90
+ typecast_xml[key.underscore] = typecast(value)
91
+ end
92
+ # An empty body will try to update with a string so only update if the result is a hash
93
+ update(typecast_xml[root]) if typecast_xml[root].is_a?(Hash)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ #:startdoc:
@@ -0,0 +1,180 @@
1
+ #:stopdoc:
2
+ module AWS
3
+ module S3
4
+ class Base
5
+ class Response < String
6
+ attr_reader :response, :body, :parsed
7
+ def initialize(response)
8
+ @response = response
9
+ @body = response.body.to_s
10
+ super(body)
11
+ end
12
+
13
+ def headers
14
+ headers = {}
15
+ response.each do |header, value|
16
+ headers[header] = value
17
+ end
18
+ headers
19
+ end
20
+ memoized :headers
21
+
22
+ def [](header)
23
+ headers[header]
24
+ end
25
+
26
+ def each(&block)
27
+ headers.each(&block)
28
+ end
29
+
30
+ def code
31
+ response.code.to_i
32
+ end
33
+
34
+ {:success => 200..299, :redirect => 300..399,
35
+ :client_error => 400..499, :server_error => 500..599}.each do |result, code_range|
36
+ class_eval(<<-EVAL, __FILE__, __LINE__)
37
+ def #{result}?
38
+ return false unless response
39
+ (#{code_range}).include? code
40
+ end
41
+ EVAL
42
+ end
43
+
44
+ def error?
45
+ !success? && response['content-type'] == 'application/xml' && parsed.root == 'error'
46
+ end
47
+
48
+ def error
49
+ Error.new(parsed, self)
50
+ end
51
+ memoized :error
52
+
53
+ def parsed()
54
+ # XmlSimple is picky about what kind of object it parses, so we pass in body rather than self
55
+ Parsing::XmlParser.new(body)
56
+ end
57
+ memoized :parsed
58
+
59
+ def inspect
60
+ "#<%s:0x%s %s %s>" % [self.class, object_id, response.code, response.message]
61
+ end
62
+ end
63
+ end
64
+
65
+ class Bucket
66
+ class Response < Base::Response
67
+ def bucket
68
+ parsed
69
+ end
70
+ end
71
+ end
72
+
73
+ class S3Object
74
+ class Response < Base::Response
75
+ def etag
76
+ headers['etag'][1...-1]
77
+ end
78
+ end
79
+ end
80
+
81
+ class Service
82
+ class Response < Base::Response
83
+ def empty?
84
+ parsed['buckets'].nil?
85
+ end
86
+
87
+ def buckets
88
+ parsed['buckets']['bucket'] || []
89
+ end
90
+ end
91
+ end
92
+
93
+ module ACL
94
+ class Policy
95
+ class Response < Base::Response
96
+ alias_method :policy, :parsed
97
+ end
98
+ end
99
+ end
100
+
101
+ # Requests whose response code is between 300 and 599 and contain an <Error></Error> in their body
102
+ # are wrapped in an Error::Response. This Error::Response contains an Error object which raises an exception
103
+ # that corresponds to the error in the response body. The exception object contains the ErrorResponse, so
104
+ # in all cases where a request happens, you can rescue ResponseError and have access to the ErrorResponse and
105
+ # its Error object which contains information about the ResponseError.
106
+ #
107
+ # begin
108
+ # Bucket.create(..)
109
+ # rescue ResponseError => exception
110
+ # exception.response
111
+ # # => <Error::Response>
112
+ # exception.response.error
113
+ # # => <Error>
114
+ # end
115
+ class Error
116
+ class Response < Base::Response
117
+ def error?
118
+ true
119
+ end
120
+
121
+ def inspect
122
+ "#<%s:0x%s %s %s: '%s'>" % [self.class.name, object_id, response.code, error.code, error.message]
123
+ end
124
+ end
125
+ end
126
+
127
+ # Guess response class name from current class name. If the guessed response class doesn't exist
128
+ # do the same thing to the current class's parent class, up the inheritance heirarchy until either
129
+ # a response class is found or until we get to the top of the heirarchy in which case we just use
130
+ # the the Base response class.
131
+ #
132
+ # Important: This implemantation assumes that the Base class has a corresponding Base::Response.
133
+ class FindResponseClass #:nodoc:
134
+ class << self
135
+ def for(start)
136
+ new(start).find
137
+ end
138
+ end
139
+
140
+ def initialize(start)
141
+ @container = AWS::S3
142
+ @current_class = start
143
+ end
144
+
145
+ def find
146
+ self.current_class = current_class.superclass until response_class_found?
147
+ target.const_get(class_to_find)
148
+ end
149
+
150
+ private
151
+ attr_reader :container
152
+ attr_accessor :current_class
153
+
154
+ def target
155
+ container.const_get(current_name)
156
+ end
157
+
158
+ def target?
159
+ container.const_defined?(current_name)
160
+ end
161
+
162
+ def response_class_found?
163
+ target? && target.const_defined?(class_to_find)
164
+ end
165
+
166
+ def class_to_find
167
+ :Response
168
+ end
169
+
170
+ def current_name
171
+ truncate(current_class)
172
+ end
173
+
174
+ def truncate(klass)
175
+ klass.name[/[^:]+$/]
176
+ end
177
+ end
178
+ end
179
+ end
180
+ #:startdoc:
@@ -0,0 +1,51 @@
1
+ module AWS
2
+ module S3
3
+ # The service lets you find out general information about your account, like what buckets you have.
4
+ #
5
+ # Service.buckets
6
+ # # => []
7
+ class Service < Base
8
+ @@response = nil #:nodoc:
9
+
10
+ class << self
11
+ # List all your buckets.
12
+ #
13
+ # Service.buckets
14
+ # # => []
15
+ #
16
+ # For performance reasons, the bucket list will be cached. If you want avoid all caching, pass the <tt>:reload</tt>
17
+ # as an argument:
18
+ #
19
+ # Service.buckets(:reload)
20
+ def buckets
21
+ response = get('/')
22
+ if response.empty?
23
+ []
24
+ else
25
+ response.buckets.map {|attributes| Bucket.new(attributes)}
26
+ end
27
+ end
28
+ memoized :buckets
29
+
30
+ # Sometimes methods that make requests to the S3 servers return some object, like a Bucket or an S3Object.
31
+ # Othertimes they return just <tt>true</tt>. Other times they raise an exception that you may want to rescue. Despite all these
32
+ # possible outcomes, every method that makes a request stores its response object for you in Service.response. You can always
33
+ # get to the last request's response via Service.response.
34
+ #
35
+ # objects = Bucket.objects('jukebox')
36
+ # Service.response.success?
37
+ # # => true
38
+ #
39
+ # This is also useful when an error exception is raised in the console which you weren't expecting. You can
40
+ # root around in the response to get more details of what might have gone wrong.
41
+ def response
42
+ @@response
43
+ end
44
+
45
+ def response=(response) #:nodoc:
46
+ @@response = response
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ module AWS
2
+ module S3
3
+ module VERSION #:nodoc:
4
+ MAJOR = '0'
5
+ MINOR = '6'
6
+ TINY = '2'
7
+ BETA = Time.now.to_i.to_s
8
+ end
9
+
10
+ Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY, VERSION::BETA].compact * '.'
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
8
+ <title>AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)</title>
9
+ <link rel="Stylesheet" href="screen.css" type="text/css" media="screen" />
10
+ <link rel="Stylesheet" href="ruby.css" type="text/css" media="screen" />
11
+ <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
12
+ </head>
13
+
14
+ <body>
15
+ <div class="page_area">
16
+ <div class="left_column">
17
+ <img id="logo" src="images/box-and-gem.gif" />
18
+ </div>
19
+ <div class="column">
20
+ <div class="header">
21
+ <h2>AWS::S3</h2>
22
+ <h3>A Ruby Library for Amazon's Simple<br />Storage Service's (S3) REST API.</h3>
23
+ <p class="links">
24
+ <a href="http://github.com/marcel/aws-s3/tree/master">Browse code</a> |
25
+ <a href="http://amazon.rubyforge.org/doc/">Docs</a> |
26
+ <a href="http://rubyforge.org/frs/?group_id=2409">Downloads</a> |
27
+ <a href="http://rubyforge.org/tracker/?group_id=2409">Bugs &amp; Patches</a> |
28
+ <a href="http://rubyforge.org/mailman/listinfo/amazon-s3-dev">Mailing list</a></p>
29
+ <h4>Download with RubyGems</h4>
30
+ <pre>sudo gem i aws-s3</pre>
31
+ <h4>Clone from the master git repository</h4>
32
+ <pre>git clone git://github.com/marcel/aws-s3.git</pre>
33
+ </div>
34
+
35
+ <div class="readme">
36
+
37
+ <h2>Readme</h2>
38
+ <h4 class="first">Getting started</h4>
39
+ <%= erb_data[:readme] %>
40
+ </body>
41
+ </html>
@@ -0,0 +1,18 @@
1
+ .ruby {border: 1px solid #333; }
2
+ .ruby .normal {}
3
+ .ruby .comment { color: #666; background-color: #eee; font-style: italic; }
4
+ .ruby .keyword { color: #c96; font-weight: bold; }
5
+ .ruby .method { color: #333; }
6
+ .ruby .class { color: #333; }
7
+ .ruby .module { color: #333; }
8
+ .ruby .punct { color: #333; font-weight: bold; }
9
+ .ruby .symbol { color: #333; }
10
+ .ruby .string { color: #996; }
11
+ .ruby .char { color: #999; }
12
+ .ruby .ident { color: #333; }
13
+ .ruby .constant { color: #69c; font-weight: bold;}
14
+ .ruby .regex { color: #333; }
15
+ .ruby .number { color: #333; }
16
+ .ruby .attribute { color: #333; }
17
+ .ruby .global { color: #333; }
18
+ .ruby .expr { color: #333; }