paperclip-aws 1.2.0 → 1.3.0
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/Gemfile +1 -1
- data/README.md +31 -7
- data/VERSION +1 -1
- data/lib/paperclip-aws.rb +34 -18
- data/paperclip-aws.gemspec +9 -11
- metadata +16 -18
- data/test/helper.rb +0 -18
- data/test/test_papepclip-aws.rb +0 -7
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# Storage module to official 'aws-sdk' gem for Amazon S3 #
|
2
2
|
|
3
|
-
'paperclip-aws' is a full featured storage module that supports all S3 locations (
|
3
|
+
'paperclip-aws' is a full featured storage module that supports all S3 locations (American, European and Japanese) without any additional hacking.
|
4
4
|
|
5
5
|
## Features ##
|
6
6
|
|
7
7
|
* supports US, European and Japanese S3 instances;
|
8
8
|
* supports both `http` and `https` urls;
|
9
9
|
* supports expiring urls;
|
10
|
+
* supports different permissions for each Paperclip style;
|
10
11
|
* can generate urls for `read`, `write` и `delete` operations;
|
11
12
|
* correctly sets content-type of uploaded files;
|
12
13
|
* **supports amazon server side encryption** (thanks to [pvertenten](https://github.com/pvertenten));
|
@@ -14,8 +15,8 @@
|
|
14
15
|
|
15
16
|
## Requirements ##
|
16
17
|
|
17
|
-
* [paperclip][0] ~> 2.
|
18
|
-
* [aws-sdk][1] >= 1.2.
|
18
|
+
* [paperclip][0] ~> 2.4
|
19
|
+
* [aws-sdk][1] >= 1.2.0
|
19
20
|
|
20
21
|
## Installation ##
|
21
22
|
|
@@ -41,10 +42,15 @@ After this add 'paperclip-aws' to your `Gemfile` or `environment.rb`
|
|
41
42
|
:secret_access_key => self.s3_config['secret_access_key'],
|
42
43
|
:endpoint => self.s3_config['endpoint']
|
43
44
|
},
|
44
|
-
:
|
45
|
+
:bucket => self.s3_config['bucket'],
|
45
46
|
:s3_host_alias => self.s3_config['s3_host_alias'],
|
46
|
-
:
|
47
|
+
:s3_permissions => :public_read,
|
47
48
|
:s3_protocol => 'http',
|
49
|
+
:s3_options => {
|
50
|
+
:sse => 'AES256',
|
51
|
+
:storage_class => :reduced_redundancy
|
52
|
+
},
|
53
|
+
|
48
54
|
:path => "company_documents/:id/:style/:data_file_name"
|
49
55
|
end
|
50
56
|
|
@@ -55,7 +61,7 @@ Endpoint where your bucket is located. Default is `'s3.amazonaws.com'` which is
|
|
55
61
|
|
56
62
|
You can find full list of endpoints and regions [here](http://aws.amazon.com/articles/3912#s3)
|
57
63
|
|
58
|
-
### :
|
64
|
+
### :s3_permissions ###
|
59
65
|
Sets permissions to your objects. Values are:
|
60
66
|
|
61
67
|
:private
|
@@ -64,10 +70,28 @@ Sets permissions to your objects. Values are:
|
|
64
70
|
:authenticated_read
|
65
71
|
:bucket_owner_read
|
66
72
|
:bucket_owner_full_control
|
73
|
+
|
74
|
+
You can setup permnissions globally for object or per style:
|
75
|
+
|
76
|
+
:s3_permissions => :public_read
|
77
|
+
|
78
|
+
|
79
|
+
:s3_permissions => {
|
80
|
+
:thumb => :public_read,
|
81
|
+
:medium => :authenticated_read,
|
82
|
+
:default => :authenticated_read
|
83
|
+
}
|
67
84
|
|
68
85
|
### :s3_protocol ###
|
69
86
|
Default protocol to use: `'http'` or `'https'`.
|
70
87
|
|
88
|
+
### :s3_options ###
|
89
|
+
Hash of additional options. Available options are:
|
90
|
+
|
91
|
+
* `:sse` – `'AES256'` (the only available encryption now)
|
92
|
+
* `:storage_class` – `:standard` (default) or `:reduced_redundancy`
|
93
|
+
|
94
|
+
|
71
95
|
## Get your data
|
72
96
|
|
73
97
|
'paperclip-aws' redefines Paperclip `url` method to get object URL.
|
@@ -75,7 +99,7 @@ Default protocol to use: `'http'` or `'https'`.
|
|
75
99
|
def url(style=default_style, options={})
|
76
100
|
end
|
77
101
|
|
78
|
-
Supported options are
|
102
|
+
Supported options are:
|
79
103
|
|
80
104
|
* `:protocol` — `'http'` or `'https'`
|
81
105
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/paperclip-aws.rb
CHANGED
@@ -12,27 +12,33 @@ module Paperclip
|
|
12
12
|
e.message << " (You may need to install the aws-sdk gem)"
|
13
13
|
raise e
|
14
14
|
end unless defined?(AWS)
|
15
|
-
|
16
|
-
base.instance_eval do
|
17
|
-
@s3_credentials
|
15
|
+
|
16
|
+
base.instance_eval do
|
17
|
+
@s3_credentials = parse_credentials(@options.s3_credentials)
|
18
|
+
@s3_permissions = set_permissions(@options.s3_permissions)
|
19
|
+
@s3_protocol = @options.s3_protocol ||
|
20
|
+
Proc.new do |style, attachment|
|
21
|
+
permission = (@s3_permissions[style.to_sym] || @s3_permissions[:default])
|
22
|
+
permission = permission.call(attachment, style) if permission.is_a?(Proc)
|
23
|
+
(permission == :public_read) ? 'http' : 'https'
|
24
|
+
end
|
25
|
+
@s3_headers = @options.s3_headers || {}
|
18
26
|
|
19
|
-
|
20
|
-
@s3_bucket = @options[:s3_bucket] || @s3_credentials[:bucket]
|
27
|
+
@s3_bucket = @options.bucket
|
21
28
|
@s3_bucket = @s3_bucket.call(self) if @s3_bucket.is_a?(Proc)
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
@s3_sse
|
26
|
-
|
30
|
+
@s3_options = @options.s3_options || {}
|
31
|
+
# setup Amazon Server Side encryption
|
32
|
+
@s3_sse = @s3_options[:sse] || false
|
27
33
|
# choose what storage class we use, 'standard' or 'reduced_redundancy'
|
28
|
-
@s3_storage_class = @
|
34
|
+
@s3_storage_class = @s3_options[:storage_class] || :standard
|
29
35
|
|
30
|
-
@
|
31
|
-
|
32
|
-
@s3_host_alias = @options
|
36
|
+
@s3_endpoint = @s3_credentials[:endpoint] || 's3.amazonaws.com'
|
37
|
+
|
38
|
+
@s3_host_alias = @options.s3_host_alias
|
33
39
|
@s3_host_alias = @s3_host_alias.call(self) if @s3_host_alias.is_a?(Proc)
|
34
40
|
|
35
|
-
|
41
|
+
|
36
42
|
|
37
43
|
@s3 = AWS::S3.new(
|
38
44
|
:access_key_id => @s3_credentials[:access_key_id],
|
@@ -40,6 +46,7 @@ module Paperclip
|
|
40
46
|
:s3_endpoint => @s3_endpoint
|
41
47
|
)
|
42
48
|
end
|
49
|
+
|
43
50
|
end
|
44
51
|
|
45
52
|
def url(style=default_style, options={})
|
@@ -54,7 +61,7 @@ module Paperclip
|
|
54
61
|
:action => :read
|
55
62
|
})
|
56
63
|
secure = ( self.choose_protocol(options) == 'https' )
|
57
|
-
@s3.buckets[@s3_bucket].objects[path(style)].url_for(options[:action], { :secure => secure, :expires => options[:expires] }).to_s
|
64
|
+
@s3.buckets[@s3_bucket].objects[path(style).gsub(%r{^/}, "")].url_for(options[:action], { :secure => secure, :expires => options[:expires] }).to_s
|
58
65
|
else
|
59
66
|
if @s3_host_alias.present?
|
60
67
|
"#{choose_protocol(options)}://#{@s3_host_alias}/#{path(style).gsub(%r{^/}, "")}"
|
@@ -73,6 +80,15 @@ module Paperclip
|
|
73
80
|
env = Object.const_defined?(:Rails) ? Rails.env : nil
|
74
81
|
(creds[env] || creds).symbolize_keys
|
75
82
|
end
|
83
|
+
|
84
|
+
def set_permissions permissions
|
85
|
+
if permissions.is_a?(Hash)
|
86
|
+
permissions[:default] = permissions[:default] || :public_read
|
87
|
+
else
|
88
|
+
permissions = { :default => permissions || :public_read }
|
89
|
+
end
|
90
|
+
permissions
|
91
|
+
end
|
76
92
|
|
77
93
|
def exists?(style = default_style)
|
78
94
|
if path(style).nil? || path(style).to_s.strip == ""
|
@@ -118,10 +134,10 @@ module Paperclip
|
|
118
134
|
|
119
135
|
@s3.buckets[@s3_bucket].objects[path(style)].write(
|
120
136
|
file,
|
121
|
-
:acl => @
|
122
|
-
:storage_class => @s3_storage_class,
|
137
|
+
:acl => @s3_permissions[:style.to_sym] || @s3_permissions[:default],
|
138
|
+
:storage_class => @s3_storage_class.to_sym,
|
123
139
|
:content_type => file.content_type,
|
124
|
-
:server_side_encryption => @s3_sse
|
140
|
+
:server_side_encryption => @s3_sse.to_s
|
125
141
|
)
|
126
142
|
rescue AWS::S3::Errors::NoSuchBucket => e
|
127
143
|
create_bucket
|
data/paperclip-aws.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.
|
7
|
+
s.name = %q{paperclip-aws}
|
8
|
+
s.version = "1.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Igor Alexandrov"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = %q{2011-11-11}
|
13
|
+
s.description = %q{'paperclip-aws' is a full featured storage module that supports all S3 locations (US, European and Tokio) without any additional hacking.}
|
14
|
+
s.email = %q{igor.alexandrov@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README.md"
|
@@ -25,15 +25,13 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"lib/paperclip-aws.rb",
|
28
|
-
"paperclip-aws.gemspec"
|
29
|
-
"test/helper.rb",
|
30
|
-
"test/test_papepclip-aws.rb"
|
28
|
+
"paperclip-aws.gemspec"
|
31
29
|
]
|
32
|
-
s.homepage =
|
30
|
+
s.homepage = %q{http://github.com/igor-alexandrov/paperclip-aws}
|
33
31
|
s.licenses = ["MIT"]
|
34
32
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version =
|
36
|
-
s.summary =
|
33
|
+
s.rubygems_version = %q{1.7.2}
|
34
|
+
s.summary = %q{Storage module to official 'aws-sdk' gem for Amazon S3}
|
37
35
|
|
38
36
|
if s.respond_to? :specification_version then
|
39
37
|
s.specification_version = 3
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-11 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: paperclip
|
16
|
-
requirement: &
|
16
|
+
requirement: &70175097366720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70175097366720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: aws-sdk
|
27
|
-
requirement: &
|
27
|
+
requirement: &70175097362700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70175097362700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: shoulda
|
38
|
-
requirement: &
|
38
|
+
requirement: &70175096884900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70175096884900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70175096882680 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70175096882680
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &70175096882000 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.6.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70175096882000
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &70175096880660 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70175096880660
|
80
80
|
description: ! '''paperclip-aws'' is a full featured storage module that supports
|
81
81
|
all S3 locations (US, European and Tokio) without any additional hacking.'
|
82
82
|
email: igor.alexandrov@gmail.com
|
@@ -95,8 +95,6 @@ files:
|
|
95
95
|
- VERSION
|
96
96
|
- lib/paperclip-aws.rb
|
97
97
|
- paperclip-aws.gemspec
|
98
|
-
- test/helper.rb
|
99
|
-
- test/test_papepclip-aws.rb
|
100
98
|
homepage: http://github.com/igor-alexandrov/paperclip-aws
|
101
99
|
licenses:
|
102
100
|
- MIT
|
@@ -112,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
110
|
version: '0'
|
113
111
|
segments:
|
114
112
|
- 0
|
115
|
-
hash: -
|
113
|
+
hash: -3697909920406882687
|
116
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
115
|
none: false
|
118
116
|
requirements:
|
@@ -121,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
119
|
version: '0'
|
122
120
|
requirements: []
|
123
121
|
rubyforge_project:
|
124
|
-
rubygems_version: 1.
|
122
|
+
rubygems_version: 1.7.2
|
125
123
|
signing_key:
|
126
124
|
specification_version: 3
|
127
125
|
summary: Storage module to official 'aws-sdk' gem for Amazon S3
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'paperclip-aws'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|
data/test/test_papepclip-aws.rb
DELETED