Class: RedactorAws::Aws

Inherits:
Object
  • Object
show all
Defined in:
app/models/redactor_aws/aws.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAws

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.default_url_options[:host]}/aws/success"
end

Instance Attribute Details

#access_keyObject (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

#bucketObject (readonly)

Returns the value of attribute bucket.


3
4
5
# File 'app/models/redactor_aws/aws.rb', line 3

def bucket
  @bucket
end

#files_pathObject (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

#prefixObject (readonly)

Returns the value of attribute prefix.


3
4
5
# File 'app/models/redactor_aws/aws.rb', line 3

def prefix
  @prefix
end

#regionObject (readonly)

Returns the value of attribute region.


3
4
5
# File 'app/models/redactor_aws/aws.rb', line 3

def region
  @region
end

#secret_keyObject (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_pathObject (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

#endpointObject


33
34
35
# File 'app/models/redactor_aws/aws.rb', line 33

def endpoint
  "http://#{@bucket}.#{@region}/"
end

#policyObject


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

#signatureObject


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