refactor crash_dump
This commit is contained in:
parent
e135e60d6c
commit
202c3f5e86
|
|
@ -10,14 +10,12 @@ module JamRuby
|
|||
belongs_to :user, :inverse_of => :crash_dumps, :class_name => "JamRuby::User"
|
||||
|
||||
validates :client_type, :client_version, :description, presence: true
|
||||
#validates :client_version, presence: true
|
||||
|
||||
attr_accessor :user_email
|
||||
|
||||
before_validation(:on => :create) do
|
||||
self.created_at ||= Time.now
|
||||
self.id = SecureRandom.uuid
|
||||
#self.uri = "dumps/#{created_at.strftime('%Y-%m-%d')}/#{self.id}.zip"
|
||||
type = description.gsub(/[^a-zA-Z0-9_.-]/, '')
|
||||
self.uri = "stats/#{type}/#{created_at.strftime('%Y-%m-%d')}/#{self.id}.zip"
|
||||
end
|
||||
|
|
@ -32,17 +30,13 @@ module JamRuby
|
|||
end
|
||||
|
||||
def read_url
|
||||
expire = Time.now + 5.years
|
||||
s3_bucket.objects[uri].url_for(:read,
|
||||
:expires => expire,
|
||||
:'response_content_type' => 'application/octet-stream').to_s
|
||||
s3_manager.sign_url(self[:uri], { :expires => Time.now + 5.years,
|
||||
:'response_content_type' => 'application/octet-stream'}, :read)
|
||||
end
|
||||
|
||||
def write_url
|
||||
s3_bucket.objects[uri].url_for(:write,
|
||||
:expires => Rails.application.config.crash_dump_data_signed_url_timeout,
|
||||
:'response_content_type' => 'application/octet-stream').to_s
|
||||
|
||||
s3_manager.sign_url(self[:uri], { :expires => Rails.application.config.crash_dump_data_signed_url_timeout,
|
||||
:'response_content_type' => 'application/octet-stream'}, :write)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -4,15 +4,17 @@ describe CrashDump do
|
|||
before do
|
||||
end
|
||||
|
||||
it "should fail to save a crash dump without a client_type and client_version" do
|
||||
CrashDump.new(:client_type => "", :client_version => "version").should_not be_valid
|
||||
CrashDump.new(:client_type => "type", :client_version => "").should_not be_valid
|
||||
it "should fail to save a crash dump without a client_type, client_version or description" do
|
||||
CrashDump.new(:client_type => "", :client_version => "version", :description => "").should_not be_valid
|
||||
CrashDump.new(:client_type => "type", :client_version => "", :description => "").should_not be_valid
|
||||
CrashDump.new(:client_type => "type", :client_version => "1.0", :description => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "should be able to save a crash dump with JUST a client_type and client_version" do
|
||||
it "should be able to save a crash dump with JUST a client_type, client_version and description" do
|
||||
@cd = CrashDump.new
|
||||
@cd.client_type = "Win32"
|
||||
@cd.client_version = "version"
|
||||
@cd.description = "crash"
|
||||
@cd.should be_valid
|
||||
@cd.save
|
||||
|
||||
|
|
|
|||
|
|
@ -684,20 +684,6 @@ class ApiUsersController < ApiController
|
|||
|
||||
# This part is the piece that really needs to be decomposed into a library...
|
||||
if Rails.application.config.storage_type == :fog
|
||||
# s3 = AWS::S3.new(:access_key_id => Rails.application.config.aws_access_key_id,
|
||||
# :secret_access_key => Rails.application.config.aws_secret_access_key)
|
||||
# bucket = s3.buckets[Rails.application.config.aws_bucket]
|
||||
# uri = @dump.uri
|
||||
# expire = Time.now + 5.years
|
||||
# read_url = bucket.objects[uri].url_for(:read,
|
||||
# :expires => expire,
|
||||
# :'response_content_type' => 'application/octet-stream').to_s
|
||||
# #@dump.update_attribute(:uri, read_url)
|
||||
|
||||
# write_url = bucket.objects[uri].url_for(:write,
|
||||
# :expires => Rails.application.config.crash_dump_data_signed_url_timeout,
|
||||
# :'response_content_type' => 'application/octet-stream').to_s
|
||||
|
||||
read_url = @dump.read_url
|
||||
write_url = @dump.write_url
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue