Class: S3BrowserUploads::FormDefinition
- Inherits:
-
Object
- Object
- S3BrowserUploads::FormDefinition
- Defined in:
- lib/s3_browser_uploads/form_definition.rb
Instance Attribute Summary collapse
-
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#expires ⇒ Object
Returns the value of attribute expires.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#region ⇒ Object
Returns the value of attribute region.
Instance Method Summary collapse
- #add_condition(key, condition) ⇒ Object
- #add_field(key, value) ⇒ Object
- #aws_access_key_id ⇒ Object
- #aws_access_key_id=(value) ⇒ Object
- #aws_session_token ⇒ Object
- #aws_session_token=(value) ⇒ Object
- #bucket ⇒ Object
- #bucket=(value) ⇒ Object
- #encoded_policy ⇒ Object
- #endpoint ⇒ Object
-
#initialize(options = {}) ⇒ FormDefinition
constructor
A new instance of FormDefinition.
- #policy_document ⇒ Object
- #restrict_content_length(range) ⇒ Object
- #signature ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ FormDefinition
Returns a new instance of FormDefinition.
57 58 59 60 61 62 63 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 57 def initialize(={}) @fields = {} @conditions = {} .each {|key, value| public_send("#{key}=", value)} @digest = OpenSSL::Digest::Digest.new('sha1') @hmac = lambda {|data| OpenSSL::HMAC.digest(@digest, @aws_secret_access_key, data)} end |
Instance Attribute Details
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
6 7 8 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 6 def aws_secret_access_key @aws_secret_access_key end |
#conditions ⇒ Object
Returns the value of attribute conditions.
6 7 8 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 6 def conditions @conditions end |
#expires ⇒ Object
Returns the value of attribute expires.
6 7 8 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 6 def expires @expires end |
#fields ⇒ Object
Returns the value of attribute fields.
6 7 8 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 6 def fields @fields end |
#region ⇒ Object
Returns the value of attribute region.
6 7 8 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 6 def region @region end |
Instance Method Details
#add_condition(key, condition) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 41 def add_condition key, condition @conditions[key] = case condition when String then {key => condition} when Hash then [condition.keys.first, "$#{key}", condition.values.first] when Range then [key, condition.begin, condition.end] else raise ArgumentError, "unknown condition type #{condition}" end end |
#add_field(key, value) ⇒ Object
35 36 37 38 39 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 35 def add_field key, value fields[key] = value add_condition key, value value end |
#aws_access_key_id ⇒ Object
13 14 15 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 13 def aws_access_key_id fields['AWSAccessKeyID'] #access key id is not included in the policy end |
#aws_access_key_id=(value) ⇒ Object
9 10 11 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 9 def aws_access_key_id= value fields['AWSAccessKeyID'] = value #access key id is not included in the policy end |
#aws_session_token ⇒ Object
18 19 20 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 18 def aws_session_token fields['x-amz-security-token'] end |
#aws_session_token=(value) ⇒ Object
22 23 24 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 22 def aws_session_token= value add_field 'x-amz-security-token', value end |
#bucket ⇒ Object
27 28 29 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 27 def bucket fields['bucket'] end |
#bucket=(value) ⇒ Object
31 32 33 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 31 def bucket= value add_field 'bucket', value end |
#encoded_policy ⇒ Object
73 74 75 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 73 def encoded_policy Base64.strict_encode64(policy_document.to_json) end |
#endpoint ⇒ Object
69 70 71 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 69 def endpoint "https://#{bucket}.s3-#{region}.amazonaws.com" end |
#policy_document ⇒ Object
77 78 79 80 81 82 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 77 def policy_document { 'expiration' => expires.xmlschema, 'conditions' => @conditions.values } end |
#restrict_content_length(range) ⇒ Object
53 54 55 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 53 def restrict_content_length range add_condition 'content-length-range', range end |
#signature ⇒ Object
65 66 67 |
# File 'lib/s3_browser_uploads/form_definition.rb', line 65 def signature Base64.strict_encode64(@hmac[encoded_policy]) end |