s33r 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ # Logfile created on Thu Feb 01 10:15:18 +0000 2007 by logger.rb/1.5.2.9
@@ -0,0 +1 @@
1
+ 5232
@@ -97,5 +97,10 @@ module S33r
97
97
  def log_receiver(state=:on)
98
98
  change_log_target_status(name, state)
99
99
  end
100
+
101
+ # Get logging status for bucket
102
+ def logging
103
+ super(:bucket => name)
104
+ end
100
105
  end
101
- end
106
+ end
@@ -41,7 +41,7 @@ module S33r
41
41
  self.send("#{prop}=", node.content) if node
42
42
  end
43
43
 
44
- # metadata
44
+ # metadata on the bucket
45
45
  prop_setter.call(:name, 'Name')
46
46
  prop_setter.call(:delimiter, 'Delimiter')
47
47
  prop_setter.call(:prefix, 'Prefix')
@@ -10,6 +10,9 @@ module S33r
10
10
 
11
11
  # Use SSL for requests.
12
12
  attr_accessor :use_ssl
13
+
14
+ # Use subdomains (set on host header)
15
+ attr_accessor :subdomain
13
16
 
14
17
  # Default expiry for authenticated URLs.
15
18
  attr_accessor :expires
@@ -24,6 +27,7 @@ module S33r
24
27
  def request_defaults
25
28
  defaults = {}
26
29
  defaults[:use_ssl] = @use_ssl
30
+ defaults[:subdomain] = @subdomain
27
31
  defaults[:expires] = @expires
28
32
  defaults[:access] = @access
29
33
  defaults[:secret] = @secret
@@ -63,6 +67,7 @@ module S33r
63
67
  # option when generating authenticated URLs. Should be parseable by S33r.parse_expiry.
64
68
  # * <tt>:canned_acl => 'public-read'</tt>: set a default canned acl to apply to all put
65
69
  # requests.
70
+ # * <tt>:subdomain => false</tt>: set to true to use subdomains in URLs
66
71
  #
67
72
  # These options change the behaviour of the HTTP client which actually sends the request:
68
73
  # * <tt>:chunk_size => Integer</tt>: use a non-standard chunk size;
@@ -74,6 +79,8 @@ module S33r
74
79
  # General client options.
75
80
  @access = options[:access]
76
81
  @secret = options[:secret]
82
+ @subdomain = false
83
+ @subdomain = true if (true == options[:subdomain])
77
84
  @use_ssl = true
78
85
  @use_ssl = false if (false == options[:use_ssl])
79
86
  @expires = options[:expires] || 'never'
@@ -190,7 +197,7 @@ module S33r
190
197
  end
191
198
 
192
199
  options[:querystring] = querystring
193
-
200
+
194
201
  resp = do_get(options)
195
202
 
196
203
  if resp.ok?
@@ -375,7 +382,7 @@ module S33r
375
382
  # otherwise 'log-<bucket name>-' is used
376
383
  def logs_to(target_bucket, options={})
377
384
  target_bucket_name = target_bucket.is_a?(Bucket) ? target_bucket.name : target_bucket
378
- log_prefix = options[:prefix] || "log-#{bucket_name}-"
385
+ log_prefix = options[:prefix] || "log-#{target_bucket_name}-"
379
386
  options[:bucket] ||= options[:for_bucket]
380
387
 
381
388
  target_bucket_acl = get_acl(:bucket => target_bucket_name)
@@ -397,4 +404,4 @@ module S33r
397
404
  put(LoggingResource.new, options)
398
405
  end
399
406
  end
400
- end
407
+ end
@@ -72,8 +72,11 @@ module S33r
72
72
  # Generate the S3 authorization header if the client has
73
73
  # the appropriate instance variable getters.
74
74
  unless (false == url_options[:authenticated])
75
+ subdomain = nil
76
+ subdomain = url_options[:bucket] if url_options[:subdomain]
77
+
75
78
  headers['Authorization'] = generate_auth_header_value(method, path, headers,
76
- url_options[:access], url_options[:secret])
79
+ url_options[:access], url_options[:secret], subdomain)
77
80
  end
78
81
 
79
82
  # Insert the headers into the request object.
@@ -106,7 +109,7 @@ module S33r
106
109
  data = nil
107
110
  end
108
111
 
109
- puts req.to_s if @dump_requests
112
+ puts req.dump(uri.host) if @dump_requests
110
113
 
111
114
  # Set up the request.
112
115
  ### <snip> start shameless stealing from Marcel Molina
@@ -180,4 +183,4 @@ module S33r
180
183
  do_request('HEAD', options, headers)
181
184
  end
182
185
  end
183
- end
186
+ end
@@ -54,10 +54,10 @@ class Net::HTTPGenericRequest
54
54
  #
55
55
  # Switch on request debugging by passing <tt>:dump_requests => true</tt> to S33r::Client
56
56
  # constructor.
57
- def to_s
57
+ def dump(host)
58
58
  str = "*******\n" +
59
59
  "#{self.class::METHOD} #{@path} HTTP/1.1\n" +
60
- "Host: #{S33r::HOST}\n"
60
+ "Host: #{host}\n"
61
61
 
62
62
  self.each_capitalized do |key, value|
63
63
  str += "#{key}: #{value}\n"
@@ -84,8 +84,9 @@ class Net::HTTPGenericRequest
84
84
  sock.write "0\r\n\r\n"
85
85
  else
86
86
  while s = f.read(@chunk_size)
87
+ puts "Writing " + @chunk_size.to_s + " bytes to network stream"
87
88
  sock.write s
88
89
  end
89
90
  end
90
91
  end
91
- end
92
+ end
@@ -10,7 +10,7 @@ module S33r
10
10
  # To set a Bucket up for logging, create a LoggingResource with the correct log_target and
11
11
  # log_prefix settings and put that to the ?logging URL for a bucket.
12
12
  class LoggingResource
13
- attr_reader :log_target, :log_prefix
13
+ attr_accessor :log_target, :log_prefix
14
14
 
15
15
  # +log_target+ is the bucket to put logs into.
16
16
  # +log_prefix+ is the prefix for log files put into the +log_target+ bucket.
@@ -109,4 +109,4 @@ module S33r
109
109
  end
110
110
  end
111
111
  end
112
- end
112
+ end
@@ -99,7 +99,8 @@ module S33r
99
99
  # * +headers+ is a hash of headers which are going to be sent with the request.
100
100
  # * +expires+ is the expiry time set in the querystring for authenticated URLs:
101
101
  # if supplied, it is used for the +date+ header.
102
- def generate_canonical_string(method, path, headers={}, expires=nil)
102
+ # * +subdomain+ is the bucket name if using "virtual hosts"
103
+ def generate_canonical_string(method, path, headers={}, expires=nil, subdomain=nil)
103
104
  interesting_headers = {}
104
105
  headers.each do |key, value|
105
106
  lk = key.downcase
@@ -117,7 +118,9 @@ module S33r
117
118
  interesting_headers['date'] = expires
118
119
  end
119
120
 
120
- buf = "#{method}\n"
121
+ buf = ''
122
+
123
+ buf << "#{method}\n"
121
124
  interesting_headers.sort { |a, b| a[0] <=> b[0] }.each do |key, value|
122
125
  if key =~ /^#{AWS_HEADER_PREFIX}/o
123
126
  buf << "#{key}:#{value}\n"
@@ -126,6 +129,8 @@ module S33r
126
129
  end
127
130
  end
128
131
 
132
+ buf << '/' + subdomain unless subdomain.nil?
133
+
129
134
  # Ignore everything after the question mark...
130
135
  buf << path.gsub(/\?.*$/, '')
131
136
 
@@ -142,7 +147,7 @@ module S33r
142
147
  end
143
148
 
144
149
  # Get the value for the AWS authentication header.
145
- def generate_auth_header_value(method, path, headers, aws_access_key, aws_secret_access_key)
150
+ def generate_auth_header_value(method, path, headers, aws_access_key, aws_secret_access_key, subdomain)
146
151
  raise MethodNotAllowed, "Method %s not available" % method if !METHOD_VERBS.include?(method)
147
152
 
148
153
  # check the headers needed for authentication have been set
@@ -156,7 +161,7 @@ module S33r
156
161
  if aws_access_key.nil? or aws_secret_access_key.nil?
157
162
 
158
163
  # get the AWS header
159
- canonical_string = generate_canonical_string(method, path, headers)
164
+ canonical_string = generate_canonical_string(method, path, headers, nil, subdomain)
160
165
  signature = generate_signature(aws_secret_access_key, canonical_string)
161
166
  AWS_AUTH_HEADER_VALUE % [aws_access_key, signature]
162
167
  end
@@ -367,7 +372,7 @@ module S33r
367
372
  path = options[:path]
368
373
  path ||= s3_path(options)
369
374
  host = HOST
370
- host = (options[:bucket] + "." + host ) if options[:subdomain]
375
+ host = (options[:bucket] + "." + host ) if options[:subdomain] and options[:bucket]
371
376
  "#{scheme}://" + host + path
372
377
  end
373
378
 
@@ -439,4 +444,4 @@ module S33r
439
444
  namespace = S33r::RESPONSE_NAMESPACE_URI.gsub('/', '\/')
440
445
  xml_in.gsub(/ xmlns="#{namespace}"/, '')
441
446
  end
442
- end
447
+ end
@@ -68,12 +68,12 @@ context 'S33r ACL functions' do
68
68
  specify 'needs equality method for grantees' do
69
69
  test_grantee = Group.new(:all_users)
70
70
  test_grantee.should == @group_grantee
71
- test_grantee.should.not.equal @amazon_grantee
71
+ test_grantee.should_not equal @amazon_grantee
72
72
  end
73
73
 
74
74
  specify 'should only accept valid permission specifiers' do
75
- lambda { Grant.new(@group_grantee, nil) }.should.raise InvalidPermission
76
- lambda { Grant.new(@group_grantee, :broken) }.should.raise InvalidPermission
75
+ lambda { Grant.new(@group_grantee, nil) }.should raise_error InvalidPermission
76
+ lambda { Grant.new(@group_grantee, :broken) }.should raise_error InvalidPermission
77
77
  end
78
78
 
79
79
  specify 'should correctly create AmazonCustomer grantee from XML node' do
@@ -111,6 +111,6 @@ context 'S33r ACL functions' do
111
111
  @full_acl_doc.grants.each do |g|
112
112
  acl_doc_from_xml.grants = acl_doc_from_xml.grants.delete_if { |i| i == g }
113
113
  end
114
- acl_doc_from_xml.grants.should.be.empty
114
+ acl_doc_from_xml.grants.size.should == 0
115
115
  end
116
- end
116
+ end
@@ -15,15 +15,15 @@ context 'S33r bucket listing' do
15
15
  end
16
16
 
17
17
  specify 'can only be created if bucket listing XML supplied' do
18
- lambda { BucketListing.new }.should.raise ArgumentError
18
+ lambda { BucketListing.new }.should raise_error ArgumentError
19
19
  end
20
20
 
21
21
  specify 'cannot be created from invalid XML' do
22
- lambda { BucketListing.new(nil) }.should.raise S3Exception::InvalidBucketListing
22
+ lambda { BucketListing.new(nil) }.should raise_error S3Exception::InvalidBucketListing
23
23
  end
24
24
 
25
25
  specify 'should recover gracefully from broken bucket listing XML' do
26
- lambda { BucketListing.new(@with_broken_bucket_listing_xml) }.should.raise S3Exception::InvalidBucketListing
26
+ lambda { BucketListing.new(@with_broken_bucket_listing_xml) }.should raise_error S3Exception::InvalidBucketListing
27
27
  end
28
28
 
29
29
  specify 'should cope if bucket is empty (i.e. no <Contents> elements)' do
@@ -40,7 +40,7 @@ context 'S33r bucket listing' do
40
40
  @bucket_listing.marker.should ==('')
41
41
  @bucket_listing.max_keys.should ==(1000)
42
42
  @bucket_listing.is_truncated.should ==(false)
43
- @bucket_listing.delimiter.should.be nil
43
+ @bucket_listing.delimiter.should be nil
44
44
  end
45
45
 
46
46
  specify 'when listing XML is reset, should update all properties correctly' do
@@ -63,16 +63,16 @@ context 'S33r bucket listing' do
63
63
  end
64
64
 
65
65
  specify 'should store resources (<Contents> elements) in a hash' do
66
- @bucket_listing.size.should_be 10
66
+ @bucket_listing.size.should be 10
67
67
  first_obj = @bucket_listing['/home/ell/dir1/four.txt']
68
- first_obj.should_be_instance_of S3Object
68
+ first_obj.should be_instance_of S3Object
69
69
  end
70
70
 
71
71
  # attempting to fix ListBucketResult errors reported by Alex Payne
72
72
  specify 'should handle suspect bucket listing' do
73
73
  puts @with_suspect_bl_xml
74
74
  bl = BucketListing.new(@with_suspect_bl_xml)
75
- bl.size.should_be 1
76
- bl.keys.should.include 'orly.jpg'
75
+ bl.size.should be 1
76
+ bl.keys.should include 'orly.jpg'
77
77
  end
78
- end
78
+ end
@@ -29,19 +29,19 @@ context 'S33r logging' do
29
29
  end
30
30
 
31
31
  specify 'should represent LogDelivery grants so buckets can act as logging targets' do
32
- @logging_acl_doc.grants.should.include @log_delivery_write
33
- @logging_acl_doc.grants.should.include @log_delivery_read_acl
32
+ @logging_acl_doc.grants.should include @log_delivery_write
33
+ @logging_acl_doc.grants.should include @log_delivery_read_acl
34
34
  end
35
35
 
36
36
  specify 'should be able to report whether an ACL indicates bucket is a logging target' do
37
- @logging_acl_doc.log_targetable?.should.be true
37
+ @logging_acl_doc.log_targetable?.should be true
38
38
 
39
39
  # check the variant where the grants have been removed
40
- @logging_acl_doc_no_grants.log_targetable?.should.be false
40
+ @logging_acl_doc_no_grants.log_targetable?.should be false
41
41
  end
42
42
 
43
43
  specify 'should be able to simply add logging target grants to an ACL' do
44
44
  @logging_acl_doc_no_grants.add_log_target_grants
45
45
  clean_xml(@logging_acl_doc_no_grants.to_xml).should == @logging_acl_xml
46
46
  end
47
- end
47
+ end
@@ -34,27 +34,11 @@ context 'S3 object' do
34
34
  @s3obj2.bucket.name.should == 'quotes'
35
35
  end
36
36
 
37
- specify 'can be created from a file' do
38
- todo
39
- end
40
-
41
37
  specify 'should treat the owner as an object in his/her own right' do
42
38
  [@s3obj.owner.user_id, @s3obj.owner.display_name].should == \
43
39
  ['56efddfead5aa65da942f156fb2b294f44d78fd932d701331edc5fba19620fd4', 'elliotsmith3']
44
40
  @s3obj.owner.should_be_instance_of S3ACL::CanonicalUser
45
41
  end
46
-
47
- specify 'can be saved' do
48
- todo
49
- end
50
-
51
- specify 'can be renamed' do
52
- todo
53
- end
54
-
55
- specify 'can be deleted' do
56
- todo
57
- end
58
42
 
59
43
  specify 'should return authenticated URL' do
60
44
  @s3obj2.url(:authenticated => true, :expires => 1141889120).should == @correct_authenticated_url
@@ -71,4 +55,4 @@ context 'S3 object' do
71
55
  specify 'should optionally return URL with domain name set to bucket name' do
72
56
  @s3obj2.url(:subdomain => true).should == @correct_public_url_with_subdomain
73
57
  end
74
- end
58
+ end
@@ -63,7 +63,7 @@ context 'S33r utility' do
63
63
  config, options = S33r.load_config(@yaml_file)
64
64
  options[:email_to].should == Testing::EMAIL
65
65
  # Make sure the 'options' section has not been included in the general config..
66
- config.keys.should.not.include :options
66
+ config.keys.should_not include :options
67
67
  end
68
68
 
69
69
  specify 'should generate correct canonical strings' do
@@ -78,17 +78,17 @@ context 'S33r utility' do
78
78
 
79
79
  specify 'should generate correct auth headers' do
80
80
  generate_auth_header_value(@for_request_method, @for_request_path, @for_request_headers,
81
- Testing::ACCESS_KEY, Testing::SECRET_ACCESS_KEY).should == @correct_auth_header
81
+ Testing::ACCESS_KEY, Testing::SECRET_ACCESS_KEY, nil).should == @correct_auth_header
82
82
  end
83
83
 
84
84
  specify 'should not generate auth header if bad HTTP method passed' do
85
- lambda { generate_auth_header_value('duff', nil, nil, nil, nil) }.should.raise \
85
+ lambda { generate_auth_header_value('duff', nil, nil, nil, nil, nil) }.should raise_error \
86
86
  MethodNotAllowed
87
87
  end
88
88
 
89
89
  specify 'should not generate auth header if required headers missing' do
90
90
  lambda { generate_auth_header_value('PUT', '/', @for_incomplete_headers,
91
- nil, nil) }.should.raise MissingRequiredHeaders
91
+ nil, nil, nil) }.should raise_error MissingRequiredHeaders
92
92
  end
93
93
 
94
94
  specify 'when generating auth header, should allow addition of Date and Content-Type headers' do
@@ -104,28 +104,28 @@ context 'S33r utility' do
104
104
  specify 'should generate correct x-amz-meta- headers from a hash' do
105
105
  meta = {'myname' => 'elliot', 'myage' => 36}
106
106
  headers = metadata_headers(meta)
107
- headers.should.include 'x-amz-meta-myname'
108
- headers.should.include 'x-amz-meta-myage'
107
+ headers.should include 'x-amz-meta-myname'
108
+ headers.should include 'x-amz-meta-myage'
109
109
  headers['x-amz-meta-myname'].should == 'elliot'
110
110
  headers['x-amz-meta-myage'].should == '36'
111
111
  end
112
112
 
113
113
  specify 'should not generate canned ACL header if invalid canned ACL supplied' do
114
- lambda { canned_acl_header('duff') }.should.raise \
114
+ lambda { canned_acl_header('duff') }.should raise_error \
115
115
  UnsupportedCannedACL
116
116
  end
117
117
 
118
118
  specify 'should correctly add canned ACL headers' do
119
119
  new_headers = canned_acl_header('private')
120
- new_headers.should.have(1).keys
121
- new_headers.keys.should.include 'x-amz-acl'
120
+ new_headers.should have(1).keys
121
+ new_headers.keys.should include 'x-amz-acl'
122
122
  new_headers['x-amz-acl'].should == 'private'
123
123
  end
124
124
 
125
125
  specify 'should set sensible defaults for missing Content-Type and Date headers' do
126
126
  fixed_headers = default_headers(@for_incomplete_headers)
127
127
  fixed_headers['Content-Type'].should == ''
128
- fixed_headers.include?('Date').should.not.be nil
128
+ fixed_headers.include?('Date').should_not === nil
129
129
  end
130
130
 
131
131
  specify 'should default to text/plain mimetype for unknown file types' do
@@ -144,9 +144,9 @@ context 'S33r utility' do
144
144
  end
145
145
 
146
146
  specify 'should recognise invalid bucket names' do
147
- lambda { bucket_name_valid?(@with_invalid_bucket_name) }.should.raise \
147
+ lambda { bucket_name_valid?(@with_invalid_bucket_name) }.should raise_error \
148
148
  MalformedBucketName
149
- lambda { bucket_name_valid?(@with_invalid_bucket_name2) }.should.raise \
149
+ lambda { bucket_name_valid?(@with_invalid_bucket_name2) }.should raise_error \
150
150
  MalformedBucketName
151
151
  end
152
152
 
@@ -234,14 +234,14 @@ context 'S33r utility' do
234
234
  expected_expiry = Time.now.to_i + DEFAULT_EXPIRY_SECS
235
235
  expires = S33r.parse_expiry
236
236
  expires.should == expected_expiry
237
- expires.should_be_kind_of Integer
237
+ expires.class.should == Bignum
238
238
 
239
239
  # If :far_flung_future is passed, default to 20 years from now.
240
240
  expected_expiry = Time.now.to_i +
241
241
  (60 * 60 * 24 * 365.25 * 20).to_i
242
242
  expires = S33r.parse_expiry(:far_flung_future)
243
243
  expires.should == expected_expiry
244
- expires.should_be_kind_of Integer
244
+ expires.class.should == Bignum
245
245
 
246
246
  class Time
247
247
  remove_method(:to_i)
@@ -254,7 +254,7 @@ context 'S33r utility' do
254
254
  expected_expiry = Time.parse(datetime_str).to_i
255
255
  expires = S33r.parse_expiry(datetime_str)
256
256
  expires.should == expected_expiry
257
- expires.should_be_kind_of Integer
257
+ expires.class.should == Bignum
258
258
  end
259
259
 
260
260
  specify 'should provide a method for converting string keys of a hash into symbols' do
@@ -268,4 +268,4 @@ context 'S33r utility' do
268
268
  s3_url(:bucket => 'quotes', :key => 'some key').should == @url_with_unescaped_key
269
269
  end
270
270
 
271
- end
271
+ end