2013-08-01 01:46:24 +00:00
|
|
|
module JamRuby
|
|
|
|
|
class CrashDump < ActiveRecord::Base
|
|
|
|
|
|
2021-04-12 18:50:46 +00:00
|
|
|
include JamRuby::S3AnalyticsManagerMixin
|
2015-12-09 17:32:24 +00:00
|
|
|
|
2013-08-01 01:46:24 +00:00
|
|
|
self.table_name = "crash_dumps"
|
|
|
|
|
|
|
|
|
|
self.primary_key = 'id'
|
2013-08-09 02:12:43 +00:00
|
|
|
|
|
|
|
|
belongs_to :user, :inverse_of => :crash_dumps, :class_name => "JamRuby::User"
|
2013-08-01 01:46:24 +00:00
|
|
|
|
2021-04-12 18:50:46 +00:00
|
|
|
validates :client_type, :client_version, :description, presence: true
|
2013-08-01 02:05:38 +00:00
|
|
|
|
2013-08-09 02:12:43 +00:00
|
|
|
attr_accessor :user_email
|
|
|
|
|
|
2013-08-01 02:05:38 +00:00
|
|
|
before_validation(:on => :create) do
|
|
|
|
|
self.created_at ||= Time.now
|
|
|
|
|
self.id = SecureRandom.uuid
|
2021-04-12 18:50:46 +00:00
|
|
|
type = description.gsub(/[^a-zA-Z0-9_.-]/, '')
|
|
|
|
|
self.uri = "stats/#{type}/#{created_at.strftime('%Y-%m-%d')}/#{self.id}.zip"
|
2013-08-01 02:05:38 +00:00
|
|
|
end
|
2013-08-09 02:12:43 +00:00
|
|
|
|
|
|
|
|
def user_email
|
|
|
|
|
nil if user_id.nil?
|
|
|
|
|
self.user.email
|
|
|
|
|
end
|
|
|
|
|
|
2015-12-09 17:32:24 +00:00
|
|
|
def sign_url(expiration_time = 3600 * 24 * 7, secure=true)
|
2021-04-12 18:50:46 +00:00
|
|
|
s3_manager.sign_url(self[:uri], {:expires => expiration_time, :secure => secure})
|
2015-12-09 17:32:24 +00:00
|
|
|
end
|
2021-04-12 18:50:46 +00:00
|
|
|
|
|
|
|
|
def read_url
|
2021-04-15 23:46:22 +00:00
|
|
|
s3_manager.sign_url(self[:uri], { :expires => Time.now + 5.years,
|
|
|
|
|
:'response_content_type' => 'application/octet-stream'}, :read)
|
2021-04-12 18:50:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def write_url
|
2021-04-15 23:46:22 +00:00
|
|
|
s3_manager.sign_url(self[:uri], { :expires => Rails.application.config.crash_dump_data_signed_url_timeout,
|
|
|
|
|
:'response_content_type' => 'application/octet-stream'}, :write)
|
2021-04-12 18:50:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def s3_bucket
|
|
|
|
|
s3 = AWS::S3.new(:access_key_id => Rails.application.config.aws_access_key_id,
|
|
|
|
|
:secret_access_key => Rails.application.config.aws_secret_access_key)
|
|
|
|
|
s3.buckets[Rails.application.config.aws_analytics_bucket]
|
|
|
|
|
end
|
|
|
|
|
|
2013-08-01 01:46:24 +00:00
|
|
|
end
|
|
|
|
|
end
|