s33r 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/cli/simple.rb +17 -0
- data/examples/fores33r/app/controllers/browser_controller.rb +32 -8
- data/examples/fores33r/app/views/browser/_create_bucket.rhtml +6 -0
- data/examples/fores33r/app/views/browser/_upload.rhtml +5 -0
- data/examples/fores33r/app/views/browser/index.rhtml +1 -8
- data/examples/fores33r/app/views/browser/plain_bucket.rhtml +3 -0
- data/examples/fores33r/app/views/browser/s3_index.rhtml +9 -0
- data/examples/fores33r/app/views/browser/show_bucket.rhtml +6 -8
- data/examples/fores33r/app/views/layouts/application.rhtml +2 -0
- data/examples/fores33r/app/views/layouts/s3_layout.rhtml +14 -0
- data/examples/fores33r/config/environment.rb +1 -1
- data/examples/fores33r/config/routes.rb +2 -0
- data/examples/fores33r/public/stylesheets/core.css +2 -2
- data/html/classes/Net/HTTPResponse.html +3 -0
- data/html/classes/S33r.html +127 -116
- data/html/classes/S33r/BucketListing.html +119 -94
- data/html/classes/S33r/Client.html +602 -536
- data/html/classes/S33r/LoggingResource.html +3 -3
- data/html/classes/S33r/NamedBucket.html +235 -191
- data/html/classes/S33r/OrderlyXmlMarkup.html +7 -7
- data/html/classes/S33r/S33rException.html +1 -0
- data/html/classes/S33r/S33rException/TryingToPutEmptyResource.html +117 -0
- data/html/classes/S33r/S3ACL/ACLDoc.html +94 -94
- data/html/classes/S33r/S3ACL/AmazonCustomer.html +5 -5
- data/html/classes/S33r/S3ACL/CanonicalUser.html +12 -12
- data/html/classes/S33r/S3ACL/Grant.html +64 -64
- data/html/classes/S33r/S3ACL/Grantee.html +36 -36
- data/html/classes/S33r/S3ACL/Group.html +8 -8
- data/html/classes/S33r/S3Object.html +387 -79
- data/html/classes/XML.html +15 -15
- data/html/created.rid +1 -1
- data/html/files/CHANGELOG.html +7 -1
- data/html/files/MIT-LICENSE.html +1 -1
- data/html/files/README_txt.html +3 -7
- data/html/files/lib/s33r/bucket_listing_rb.html +1 -9
- data/html/files/lib/s33r/builder_rb.html +1 -1
- data/html/files/lib/s33r/client_rb.html +1 -1
- data/html/files/lib/s33r/core_rb.html +1 -2
- data/html/files/lib/s33r/libxml_extensions_rb.html +1 -7
- data/html/files/lib/s33r/libxml_loader_rb.html +109 -0
- data/html/files/lib/s33r/logging_rb.html +1 -2
- data/html/files/lib/s33r/mimetypes_rb.html +1 -1
- data/html/files/lib/s33r/named_bucket_rb.html +1 -1
- data/html/files/lib/s33r/s33r_exception_rb.html +1 -1
- data/html/files/lib/s33r/s33r_http_rb.html +1 -1
- data/html/files/lib/s33r/s3_acl_rb.html +1 -2
- data/html/files/lib/s33r/s3_obj_rb.html +108 -0
- data/html/files/lib/s33r/sync_rb.html +1 -1
- data/html/files/lib/s33r_rb.html +1 -1
- data/html/fr_class_index.html +1 -0
- data/html/fr_file_index.html +2 -0
- data/html/fr_method_index.html +80 -71
- data/lib/s33r/bucket_listing.rb +30 -55
- data/lib/s33r/client.rb +70 -28
- data/lib/s33r/core.rb +9 -4
- data/lib/s33r/libxml_extensions.rb +2 -0
- data/lib/s33r/libxml_loader.rb +6 -0
- data/lib/s33r/logging.rb +3 -3
- data/lib/s33r/named_bucket.rb +33 -15
- data/lib/s33r/s33r_exception.rb +4 -0
- data/lib/s33r/s33r_http.rb +1 -1
- data/lib/s33r/s3_acl.rb +3 -2
- data/lib/s33r/s3_obj.rb +186 -0
- data/test/cases/spec_bucket_listing.rb +9 -33
- data/test/cases/spec_s3_object.rb +35 -0
- data/test/files/suspect_bucket_listing.xml +19 -0
- metadata +94 -89
- data/examples/fores33r/log/development.log +0 -5960
- data/examples/fores33r/log/production.log +0 -0
- data/examples/fores33r/log/server.log +0 -0
- data/examples/fores33r/log/test.log +0 -0
- data/examples/fores33r/tmp/sessions/ruby_sess.2ea325f604aa5fb9 +0 -0
- data/examples/fores33r/tmp/sessions/ruby_sess.39d37e054d21d545 +0 -0
- data/examples/fores33r/tmp/sessions/ruby_sess.acf71fc73aa74983 +0 -0
- data/examples/fores33r/tmp/sessions/ruby_sess.c1697b7d6670f3cd +0 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Simple client for uploading individual files from the command line
|
3
|
+
require 'rubygems'
|
4
|
+
require 's33r'
|
5
|
+
|
6
|
+
local_file = ARGV[0]
|
7
|
+
base_name = File.basename(local_file)
|
8
|
+
bucket = ARGV[1]
|
9
|
+
|
10
|
+
puts "Uploading #{local_file} as '#{base_name}' to '#{bucket}'"
|
11
|
+
|
12
|
+
S33r::NamedBucket.new('accesskey', 'secretaccesskey',
|
13
|
+
:default_bucket => bucket) do |client|
|
14
|
+
client.put_file(local_file, base_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
puts "Uploaded!"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class BrowserController < ApplicationController
|
2
2
|
before_filter :get_s3_client
|
3
|
+
before_filter :get_bucket_listing, :only => ['show_bucket', 'plain_bucket', 'add_index']
|
3
4
|
|
4
5
|
def get_s3_client
|
5
6
|
@s3 = S3_CLIENT
|
@@ -8,17 +9,27 @@ class BrowserController < ApplicationController
|
|
8
9
|
|
9
10
|
def index
|
10
11
|
@buckets = @s3.list_buckets
|
12
|
+
@options_pane = 'create_bucket'
|
11
13
|
end
|
12
14
|
|
13
15
|
def show_bucket
|
14
|
-
@
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
@options_pane = 'upload'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Show bucket content as links in plain text.
|
20
|
+
def plain_bucket
|
21
|
+
response.headers['Content-Type'] = 'text/plain'
|
22
|
+
response.headers['Content-Disposition'] = 'attachment'
|
23
|
+
render :action => 'plain_bucket', :layout => false
|
24
|
+
end
|
25
|
+
|
26
|
+
# Add an S3 index page to the bucket (puts an HTML file index.html
|
27
|
+
# into the S3 bucket, with authenticated links to the bucket content).
|
28
|
+
def add_index
|
29
|
+
out = render(:action => 's3_index', :layout => 's3_layout')
|
30
|
+
@s3.put_resource(@bucket_name, 'index.html', out, {'Content-Type' => 'text/html'})
|
31
|
+
flash[:notice] = 'Added an index to the bucket'
|
32
|
+
response.redirect url_for(:action => 'show_bucket', :bucket_name => @bucket_name)
|
22
33
|
end
|
23
34
|
|
24
35
|
# NB this doesn't check whether the thing being deleted exists;
|
@@ -70,4 +81,17 @@ class BrowserController < ApplicationController
|
|
70
81
|
end
|
71
82
|
redirect_to :action => 'index'
|
72
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def get_bucket_listing
|
87
|
+
@bucket_name = params[:bucket_name]
|
88
|
+
resp, listing = @s3.list_bucket(@bucket_name)
|
89
|
+
if resp.ok?
|
90
|
+
@keys = listing.pretty
|
91
|
+
@objects = listing.contents
|
92
|
+
else
|
93
|
+
flash[:notice] = "Bucket listing could not be retrieved"
|
94
|
+
redirect_to :action => 'index'
|
95
|
+
end
|
96
|
+
end
|
73
97
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%= start_form_tag :action => 'create_bucket' %>
|
2
|
+
<p>Create a new bucket: <%= text_field 'bucket', 'name' %></p>
|
3
|
+
<p>Use your default bucket prefix (<strong><%= @default_prefix %></strong>)?
|
4
|
+
<%= check_box_tag 'bucket[prefix]', 1, true %></p>
|
5
|
+
<p><%= submit_tag 'Create' %></p>
|
6
|
+
<%= end_form_tag %>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<%= start_form_tag({:action => 'upload'}, :multipart => true) %>
|
2
|
+
<%= hidden_field 'upload', 'bucket_name', :value => @bucket_name %>
|
3
|
+
<p>Upload a file to this bucket:<br /><%= file_field('upload', 'filename') %></p>
|
4
|
+
<p><%= submit_tag 'Upload' %></p>
|
5
|
+
<%= end_form_tag %>
|
@@ -8,11 +8,4 @@
|
|
8
8
|
:bucket_name => bucket.name %> | <%= link_to 'delete', {:action => 'delete', :bucket_name => bucket.name},
|
9
9
|
:confirm => 'Are you sure you want to delete this bucket?' %></p>
|
10
10
|
<% end %>
|
11
|
-
<% end %>
|
12
|
-
|
13
|
-
<%= start_form_tag :action => 'create_bucket' %>
|
14
|
-
<p>Create a new bucket: <%= text_field 'bucket', 'name' %></p>
|
15
|
-
<p>Use your default bucket prefix (<strong><%= @default_prefix %></strong>)?
|
16
|
-
<%= check_box_tag 'bucket[prefix]', 1, true %></p>
|
17
|
-
<p><%= submit_tag 'Create' %></p>
|
18
|
-
<%= end_form_tag %>
|
11
|
+
<% end %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<h1>Contents of <%= @bucket_name %> bucket on S3</h1>
|
2
|
+
|
3
|
+
<% for key in @keys -%>
|
4
|
+
<% obj = @objects[key] -%>
|
5
|
+
<% size = " (#{human_size(obj.size)})" -%>
|
6
|
+
<% unless 'index.html' == key -%>
|
7
|
+
<%= content_tag 'p', link_to(key, authenticated_url(@bucket_name, key)) + size %>
|
8
|
+
<% end %>
|
9
|
+
<% end -%>
|
@@ -1,14 +1,12 @@
|
|
1
1
|
<h2>Content of bucket <em><%= @bucket_name %></em></h2>
|
2
2
|
|
3
|
+
<p>[ <%= link_to 'Authenticated URLs for bucket contents as plain text',
|
4
|
+
:action => 'plain_bucket', :bucket_name => @bucket_name %> |
|
5
|
+
<%= link_to 'Add index to bucket', :action => 'add_index', :bucket_name => @bucket_name %> ]</p>
|
6
|
+
|
3
7
|
<% for key in @keys do %>
|
4
|
-
<p><%= link_to key, authenticated_url(@bucket_name, key) %> 
|
8
|
+
<p><%= link_to key, authenticated_url(@bucket_name, key) %> |
|
5
9
|
<%= link_to 'delete', {:action => 'delete', :bucket_name => @bucket_name,
|
6
10
|
:resource_key => key}, :confirm => 'Are you sure you want to delete this resource?' %>
|
7
11
|
</p>
|
8
|
-
<% end %>
|
9
|
-
|
10
|
-
<%= start_form_tag({:action => 'upload'}, :multipart => true) %>
|
11
|
-
<%= hidden_field 'upload', 'bucket_name', :value => @bucket_name %>
|
12
|
-
<p>Upload a file to this bucket: <%= file_field('upload', 'filename') %></p>
|
13
|
-
<p><%= submit_tag 'Upload' %></p>
|
14
|
-
<%= end_form_tag %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_GB" xml:lang="en_GB">
|
5
|
+
<head>
|
6
|
+
<title>Contents of <%= @bucket_name %></title>
|
7
|
+
<%= stylesheet_link_tag 'core' %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= @content_for_layout %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -61,4 +61,4 @@ require File.join(RAILS_ROOT, '..', '..', 'lib', 's33r')
|
|
61
61
|
ACCESS_KEY, SECRET_ACCESS_KEY, S3_OPTIONS =
|
62
62
|
S33r::Client.load_config(File.join(RAILS_ROOT, 'config', 's3.yaml'))
|
63
63
|
|
64
|
-
S3_CLIENT = S33r::Client.new(ACCESS_KEY, SECRET_ACCESS_KEY, S3_OPTIONS)
|
64
|
+
S3_CLIENT = S33r::Client.new(ACCESS_KEY, SECRET_ACCESS_KEY, S3_OPTIONS)
|
@@ -14,6 +14,8 @@ ActionController::Routing::Routes.draw do |map|
|
|
14
14
|
map.connect '', :controller => 'browser'
|
15
15
|
|
16
16
|
map.connect '/show_bucket/:bucket_name', :controller => 'browser', :action => 'show_bucket'
|
17
|
+
map.connect '/plain_bucket/:bucket_name/listing.txt', :controller => 'browser', :action => 'plain_bucket'
|
18
|
+
map.connect '/add_index/:bucket_name', :controller => 'browser', :action => 'add_index'
|
17
19
|
map.connect '/delete/:bucket_name', :controller => 'browser', :action => 'delete'
|
18
20
|
map.connect '/delete/:bucket_name/:resource_key', :controller => 'browser', :action => 'delete'
|
19
21
|
map.connect '/create_bucket', :controller => 'browser', :action => 'create_bucket'
|
data/html/classes/S33r.html
CHANGED
@@ -55,40 +55,44 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../files/lib/s33r/
|
59
|
-
lib/s33r/
|
58
|
+
<a href="../files/lib/s33r/bucket_listing_rb.html">
|
59
|
+
lib/s33r/bucket_listing.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
62
62
|
<a href="../files/lib/s33r/client_rb.html">
|
63
63
|
lib/s33r/client.rb
|
64
64
|
</a>
|
65
65
|
<br />
|
66
|
-
<a href="../files/lib/s33r/
|
67
|
-
lib/s33r/
|
68
|
-
</a>
|
69
|
-
<br />
|
70
|
-
<a href="../files/lib/s33r/bucket_listing_rb.html">
|
71
|
-
lib/s33r/bucket_listing.rb
|
66
|
+
<a href="../files/lib/s33r/named_bucket_rb.html">
|
67
|
+
lib/s33r/named_bucket.rb
|
72
68
|
</a>
|
73
69
|
<br />
|
74
70
|
<a href="../files/lib/s33r/s3_acl_rb.html">
|
75
71
|
lib/s33r/s3_acl.rb
|
76
72
|
</a>
|
77
73
|
<br />
|
78
|
-
<a href="../files/lib/s33r/
|
79
|
-
lib/s33r/
|
74
|
+
<a href="../files/lib/s33r/s3_obj_rb.html">
|
75
|
+
lib/s33r/s3_obj.rb
|
80
76
|
</a>
|
81
77
|
<br />
|
82
|
-
<a href="../files/lib/s33r/
|
83
|
-
lib/s33r/
|
78
|
+
<a href="../files/lib/s33r/builder_rb.html">
|
79
|
+
lib/s33r/builder.rb
|
80
|
+
</a>
|
81
|
+
<br />
|
82
|
+
<a href="../files/lib/s33r/logging_rb.html">
|
83
|
+
lib/s33r/logging.rb
|
84
|
+
</a>
|
85
|
+
<br />
|
86
|
+
<a href="../files/lib/s33r/core_rb.html">
|
87
|
+
lib/s33r/core.rb
|
84
88
|
</a>
|
85
89
|
<br />
|
86
90
|
<a href="../files/lib/s33r/s33r_exception_rb.html">
|
87
91
|
lib/s33r/s33r_exception.rb
|
88
92
|
</a>
|
89
93
|
<br />
|
90
|
-
<a href="../files/lib/s33r/
|
91
|
-
lib/s33r/
|
94
|
+
<a href="../files/lib/s33r/sync_rb.html">
|
95
|
+
lib/s33r/sync.rb
|
92
96
|
</a>
|
93
97
|
<br />
|
94
98
|
</td>
|
@@ -374,13 +378,13 @@ Returns a hash with ‘symbolised’ keys.
|
|
374
378
|
onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
|
375
379
|
<div class="method-source-code" id="M000056-source">
|
376
380
|
<pre>
|
377
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
381
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 260</span>
|
382
|
+
260: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">keys_to_symbols</span>(<span class="ruby-identifier">hsh</span>)
|
383
|
+
261: <span class="ruby-identifier">symbolised</span> = <span class="ruby-identifier">hsh</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">symbolised</span>, <span class="ruby-identifier">key_value</span><span class="ruby-operator">|</span>
|
384
|
+
262: <span class="ruby-identifier">symbolised</span>.<span class="ruby-identifier">merge</span>({<span class="ruby-identifier">key_value</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_sym</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">key_value</span>[<span class="ruby-value">1</span>]})
|
385
|
+
263: <span class="ruby-keyword kw">end</span>
|
386
|
+
264: <span class="ruby-identifier">symbolised</span>
|
387
|
+
265: <span class="ruby-keyword kw">end</span>
|
384
388
|
</pre>
|
385
389
|
</div>
|
386
390
|
</div>
|
@@ -412,21 +416,21 @@ TODO: testing for this
|
|
412
416
|
onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
|
413
417
|
<div class="method-source-code" id="M000057-source">
|
414
418
|
<pre>
|
415
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
419
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 275</span>
|
420
|
+
275: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">parse_expiry</span>(<span class="ruby-identifier">expires</span>)
|
421
|
+
276: <span class="ruby-identifier">base_expires</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>
|
422
|
+
277: <span class="ruby-keyword kw">if</span> <span class="ruby-value str">'forever'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">expires</span>
|
423
|
+
278: <span class="ruby-comment cmt"># 20 years (same as forever in computer terms)</span>
|
424
|
+
279: <span class="ruby-identifier">expires</span> = <span class="ruby-identifier">base_expires</span> <span class="ruby-operator">+</span> (<span class="ruby-value">60</span> <span class="ruby-operator">*</span> <span class="ruby-value">60</span> <span class="ruby-operator">*</span> <span class="ruby-value">24</span> <span class="ruby-operator">*</span> <span class="ruby-value">365.25</span> <span class="ruby-operator">*</span> <span class="ruby-value">20</span>).<span class="ruby-identifier">to_i</span>
|
425
|
+
280: <span class="ruby-keyword kw">elsif</span> <span class="ruby-value str">'default'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">expires</span>
|
426
|
+
281: <span class="ruby-comment cmt"># default to DEFAULT_EXPIRY_SECS seconds from now if expires not set</span>
|
427
|
+
282: <span class="ruby-identifier">expires</span> = <span class="ruby-identifier">base_expires</span> <span class="ruby-operator">+</span> <span class="ruby-constant">DEFAULT_EXPIRY_SECS</span>
|
428
|
+
283: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">expires</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
|
429
|
+
284: <span class="ruby-identifier">datetime_parts</span> = <span class="ruby-constant">ParseDate</span>.<span class="ruby-identifier">parsedate</span>(<span class="ruby-identifier">expires</span>)
|
430
|
+
285: <span class="ruby-identifier">expires</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">gm</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">datetime_parts</span>).<span class="ruby-identifier">to_i</span>
|
431
|
+
286: <span class="ruby-keyword kw">end</span>
|
432
|
+
287: <span class="ruby-identifier">expires</span>
|
433
|
+
288: <span class="ruby-keyword kw">end</span>
|
430
434
|
</pre>
|
431
435
|
</div>
|
432
436
|
</div>
|
@@ -450,11 +454,11 @@ response bodies (libxml isn’t fond of it).
|
|
450
454
|
onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
|
451
455
|
<div class="method-source-code" id="M000058-source">
|
452
456
|
<pre>
|
453
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
457
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 292</span>
|
458
|
+
292: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">remove_namespace</span>(<span class="ruby-identifier">xml_in</span>)
|
459
|
+
293: <span class="ruby-identifier">namespace</span> = <span class="ruby-constant">S33r</span><span class="ruby-operator">::</span><span class="ruby-constant">RESPONSE_NAMESPACE_URI</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'/'</span>, <span class="ruby-value str">'\/'</span>)
|
460
|
+
294: <span class="ruby-identifier">xml_in</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-node">/ xmlns="#{namespace}"/</span>, <span class="ruby-value str">''</span>)
|
461
|
+
295: <span class="ruby-keyword kw">end</span>
|
458
462
|
</pre>
|
459
463
|
</div>
|
460
464
|
</div>
|
@@ -519,12 +523,12 @@ Ensure that a bucket_name is well-formed (no leading or trailing slash).
|
|
519
523
|
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
520
524
|
<div class="method-source-code" id="M000048-source">
|
521
525
|
<pre>
|
522
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
526
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 195</span>
|
527
|
+
195: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">bucket_name_valid?</span>(<span class="ruby-identifier">bucket_name</span>)
|
528
|
+
196: <span class="ruby-keyword kw">if</span> (<span class="ruby-value str">'/'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">bucket_name</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'/'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">bucket_name</span>[<span class="ruby-value">-1</span>,<span class="ruby-value">1</span>])
|
529
|
+
197: <span class="ruby-identifier">raise</span> <span class="ruby-constant">S33rException</span><span class="ruby-operator">::</span><span class="ruby-constant">MalformedBucketName</span>, <span class="ruby-value str">"Bucket name cannot have a leading or trailing slash"</span>
|
530
|
+
198: <span class="ruby-keyword kw">end</span>
|
531
|
+
199: <span class="ruby-keyword kw">end</span>
|
528
532
|
</pre>
|
529
533
|
</div>
|
530
534
|
</div>
|
@@ -547,16 +551,16 @@ Add a canned ACL setter header.
|
|
547
551
|
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
548
552
|
<div class="method-source-code" id="M000046-source">
|
549
553
|
<pre>
|
550
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
554
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 176</span>
|
555
|
+
176: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">canned_acl_header</span>(<span class="ruby-identifier">canned_acl</span>, <span class="ruby-identifier">headers</span>={})
|
556
|
+
177: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">canned_acl</span>.<span class="ruby-identifier">nil?</span>
|
557
|
+
178: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">CANNED_ACLS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">canned_acl</span>)
|
558
|
+
179: <span class="ruby-identifier">raise</span> <span class="ruby-constant">S33rException</span><span class="ruby-operator">::</span><span class="ruby-constant">UnsupportedCannedACL</span>, <span class="ruby-node">"The canned ACL #{canned_acl} is not supported"</span>
|
559
|
+
180: <span class="ruby-keyword kw">end</span>
|
560
|
+
181: <span class="ruby-identifier">headers</span>[<span class="ruby-constant">AWS_HEADER_PREFIX</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'acl'</span>] = <span class="ruby-identifier">canned_acl</span>
|
561
|
+
182: <span class="ruby-keyword kw">end</span>
|
562
|
+
183: <span class="ruby-identifier">headers</span>
|
563
|
+
184: <span class="ruby-keyword kw">end</span>
|
560
564
|
</pre>
|
561
565
|
</div>
|
562
566
|
</div>
|
@@ -683,14 +687,14 @@ variable can be a string or symbol.
|
|
683
687
|
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
684
688
|
<div class="method-source-code" id="M000049-source">
|
685
689
|
<pre>
|
686
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
690
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 203</span>
|
691
|
+
203: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_querystring</span>(<span class="ruby-identifier">pairs</span>={})
|
692
|
+
204: <span class="ruby-identifier">str</span> = <span class="ruby-value str">''</span>
|
693
|
+
205: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pairs</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
694
|
+
206: <span class="ruby-identifier">str</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">"?"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">pairs</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-node">"#{key}=#{CGI::escape(value.to_s)}"</span> }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'&'</span>)
|
695
|
+
207: <span class="ruby-keyword kw">end</span>
|
696
|
+
208: <span class="ruby-identifier">str</span>
|
697
|
+
209: <span class="ruby-keyword kw">end</span>
|
694
698
|
</pre>
|
695
699
|
</div>
|
696
700
|
</div>
|
@@ -742,12 +746,12 @@ guessed, "text/plain" is used.
|
|
742
746
|
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
743
747
|
<div class="method-source-code" id="M000047-source">
|
744
748
|
<pre>
|
745
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
749
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 188</span>
|
750
|
+
188: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">guess_mime_type</span>(<span class="ruby-identifier">file_name</span>)
|
751
|
+
189: <span class="ruby-identifier">mime_type</span> = <span class="ruby-constant">MIME</span><span class="ruby-operator">::</span><span class="ruby-constant">Types</span>.<span class="ruby-identifier">type_for</span>(<span class="ruby-identifier">file_name</span>)[<span class="ruby-value">0</span>]
|
752
|
+
190: <span class="ruby-identifier">mime_type</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">MIME</span><span class="ruby-operator">::</span><span class="ruby-constant">Types</span>[<span class="ruby-value str">'text/plain'</span>][<span class="ruby-value">0</span>]
|
753
|
+
191: <span class="ruby-identifier">mime_type</span>
|
754
|
+
192: <span class="ruby-keyword kw">end</span>
|
751
755
|
</pre>
|
752
756
|
</div>
|
753
757
|
</div>
|
@@ -764,8 +768,15 @@ guessed, "text/plain" is used.
|
|
764
768
|
|
765
769
|
<div class="method-description">
|
766
770
|
<p>
|
767
|
-
Add metadata headers, correctly prefixing them first.
|
771
|
+
Add metadata headers, correctly prefixing them first, e.g. you might do <a
|
772
|
+
href="S33r.html#M000045">metadata_headers</a>({}, {‘myname’
|
773
|
+
=> ‘elliot’, ‘myage’ => 36}) to add two
|
774
|
+
headers to the request:
|
768
775
|
</p>
|
776
|
+
<pre>
|
777
|
+
x-amz-meta-myname: elliot
|
778
|
+
x-amz-meta-myage: 36
|
779
|
+
</pre>
|
769
780
|
<p>
|
770
781
|
Returns headers with the metadata headers appended.
|
771
782
|
</p>
|
@@ -773,13 +784,13 @@ Returns headers with the metadata headers appended.
|
|
773
784
|
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
774
785
|
<div class="method-source-code" id="M000045-source">
|
775
786
|
<pre>
|
776
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
787
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 168</span>
|
788
|
+
168: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">metadata_headers</span>(<span class="ruby-identifier">headers</span>, <span class="ruby-identifier">metadata</span>={})
|
789
|
+
169: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">metadata</span>.<span class="ruby-identifier">empty?</span>
|
790
|
+
170: <span class="ruby-identifier">metadata</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">headers</span>[<span class="ruby-constant">METADATA_PREFIX</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span> }
|
791
|
+
171: <span class="ruby-keyword kw">end</span>
|
792
|
+
172: <span class="ruby-identifier">headers</span>
|
793
|
+
173: <span class="ruby-keyword kw">end</span>
|
783
794
|
</pre>
|
784
795
|
</div>
|
785
796
|
</div>
|
@@ -802,10 +813,10 @@ Return the location of the ACL for a resource.
|
|
802
813
|
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
803
814
|
<div class="method-source-code" id="M000050-source">
|
804
815
|
<pre>
|
805
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
806
|
-
|
807
|
-
|
808
|
-
|
816
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 212</span>
|
817
|
+
212: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_acl_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
|
818
|
+
213: <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">"?acl"</span>
|
819
|
+
214: <span class="ruby-keyword kw">end</span>
|
809
820
|
</pre>
|
810
821
|
</div>
|
811
822
|
</div>
|
@@ -834,20 +845,20 @@ suitable value from a string.
|
|
834
845
|
onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
|
835
846
|
<div class="method-source-code" id="M000055-source">
|
836
847
|
<pre>
|
837
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
848
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 243</span>
|
849
|
+
243: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_authenticated_url</span>(<span class="ruby-identifier">aws_access_key</span>, <span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>,
|
850
|
+
244: <span class="ruby-identifier">expires</span>=<span class="ruby-keyword kw">nil</span>)
|
851
|
+
245: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
|
852
|
+
246: <span class="ruby-identifier">expires</span> = <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">parse_expiry</span>(<span class="ruby-identifier">expires</span>)
|
853
|
+
247:
|
854
|
+
248: <span class="ruby-identifier">canonical_string</span> = <span class="ruby-identifier">generate_canonical_string</span>(<span class="ruby-value str">'GET'</span>, <span class="ruby-identifier">path</span>, {}, <span class="ruby-identifier">expires</span>)
|
855
|
+
249: <span class="ruby-identifier">signature</span> = <span class="ruby-identifier">generate_signature</span>(<span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">canonical_string</span>)
|
856
|
+
250:
|
857
|
+
251: <span class="ruby-identifier">querystring</span> = <span class="ruby-identifier">generate_querystring</span>({ <span class="ruby-value str">'Signature'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">signature</span>, <span class="ruby-value str">'Expires'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">expires</span>,
|
858
|
+
252: <span class="ruby-value str">'AWSAccessKeyId'</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">aws_access_key</span> })
|
859
|
+
253:
|
860
|
+
254: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">path</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">querystring</span>
|
861
|
+
255: <span class="ruby-keyword kw">end</span>
|
851
862
|
</pre>
|
852
863
|
</div>
|
853
864
|
</div>
|
@@ -870,10 +881,10 @@ Return the location of the logging definition for a resource.
|
|
870
881
|
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
871
882
|
<div class="method-source-code" id="M000051-source">
|
872
883
|
<pre>
|
873
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
874
|
-
|
875
|
-
|
876
|
-
|
884
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 217</span>
|
885
|
+
217: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_logging_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
|
886
|
+
218: <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">"?logging"</span>
|
887
|
+
219: <span class="ruby-keyword kw">end</span>
|
877
888
|
</pre>
|
878
889
|
</div>
|
879
890
|
</div>
|
@@ -896,12 +907,12 @@ Returns the path for this bucket and key.
|
|
896
907
|
onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
|
897
908
|
<div class="method-source-code" id="M000054-source">
|
898
909
|
<pre>
|
899
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
910
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 233</span>
|
911
|
+
233: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
|
912
|
+
234: <span class="ruby-identifier">path</span> = <span class="ruby-value str">'/'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">bucket_name</span>
|
913
|
+
235: <span class="ruby-identifier">path</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">'/'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">resource_key</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-value str">''</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">resource_key</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">resource_key</span>.<span class="ruby-identifier">nil?</span>
|
914
|
+
236: <span class="ruby-identifier">path</span>
|
915
|
+
237: <span class="ruby-keyword kw">end</span>
|
905
916
|
</pre>
|
906
917
|
</div>
|
907
918
|
</div>
|
@@ -924,11 +935,11 @@ Public readable URL for a bucket and resource.
|
|
924
935
|
onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
|
925
936
|
<div class="method-source-code" id="M000053-source">
|
926
937
|
<pre>
|
927
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
938
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 227</span>
|
939
|
+
227: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_public_url</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>=<span class="ruby-value str">''</span>)
|
940
|
+
228: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
|
941
|
+
229: <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">path</span>)
|
942
|
+
230: <span class="ruby-keyword kw">end</span>
|
932
943
|
</pre>
|
933
944
|
</div>
|
934
945
|
</div>
|
@@ -951,10 +962,10 @@ Prepend scheme and HOST to path.
|
|
951
962
|
onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
|
952
963
|
<div class="method-source-code" id="M000052-source">
|
953
964
|
<pre>
|
954
|
-
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line
|
955
|
-
|
956
|
-
|
957
|
-
|
965
|
+
<span class="ruby-comment cmt"># File lib/s33r/core.rb, line 222</span>
|
966
|
+
222: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">path</span>)
|
967
|
+
223: <span class="ruby-value str">"http://"</span> <span class="ruby-operator">+</span> <span class="ruby-constant">HOST</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">path</span>
|
968
|
+
224: <span class="ruby-keyword kw">end</span>
|
958
969
|
</pre>
|
959
970
|
</div>
|
960
971
|
</div>
|