From ad687839b0b3f6368ebc1f3117936096bca222a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 29 Sep 2015 17:47:09 +0200 Subject: [PATCH] Send token to Sentry for debugging purposes --- Gemfile | 2 +- Gemfile.lock | 4 +--- lib/remote_storage/swift.rb | 29 +++++++++++++++++++++++++---- liquor-cabinet.rb | 3 ++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index b785f48..f5ee5c7 100644 --- a/Gemfile +++ b/Gemfile @@ -17,5 +17,5 @@ end group :staging, :production do gem "rainbows" - gem "sentry-raven" + gem "sentry-raven", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index e0d14a8..2c575e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -22,7 +22,6 @@ GEM backports (3.6.4) beefcake (0.3.7) builder (3.2.2) - certifi (2015.08.10) domain_name (0.5.24) unf (>= 0.0.5, < 1.0.0) excon (0.16.10) @@ -77,8 +76,7 @@ GEM mime-types (>= 1.16, < 3.0) netrc (~> 0.7) ruby-hmac (0.4.0) - sentry-raven (0.14.0) - certifi + sentry-raven (0.15.2) faraday (>= 0.7.6) sinatra (1.4.6) rack (~> 1.4) diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index 30226ec..535933d 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -317,19 +317,27 @@ module RemoteStorage end def do_put_request(url, data, content_type) - RestClient.put(url, data, default_headers.merge({content_type: content_type})) + deal_with_unauthorized_requests do + RestClient.put(url, data, default_headers.merge({content_type: content_type})) + end end def do_get_request(url, &block) - RestClient.get(url, default_headers, &block) + deal_with_unauthorized_requests do + RestClient.get(url, default_headers, &block) + end end def do_head_request(url, &block) - RestClient.head(url, default_headers, &block) + deal_with_unauthorized_requests do + RestClient.head(url, default_headers, &block) + end end def do_delete_request(url) - RestClient.delete(url, default_headers) + deal_with_unauthorized_requests do + RestClient.delete(url, default_headers) + end end def escape(url) @@ -367,5 +375,18 @@ module RemoteStorage settings.swift_token end + + def deal_with_unauthorized_requests(&block) + begin + block.call + rescue RestClient::Unauthorized => ex + Raven.capture_exception( + ex, + tags: { swift_token: settings.swift_token, + swift_token_loaded_at: settings.swift_token_loaded_at } + ) + server.halt 500 + end + end end end diff --git a/liquor-cabinet.rb b/liquor-cabinet.rb index 6796d2a..084974a 100644 --- a/liquor-cabinet.rb +++ b/liquor-cabinet.rb @@ -39,7 +39,8 @@ class LiquorCabinet < Sinatra::Base configure :production, :staging do if ENV['SENTRY_DSN'] - require "raven" + require "raven/base" + require "raven/integrations/rack" Raven.configure do |config| config.dsn = ENV['SENTRY_DSN']