Sha256: 42d34b3f357a621d178fa5efe72bf311df3ec8ea6e5b6c9cf6d49644b56bbae1

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

# This module provides helper methods for assets in the CMS admin.
# #
module Admin::AssetsHelper
  include Admin::AdminHelper

  # Sign policy with S3 credentials
  #
  # @!visibility private
  def signature(options = {})
    Base64.encode64(
      OpenSSL::HMAC.digest(
        OpenSSL::Digest::Digest.new('sha1'),
        Slices::Config.s3_credentials[:secret_access_key],
        policy({ secret_access_key: Slices::Config.s3_credentials[:secret_access_key] })
      )
    ).gsub(/\n/, '')
  end

  # Generate policy for uploading asset direct to S3
  #
  # @!visibility private
  def policy(options = {})
    Base64.encode64(
      {
        expiration: 30.minutes.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z'),
        conditions: [
          { bucket: Slices::Config.s3_credentials[:bucket] },
          { acl: 'public-read' },
          { success_action_status: '201' },
          ['starts-with', '$key', ''],
          ['starts-with', '$Content-Type', ''],
        ]
      }.to_json
    ).gsub(/\n|\r/, '')
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
slices-2.0.2 app/helpers/admin/assets_helper.rb
slices-2.0.1 app/helpers/admin/assets_helper.rb
slices-2.0.0 app/helpers/admin/assets_helper.rb
slices-1.0.5 app/helpers/admin/assets_helper.rb
slices-1.0.4 app/helpers/admin/assets_helper.rb
slices-1.0.3 app/helpers/admin/assets_helper.rb
slices-1.0.2 app/helpers/admin/assets_helper.rb
slices-1.0.1 app/helpers/admin/assets_helper.rb
slices-1.0.0 app/helpers/admin/assets_helper.rb