anaconda 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +4 -1
- data/lib/anaconda.rb +1 -0
- data/lib/anaconda/form_builder_helpers.rb +1 -80
- data/lib/anaconda/s3_uploader.rb +80 -0
- data/lib/anaconda/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a362cf9690829d3184624cbf62dc7a0b91cc555
|
4
|
+
data.tar.gz: e3fed3967d2f2c8eb7adbee4a64a1f2fa35ecd2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc25838f832c4fe24971d5c054dd8da3923781ee02ffc0f3f71415a636ca37646b257697970f7764922d2e11722ca1ab042b5337acdd78abcae6302c87536be8
|
7
|
+
data.tar.gz: fe04aefa077d7d1da356b7a8fdbd70dbb304321101ed542e5b779b1939e67a738398010942bf5ea37ab1d1b51cb8863ba28e28e2f89d1d7ea42d59fbe90fd705
|
data/README.markdown
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Dead simple direct-to-s3 file uploading for your rails app.
|
4
4
|
|
5
|
-
Current Version: 1.0.
|
5
|
+
Current Version: 1.0.2
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -202,6 +202,9 @@ If you return false to the following events it will prevent the default behavior
|
|
202
202
|
From version 1.0.0 on we have used [Semantic Versioning](http://semver.org/).
|
203
203
|
|
204
204
|
## Changelog
|
205
|
+
* 1.0.2
|
206
|
+
* Refactor S3Uploader into it's own class so it can be used outside of the form helper
|
207
|
+
|
205
208
|
* 1.0.1
|
206
209
|
* Use OpenSSL::Digest instead of deprecated OpenSSL::Digest::Digest.
|
207
210
|
|
data/lib/anaconda.rb
CHANGED
@@ -23,7 +23,7 @@ module Anaconda
|
|
23
23
|
options[:base_key] = instance.send(options[:base_key].to_s) if options[:base_key].kind_of? Symbol
|
24
24
|
end
|
25
25
|
|
26
|
-
uploader = S3Uploader.new(options)
|
26
|
+
uploader = Anaconda::S3Uploader.new(options)
|
27
27
|
output += self.input_field "file", name: "file", id: element_id, as: :file, data: {url: uploader.url, form_data: uploader.fields.to_json, media_types: Anaconda.js_file_types}
|
28
28
|
end
|
29
29
|
|
@@ -64,84 +64,5 @@ module Anaconda
|
|
64
64
|
|
65
65
|
output.html_safe
|
66
66
|
end
|
67
|
-
|
68
|
-
class S3Uploader
|
69
|
-
def initialize(options)
|
70
|
-
@options = options.reverse_merge(
|
71
|
-
id: "fileupload",
|
72
|
-
aws_access_key_id: Anaconda.aws[:aws_access_key],
|
73
|
-
aws_secret_access_key: Anaconda.aws[:aws_secret_key],
|
74
|
-
bucket: Anaconda.aws[:aws_bucket],
|
75
|
-
acl: "public-read",
|
76
|
-
expiration: 10.hours.from_now.utc,
|
77
|
-
max_file_size: 500.megabytes,
|
78
|
-
as: "file"
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
def form_options
|
83
|
-
{
|
84
|
-
id: @options[:id],
|
85
|
-
method: "post",
|
86
|
-
authenticity_token: false,
|
87
|
-
multipart: true,
|
88
|
-
data: {
|
89
|
-
post: @options[:post],
|
90
|
-
as: @options[:as],
|
91
|
-
base_key: base_key
|
92
|
-
}
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
def fields
|
97
|
-
{
|
98
|
-
:key => key,
|
99
|
-
:acl => @options[:acl],
|
100
|
-
"Content-Type" => "application/octet-stream",
|
101
|
-
:policy => policy,
|
102
|
-
:signature => signature,
|
103
|
-
"AWSAccessKeyId" => @options[:aws_access_key_id],
|
104
|
-
}
|
105
|
-
end
|
106
|
-
|
107
|
-
def key
|
108
|
-
@key ||= "#{base_key}/${filename}"
|
109
|
-
end
|
110
|
-
|
111
|
-
def base_key
|
112
|
-
@options[:base_key]
|
113
|
-
end
|
114
|
-
|
115
|
-
def url
|
116
|
-
"https://s3.amazonaws.com/#{@options[:bucket]}/"
|
117
|
-
end
|
118
|
-
|
119
|
-
def policy
|
120
|
-
Base64.encode64(policy_data.to_json).gsub("\n", "")
|
121
|
-
end
|
122
|
-
|
123
|
-
def policy_data
|
124
|
-
{
|
125
|
-
expiration: @options[:expiration],
|
126
|
-
conditions: [
|
127
|
-
#["starts-with", "$utf8", ""],
|
128
|
-
["starts-with", "$key", base_key],
|
129
|
-
["starts-with", "$Content-Type", ""],
|
130
|
-
["content-length-range", 1, @options[:max_file_size]],
|
131
|
-
{bucket: @options[:bucket]},
|
132
|
-
{acl: @options[:acl]}
|
133
|
-
]
|
134
|
-
}
|
135
|
-
end
|
136
|
-
|
137
|
-
def signature
|
138
|
-
Base64.encode64(
|
139
|
-
OpenSSL::HMAC.digest(
|
140
|
-
OpenSSL::Digest.new('sha1'),
|
141
|
-
@options[:aws_secret_access_key], policy
|
142
|
-
)
|
143
|
-
).gsub("\n", "")
|
144
|
-
end
|
145
|
-
end
|
146
67
|
end
|
147
68
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Anaconda
|
2
|
+
class S3Uploader
|
3
|
+
def initialize(options)
|
4
|
+
@options = options.reverse_merge(
|
5
|
+
id: "fileupload",
|
6
|
+
aws_access_key_id: Anaconda.aws[:aws_access_key],
|
7
|
+
aws_secret_access_key: Anaconda.aws[:aws_secret_key],
|
8
|
+
bucket: Anaconda.aws[:aws_bucket],
|
9
|
+
acl: "public-read",
|
10
|
+
expiration: 10.hours.from_now.utc,
|
11
|
+
max_file_size: 500.megabytes,
|
12
|
+
as: "file"
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def form_options
|
17
|
+
{
|
18
|
+
id: @options[:id],
|
19
|
+
method: "post",
|
20
|
+
authenticity_token: false,
|
21
|
+
multipart: true,
|
22
|
+
data: {
|
23
|
+
post: @options[:post],
|
24
|
+
as: @options[:as],
|
25
|
+
base_key: base_key
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def fields
|
31
|
+
{
|
32
|
+
:key => key,
|
33
|
+
:acl => @options[:acl],
|
34
|
+
"Content-Type" => "application/octet-stream",
|
35
|
+
:policy => policy,
|
36
|
+
:signature => signature,
|
37
|
+
"AWSAccessKeyId" => @options[:aws_access_key_id],
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def key
|
42
|
+
@key ||= "#{base_key}/${filename}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def base_key
|
46
|
+
@options[:base_key]
|
47
|
+
end
|
48
|
+
|
49
|
+
def url
|
50
|
+
"https://s3.amazonaws.com/#{@options[:bucket]}/"
|
51
|
+
end
|
52
|
+
|
53
|
+
def policy
|
54
|
+
Base64.encode64(policy_data.to_json).gsub("\n", "")
|
55
|
+
end
|
56
|
+
|
57
|
+
def policy_data
|
58
|
+
{
|
59
|
+
expiration: @options[:expiration],
|
60
|
+
conditions: [
|
61
|
+
#["starts-with", "$utf8", ""],
|
62
|
+
["starts-with", "$key", base_key],
|
63
|
+
["starts-with", "$Content-Type", ""],
|
64
|
+
["content-length-range", 1, @options[:max_file_size]],
|
65
|
+
{bucket: @options[:bucket]},
|
66
|
+
{acl: @options[:acl]}
|
67
|
+
]
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def signature
|
72
|
+
Base64.encode64(
|
73
|
+
OpenSSL::HMAC.digest(
|
74
|
+
OpenSSL::Digest.new('sha1'),
|
75
|
+
@options[:aws_secret_access_key], policy
|
76
|
+
)
|
77
|
+
).gsub("\n", "")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/anaconda/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anaconda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McFadden
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/anaconda/errors.rb
|
64
64
|
- lib/anaconda/form_builder_helpers.rb
|
65
65
|
- lib/anaconda/railtie.rb
|
66
|
+
- lib/anaconda/s3_uploader.rb
|
66
67
|
- lib/anaconda/version.rb
|
67
68
|
- lib/generators/anaconda/install_generator.rb
|
68
69
|
- lib/generators/anaconda/migration_generator.rb
|