policia 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/example/policia_application.rb +18 -0
- data/example/views/index.erb +23 -0
- data/example/views/process.erb +2 -0
- data/lib/policia/version.rb +3 -0
- data/lib/policia.rb +19 -0
- data/policia.gemspec +19 -0
- data/test/policia_test.rb +32 -0
- metadata +66 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
require 'sinatra'
|
3
|
+
require 'policia'
|
4
|
+
|
5
|
+
get '/' do
|
6
|
+
document = { "expiration" => "2012-12-12T00:00:00Z",
|
7
|
+
"conditions" => [ {"bucket" => "YOUR-BUCKET-NAME"},
|
8
|
+
["starts-with", "$key", ""],
|
9
|
+
{"acl" => "public-read"},
|
10
|
+
{"success_action_redirect" => "http://localhost:4567/process"},
|
11
|
+
["starts-with", "$Content-Type", "image"], ] }
|
12
|
+
@policy_document = Policia.new("YOUR-S3-SECRET-KEY", document)
|
13
|
+
erb :index
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/process' do
|
17
|
+
erb :process
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>S3 POST Form</title>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
5
|
+
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<form action="http://adotapart-eu.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
|
9
|
+
<input type="hidden" name="key" value="${filename}">
|
10
|
+
<input type="hidden" name="AWSAccessKeyId" value="AKIAJGANQFDFTVMK5STQ">
|
11
|
+
<input type="hidden" name="acl" value="public-read">
|
12
|
+
<input type="hidden" name="success_action_redirect" value="http://localhost:4567/process">
|
13
|
+
<input type="hidden" name="policy" value="<%= @policy_document.policy %>">
|
14
|
+
<input type="hidden" name="signature" value="<%= @policy_document.signature %>">
|
15
|
+
<input type="hidden" name="Content-Type" value="image/jpeg">
|
16
|
+
<!-- Include any additional input fields here -->
|
17
|
+
|
18
|
+
File to upload to S3:
|
19
|
+
<input name="file" type="file">
|
20
|
+
<input type="submit">
|
21
|
+
</form>
|
22
|
+
</body>
|
23
|
+
</html>
|
data/lib/policia.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'base64'
|
3
|
+
require 'openssl'
|
4
|
+
require 'digest/sha1'
|
5
|
+
|
6
|
+
class Policia
|
7
|
+
def initialize(secret, document)
|
8
|
+
@document = document.class == Hash ? document.to_json : document
|
9
|
+
@secret = secret
|
10
|
+
end
|
11
|
+
|
12
|
+
def policy
|
13
|
+
Base64.encode64(@document).gsub(/\n|\r/, '')
|
14
|
+
end
|
15
|
+
|
16
|
+
def signature
|
17
|
+
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret, policy)).gsub(/\n| |\r/, '')
|
18
|
+
end
|
19
|
+
end
|
data/policia.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "policia/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "policia"
|
7
|
+
s.version = Policia::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Antony Sastre"]
|
10
|
+
s.email = ["antony@adotapart.com"]
|
11
|
+
s.homepage = ""
|
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}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../lib/policia.rb', File.dirname(__FILE__))
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/spec'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
describe Policia do
|
7
|
+
before do
|
8
|
+
@secret = "uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"
|
9
|
+
@document = { 'expiration' => "2007-12-01T12:00:00.000Z",
|
10
|
+
'conditions' => [
|
11
|
+
{ 'bucket' => "johnsmith" },
|
12
|
+
[ 'starts-with', "$key", "user/eric/" ],
|
13
|
+
{ 'acl' => "public-read" },
|
14
|
+
{ 'success_action_redirect' => "http://johnsmith.s3.amazonaws.com/successful_upload.html"},
|
15
|
+
[ 'starts-with', "$Content-Type", "image/" ],
|
16
|
+
{ 'x-amz-meta-uuid' => "14365123651274" },
|
17
|
+
[ 'starts-with', "$x-amz-meta-tag", ""]
|
18
|
+
] }.to_json
|
19
|
+
@policia = Policia.new(@secret, @document)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "provides a Base64 encoded policy" do
|
23
|
+
@policia.policy.must_equal( Base64.encode64(@document).gsub(/\n|\r/, '') )
|
24
|
+
end
|
25
|
+
|
26
|
+
it "provides a Base64 encoded signature" do
|
27
|
+
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret, @policia.policy)
|
28
|
+
expected_signature = Base64.encode64(hmac).gsub(/\n| |\r/, '')
|
29
|
+
|
30
|
+
@policia.signature.must_equal( expected_signature )
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: policia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Antony Sastre
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-05 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
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
|
18
|
+
email:
|
19
|
+
- antony@adotapart.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- Rakefile
|
30
|
+
- example/policia_application.rb
|
31
|
+
- example/views/index.erb
|
32
|
+
- example/views/process.erb
|
33
|
+
- lib/policia.rb
|
34
|
+
- lib/policia/version.rb
|
35
|
+
- policia.gemspec
|
36
|
+
- test/policia_test.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: ""
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.6.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Policia is a simple Amazon S3 Policy Document Signature generator.
|
65
|
+
test_files:
|
66
|
+
- test/policia_test.rb
|