policia 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,51 @@
1
+ = Policia
2
+
3
+ == Information
4
+
5
+ Policia is a simple generator of Amazon S3 policy document signatures for use in authenticating POST/REST/API uploads to you S3 buckets.
6
+
7
+ For more information on Amazon S3 Policy Documents {see the their documentation}[http://docs.amazonwebservices.com/AmazonS3/latest/dev/S3_Authentication.html].
8
+
9
+ == Installation
10
+
11
+ Install the latest stable release:
12
+
13
+ [sudo] gem install policia
14
+
15
+ Or if using bundler add the following to your Gemfile:
16
+
17
+ gem 'policia'
18
+
19
+
20
+ == Example use
21
+
22
+ An quick example, note to at least change YOUR-S3-BUCKET-NAME, YOUR-S3-ACCESS-KEY and YOUR-S3-SECRET-KEY
23
+
24
+ @document = { "expiration" => "2012-12-12T00:00:00Z",
25
+ "conditions" => [ {"bucket" => "YOUR-S3-BUCKET-NAME"},
26
+ ["starts-with", "$key", ""],
27
+ {"acl" => "public-read"},
28
+ {"success_action_redirect" => "YOUR-CHOICE-OF-CALLBACK"},
29
+ ["starts-with", "$Content-Type", "image"] ] }
30
+
31
+ @policy_document = Policia.new("YOUR-S3-SECRET-KEY", @document)
32
+
33
+ Then in your form (i.e. using ERB template)
34
+
35
+ <form action="http://YOUR-S3-BUCKET-NAME.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
36
+ <input type="hidden" name="key" value="${filename}">
37
+ <input type="hidden" name="AWSAccessKeyId" value="YOUR-S3-ACCESS-KEY">
38
+ <input type="hidden" name="acl" value="public-read">
39
+ <input type="hidden" name="success_action_redirect" value="YOUR-CHOICE-OF-CALLBACK">
40
+
41
+ <input type="hidden" name="policy" value="<%= @policy_document.policy %>">
42
+ <input type="hidden" name="signature" value="<%= @policy_document.signature %>">
43
+
44
+ <input type="hidden" name="Content-Type" value="image/jpeg">
45
+ <!-- Include any additional input fields here -->
46
+
47
+ File to upload to S3: <input name="file" type="file"> <input type="submit">
48
+ </form>
49
+
50
+
51
+ The example above will post your file to your amazon s3 bucket root and then return to your given callback with parameters containing file info.
@@ -10,10 +10,10 @@ class Policia
10
10
  end
11
11
 
12
12
  def policy
13
- Base64.encode64(@document).gsub(/\n|\r/, '')
13
+ @policy ||= Base64.encode64(@document).gsub(/\n|\r/, '')
14
14
  end
15
15
 
16
16
  def signature
17
- Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret, policy)).gsub(/\n| |\r/, '')
17
+ @signature ||= Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret, policy)).gsub(/\n| |\r/, '')
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module Policia
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -8,9 +8,9 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Antony Sastre"]
10
10
  s.email = ["antony@adotapart.com"]
11
- s.homepage = ""
11
+ s.homepage = "http://github.com/antonysastre/policia"
12
12
  s.summary = %q{Policia is a simple Amazon S3 Policy Document Signature generator.}
13
- s.description = %q{Amazons uses a policy document protocol to allow things like regular forms and resful api to upload files to your buckets. The policy document can be a bit of a hassle to get encoded into a signature - this gem makes it easier. It gives you the choice of providing the document as a nice good'ol ruby Hash. Currently only supports ruby 1.9}
13
+ s.description = %q{Amazon uses a policy document protocol to allow i.e. regular forms to upload files to your S3 buckets. The policy document can be a bit of a hassle to manage and encode into the nescessary signature - this gem aims to make it easier. Currently only supports ruby 1.9.}
14
14
 
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: policia
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Antony Sastre
@@ -14,7 +14,7 @@ date: 2011-05-05 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
- description: Amazons uses a policy document protocol to allow things like regular forms and resful api to upload files to your buckets. The policy document can be a bit of a hassle to get encoded into a signature - this gem makes it easier. It gives you the choice of providing the document as a nice good'ol ruby Hash. Currently only supports ruby 1.9
17
+ description: Amazon uses a policy document protocol to allow i.e. regular forms to upload files to your S3 buckets. The policy document can be a bit of a hassle to manage and encode into the nescessary signature - this gem aims to make it easier. Currently only supports ruby 1.9.
18
18
  email:
19
19
  - antony@adotapart.com
20
20
  executables: []
@@ -26,6 +26,7 @@ extra_rdoc_files: []
26
26
  files:
27
27
  - .gitignore
28
28
  - Gemfile
29
+ - README.rdoc
29
30
  - Rakefile
30
31
  - example/policia_application.rb
31
32
  - example/views/index.erb
@@ -35,7 +36,7 @@ files:
35
36
  - policia.gemspec
36
37
  - test/policia_test.rb
37
38
  has_rdoc: true
38
- homepage: ""
39
+ homepage: http://github.com/antonysastre/policia
39
40
  licenses: []
40
41
 
41
42
  post_install_message:
@@ -58,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  requirements: []
59
60
 
60
61
  rubyforge_project:
61
- rubygems_version: 1.6.2
62
+ rubygems_version: 1.5.2
62
63
  signing_key:
63
64
  specification_version: 3
64
65
  summary: Policia is a simple Amazon S3 Policy Document Signature generator.