VRFS-2132 modified crash_dumps to accept dump files and upload them to aws

This commit is contained in:
Jonathan Kolyer 2014-10-31 05:04:48 +00:00
parent 53706aec71
commit 6f28ca7874
2 changed files with 16 additions and 7 deletions

View File

@ -7,7 +7,7 @@ ActiveAdmin.register JamRuby::CrashDump, :as => 'Crash Dump' do
index do
column "Timestamp" do |post|
post.timestamp.strftime('%b %d %Y, %H:%M')
(post.timestamp || post.created_at).strftime('%b %d %Y, %H:%M')
end
column "Client Type", :client_type
column "Dump URL" do |post|

View File

@ -477,14 +477,14 @@ class ApiUsersController < ApiController
# This should largely be moved into a library somewhere in jam-ruby.
def crash_dump
# example of using curl to access this API:
# curl -L -T some_file -X PUT http://localhost:3000/api/users/dump.json?client_type=[MACOSX/Win32/JamBox]&client_version=[VERSION]&client_id=[CLIENT_ID]&session_id=[SESSION_ID]&timestamp=[TIMESTAMP]
# curl -L -T some_file -X PUT http://localhost:3000/api/dumps?client_type=[MACOSX/Win32/JamBox]&client_version=[VERSION]&client_id=[CLIENT_ID]&session_id=[SESSION_ID]&timestamp=[TIMESTAMP]
# user_id is deduced if possible from the user's cookie.
@dump = CrashDump.new
@dump.client_type = params[:client_type]
@dump.client_version = params[:client_version]
@dump.client_id = params[:client_id]
@dump.user_id = current_user
@dump.user_id = current_user.try(:id)
@dump.session_id = params[:session_id]
@dump.timestamp = params[:timestamp]
@ -494,17 +494,26 @@ class ApiUsersController < ApiController
respond_with @dump
return
end
# 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]
url = bucket.objects[@dump.uri].url_for(:write, :expires => Rails.application.config.crash_dump_data_signed_url_timeout, :'response_content_type' => 'application/octet-stream').to_s
uri = @dump.uri
expire = Time.now + 20.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)
logger.debug("crash_dump can upload to url #{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
logger.debug("crash_dump can read from url #{read_url}")
redirect_to url
redirect_to write_url
else
# we should store it here to aid in development, but we don't have to until someone wants the feature
# so... just return 200