Class: RedactorAws::Aws
- Inherits:
-
Object
- Object
- RedactorAws::Aws
- Defined in:
- app/models/redactor_aws/aws.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#files_path ⇒ Object
readonly
Returns the value of attribute files_path.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#success_path ⇒ Object
readonly
Returns the value of attribute success_path.
Instance Method Summary collapse
- #endpoint ⇒ Object
-
#initialize ⇒ Aws
constructor
A new instance of Aws.
- #policy ⇒ Object
- #signature ⇒ Object
Constructor Details
#initialize ⇒ Aws
Returns a new instance of Aws.
5 6 7 8 9 10 11 12 |
# File 'app/models/redactor_aws/aws.rb', line 5 def initialize @access_key = RedactorAws.access_key || ENV['AWS_ACCESS_KEY_ID'] @secret_key = RedactorAws.secret_key || ENV['AWS_SECRET_ACCESS_KEY'] @bucket = RedactorAws.bucket @region = RedactorAws.region @prefix = RedactorAws.prefix @success_path = "http://#{Ksv::Application.config.action_mailer.[:host]}/aws/success" end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def access_key @access_key end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def bucket @bucket end |
#files_path ⇒ Object (readonly)
Returns the value of attribute files_path.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def files_path @files_path end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def prefix @prefix end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def region @region end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def secret_key @secret_key end |
#success_path ⇒ Object (readonly)
Returns the value of attribute success_path.
3 4 5 |
# File 'app/models/redactor_aws/aws.rb', line 3 def success_path @success_path end |
Instance Method Details
#endpoint ⇒ Object
33 34 35 |
# File 'app/models/redactor_aws/aws.rb', line 33 def endpoint "http://#{@bucket}.#{@region}/" end |
#policy ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/redactor_aws/aws.rb', line 14 def policy policy_json="{'expiration': '2020-01-01T00:00:00Z', 'conditions': [ {'bucket': '#{@bucket}'}, ['starts-with', '$key', ''], {'acl': 'public-read'}, {'success_action_redirect': '#{@success_path}'}, ['starts-with', '$Content-Type', ''], ['content-length-range', 0, 1048576] ] }" Base64.encode64(policy_json).gsub("\n","") end |
#signature ⇒ Object
29 30 31 |
# File 'app/models/redactor_aws/aws.rb', line 29 def signature Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret_key, policy)).gsub("\n","") end |