From 6f28ca7874856ca1a92fc877324f2b1f15cdb1e4 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Fri, 31 Oct 2014 05:04:48 +0000 Subject: [PATCH] VRFS-2132 modified crash_dumps to accept dump files and upload them to aws --- admin/app/admin/crash_dumps.rb | 2 +- web/app/controllers/api_users_controller.rb | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/admin/app/admin/crash_dumps.rb b/admin/app/admin/crash_dumps.rb index 8e296efcd..759f3e656 100644 --- a/admin/app/admin/crash_dumps.rb +++ b/admin/app/admin/crash_dumps.rb @@ -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| diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 57255ab66..06d9d6b03 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -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]×tamp=[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]×tamp=[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