Class: S3loginProvider
- Inherits:
-
Object
- Object
- S3loginProvider
- Defined in:
- lib/wheels/s3login_provider.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#acl ⇒ Object
Returns the value of attribute acl.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
-
#key ⇒ Object
Returns the value of attribute key.
-
#max_filesize ⇒ Object
Returns the value of attribute max_filesize.
-
#policy ⇒ Object
Returns the value of attribute policy.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ S3loginProvider
constructor
A new instance of S3loginProvider.
Constructor Details
#initialize(options = {}) ⇒ S3loginProvider
Returns a new instance of S3loginProvider.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wheels/s3login_provider.rb', line 5 def initialize( = {}) filename = "#{Rails.root}/config/amazon_s3.yml" config = YAML.load_file(filename) self.bucket = config[ENV["RAILS_ENV"]]['bucket_name'] self.access_key_id = config[ENV["RAILS_ENV"]]['access_key_id'] self.secret_access_key = config[ENV["RAILS_ENV"]]['secret_access_key'] self.key = [:key] || '' self.content_type = [:content_type] || '' self.acl = [:acl] || 'public-read' self.expiration_date = ([:expiration_date] || 10.hours).from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z') self.max_filesize = [:max_filesize] || 500.megabyte self.policy = Base64.encode64( "{'expiration': '#{expiration_date}', 'conditions': [ {'bucket': '#{bucket}'}, ['starts-with', '$key', '#{key}'], {'acl': '#{acl}'}, {'success_action_status': '201'}, ['content-length-range', 0, #{max_filesize}], ['starts-with', '$Filename', ''], ['starts-with', '#{content_type}', ''] ] }").gsub(/\n|\r/, '') self.signature = Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::Digest.new('sha1'), self.secret_access_key, self.policy)).gsub("\n","") self.form_fields = %( <form action="https://#{bucket}.s3.amazonaws.com/" method="post" enctype="multipart/form-data" id="upload-form"> <input type="hidden" name="key" value="#{key}/${filename}"> <input type="hidden" name="AWSAccessKeyId" value="#{access_key_id}"> <input type="hidden" name="acl" value="#{acl}"> <input type="hidden" name="policy" value="#{policy}"> <input type="hidden" name="signature" value="#{signature}"> <input type="hidden" name="success_action_status" value="201"> <input type="hidden" name="Content-Type" value="#{content_type}"> <input name="file" type="file" id="" /> <input name="submit" value="Upload" type="submit" id="upload_button" /> </form> ) end |
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def access_key_id @access_key_id end |
#acl ⇒ Object
Returns the value of attribute acl.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def acl @acl end |
#bucket ⇒ Object
Returns the value of attribute bucket.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def bucket @bucket end |
#content_type ⇒ Object
Returns the value of attribute content_type.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def content_type @content_type end |
#expiration_date ⇒ Object
Returns the value of attribute expiration_date.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def expiration_date @expiration_date end |
#key ⇒ Object
Returns the value of attribute key.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def key @key end |
#max_filesize ⇒ Object
Returns the value of attribute max_filesize.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def max_filesize @max_filesize end |
#policy ⇒ Object
Returns the value of attribute policy.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def policy @policy end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def secret_access_key @secret_access_key end |
#signature ⇒ Object
Returns the value of attribute signature.
2 3 4 |
# File 'lib/wheels/s3login_provider.rb', line 2 def signature @signature end |