lhc-core-interceptors 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ee16284796c7f53b053b526ed636722b2ed5ea8
4
- data.tar.gz: 7a190e5024b2dfdd546ff12982cd97d11cdad36b
3
+ metadata.gz: 4f9b008ab67152dd009a75908ba53b46e859c3e9
4
+ data.tar.gz: 894734ee22df57d95f6a5e4b579d8eba39847625
5
5
  SHA512:
6
- metadata.gz: fa70a751b5be926bcf04bce083ca290e35ece2b29f861790d442bb4901b48004ae2bfd6f5dece684b3c05eee01e09e6eadb1d1e0492563dfe0d68bc8a086748d
7
- data.tar.gz: f7c1aba4e0dfe23cf207132050f247ffc91eda1fd93dcb3acf5534451daa318882efcf144746b59a6e9409645d7687244af7f9d453c561602ee02484f801c8b2
6
+ metadata.gz: 20f42d9456146fed2455827f7aca139a096a1cad24c8489b3e9c2617c042439fc1fa4b98fafe6be92b34af8ac4cb87186c90871354faac297426baf7e2b291f4
7
+ data.tar.gz: c39c15d1541a41727342ac0f50c6f17d5c486364db5fa021459ada3026c733a37419cb94d57a677ee1b27233173e4326b8fd69f16259c5b0264b5b9b62db4618
data/.gitignore CHANGED
@@ -13,7 +13,6 @@ spec/dummy/log/*
13
13
  spec/dummy/tmp/cache/*
14
14
  Gemfile.lock
15
15
  .ruby-gemset
16
- .ruby-version
17
16
 
18
17
  ## Specific to RubyMotion:
19
18
  .dat*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.2
data/README.md CHANGED
@@ -130,6 +130,26 @@ Adds the following header to the request:
130
130
 
131
131
  Which is the base64 encoded credentials "username:password".
132
132
 
133
+ ## Rollbar Interceptor
134
+
135
+ Forward errors to rollbar when exceptions occur during http requests.
136
+
137
+ ```ruby
138
+ LHC.config.interceptors = [LHC::Rollbar]
139
+ ```
140
+
141
+ ```ruby
142
+ LHC.get('http://local.ch')
143
+ ```
144
+
145
+ If it raises, it forwards the request and response object to rollbar, which contain all necessary data.
146
+
147
+ ### Forward additional parameters
148
+
149
+ ```ruby
150
+ LHC.get('http://local.ch', rollbar: { tracking_key: 'this particular request' })
151
+ ```
152
+
133
153
  ## License
134
154
 
135
155
  [GNU Affero General Public License Version 3.](https://www.gnu.org/licenses/agpl-3.0.en.html)
data/cider-ci.yml CHANGED
@@ -1,4 +1,3 @@
1
1
  jobs:
2
- _cider-ci_include:
3
- - cider-ci/jobs/rubocop.yml
2
+ include:
4
3
  - cider-ci/jobs/rspec.yml
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+ set -eux
3
+
4
+ export PATH=~/.rubies/$RUBY/bin:$PATH
5
+ rm -f .bundle/config
6
+
7
+ if [ ! -f ~/.rubies/$RUBY/bin/bundle ]; then
8
+ gem install bundler
9
+ fi
10
+
11
+ sed "s/^source 'https:\/\/rubygems\.intra\.local\.ch'*/source 'http\:\/\/52.29.7.59:9292'/g" Gemfile > Gemfile.tmp
12
+ mv Gemfile.tmp Gemfile
13
+
14
+ DIGEST=$(git ls-tree HEAD --\
15
+ cider-ci.yml cider-ci Gemfile.lock \
16
+ | openssl dgst -sha1 | cut -d ' ' -f 2)
17
+
18
+ DIGEST=$(echo "$DIGEST $PATH" \
19
+ | openssl dgst -sha1 | cut -d ' ' -f 2)
20
+
21
+ CACHE_SIGNATURE_FILE="/tmp/bundle_cache_signature_${DIGEST}"
22
+
23
+ if [ ! -f $CACHE_SIGNATURE_FILE ] ; then
24
+ bundle install
25
+ touch $CACHE_SIGNATURE_FILE
26
+ fi
27
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -eux
3
+
4
+ export PATH=~/.rubies/$RUBY/bin:$PATH
5
+
6
+ if [ ! -d ~/.rubies/$RUBY ]; then
7
+ ruby-install --no-install-deps $RUBY
8
+ fi
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+ set -eux
3
+
4
+ if [ -f ./.ruby-version ]; then
5
+ echo ".ruby-version file found"
6
+ fi
7
+
8
+ if [ ! -f ./.ruby-version ]; then
9
+ echo ".ruby-version file not found"
10
+ exit 1
11
+ fi
12
+
13
+ IFS='-' read -ra EXPLODED_RUBY <<< "$RUBY"
14
+
15
+ if [ "${#EXPLODED_RUBY[@]}" == "1" ]; then
16
+ echo 'No engine/version separator "-" found in .ruby-version file.'
17
+ exit 1
18
+ fi
19
+
20
+ if [ "${#EXPLODED_RUBY[@]}" != "1" ] && [ "${#EXPLODED_RUBY[@]}" != "2" ]; then
21
+ echo "Unknown format of .ruby-version file"
22
+ exit 1
23
+ fi
24
+
25
+ echo $RUBY
@@ -1,48 +1,24 @@
1
1
  rspec:
2
- name: 'RSPec tests'
2
+ name: 'rspec'
3
3
 
4
- run-on:
5
- - type: branch
6
- include-match: ^.*$
4
+ run_when:
5
+ 'some HEAD has been updated':
6
+ type: branch
7
+ include_match: ^.*$
7
8
 
8
9
  context:
9
- task-defaults:
10
- ports:
11
- CAPYBARA_PORT:
12
- inet_address: "localhost"
13
- min: 8000
14
- max: 8999
15
- PHANTOMJS_PORT:
16
- inet_address: "localhost"
17
- min: 44600
18
- max: 44999
19
10
 
20
- scripts:
21
- rspec:
22
- start-when:
23
- - script: bundle
24
- - script: ruby-version
25
- - script: tmp-cache
11
+ script_defaults:
12
+ template_environment_variables: true
26
13
 
14
+ task_defaults:
15
+ max_trials: 2
16
+ dispatch_storm_delay_duration: 1 Seconds
17
+ include:
18
+ - cider-ci/task_components/ruby.yml
19
+ - cider-ci/task_components/bundle.yml
20
+ - cider-ci/task_components/rspec.yml
27
21
 
28
- _cider-ci_include:
29
- - cider-ci/scripts/bundle.yml
30
- - cider-ci/scripts/tmp-cache.yml
31
- - cider-ci/scripts/ruby-version.yml
32
- - cider-ci/scripts/rspec.yml
33
-
34
-
35
- trial-attachments:
36
- logs:
37
- include-match: log\/.*\.log$
38
- content-type: text/plain
39
- image-screenshots:
40
- include-match: tmp\/capybara\/.*\.png$
41
- content-type: image/png
42
- html-screenshots:
43
- include-match: tmp\/capybara\/.*\.html$
44
- content-type: text/html
45
-
46
- _cider-ci_generate-tasks:
47
- include-match: spec/.*_spec.rb
48
- exclude-match: spec/support/shared/*
22
+ tasks:
23
+ all-rspec:
24
+ name: All rspec tests
@@ -0,0 +1,18 @@
1
+ traits:
2
+ ruby-install: true
3
+ Bash: true
4
+
5
+ trial_attachments:
6
+ gemfile:
7
+ include_match: Gemfile
8
+ content_type: text/plain
9
+
10
+ scripts:
11
+
12
+ bundle:
13
+ exclusive_executor_resource: ruby-install_{{$RUBY}}
14
+ timeout: 20 Minutes
15
+ body: cider-ci/bin/bundle
16
+ start_when:
17
+ 'ruby installed':
18
+ script_key: ruby-install
@@ -0,0 +1,36 @@
1
+ ports:
2
+ CAPYBARA_PORT:
3
+ min: 8000
4
+ max: 8999
5
+ PHANTOMJS_PORT:
6
+ min: 44600
7
+ max: 44999
8
+
9
+ environment_variables:
10
+ RUBY:
11
+ read_and_replace_with: .ruby-version
12
+
13
+ scripts:
14
+ rspec:
15
+ body: |
16
+ #!/usr/bin/env bash
17
+ set -eux
18
+ mkdir -p tmp/cache
19
+ export PATH=~/.rubies/$RUBY/bin:$PATH
20
+ bundle exec rspec
21
+
22
+ start_when:
23
+ 'bundled':
24
+ script_key: bundle
25
+
26
+
27
+ trial_attachments:
28
+ logs:
29
+ include_match: log\/.*\.log$
30
+ content_type: text/plain
31
+ image-screenshots:
32
+ include_match: tmp\/capybara\/.*\.png$
33
+ content_type: image/png
34
+ html-screenshots:
35
+ include_match: tmp\/capybara\/.*\.html$
36
+ content_type: text/html
@@ -0,0 +1,15 @@
1
+ environment_variables:
2
+ RUBY:
3
+ read_and_replace_with: .ruby-version
4
+
5
+ scripts:
6
+ ruby-version:
7
+ body: cider-ci/bin/ruby_version
8
+ ruby-install:
9
+ exclusive_executor_resource: ruby-install_{{$RUBY}}
10
+ timeout: 20 Minutes
11
+ body: cider-ci/bin/ruby_install
12
+ start_when:
13
+ 'ruby version checked':
14
+ script_key: ruby-version
15
+
@@ -0,0 +1,18 @@
1
+ class LHC::Rollbar < LHC::Interceptor
2
+ include ActiveSupport::Configurable
3
+
4
+ def after_response(response)
5
+ return unless Object.const_defined?('Rollbar')
6
+ request = response.request
7
+ additional_params = request.options.fetch(:rollbar, {})
8
+ error = LHC::Error.find(response)
9
+ data = {
10
+ response: response,
11
+ request: request
12
+ }.merge additional_params
13
+ Rollbar.error(
14
+ error,
15
+ data
16
+ )
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module LHCCoreInterceptors
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -0,0 +1,46 @@
1
+ require 'rails_helper'
2
+
3
+ describe LHC::Rollbar do
4
+ before(:each) do
5
+ LHC.config.interceptors = [LHC::Rollbar]
6
+ end
7
+
8
+ it 'does not report if Rollbar is not defined' do
9
+ stub_request(:get, 'http://local.ch').to_return(status: 400)
10
+ expect(-> { LHC.get('http://local.ch') })
11
+ .to raise_error LHC::BadRequest
12
+ end
13
+
14
+ context 'Rollbar is defined' do
15
+ before(:each) do
16
+ class Rollbar; end
17
+ allow(::Rollbar).to receive(:error)
18
+ end
19
+
20
+ it 'does report errors to rollbar' do
21
+ stub_request(:get, 'http://local.ch').to_return(status: 400)
22
+ expect(-> { LHC.get('http://local.ch') })
23
+ .to raise_error LHC::BadRequest
24
+ expect(::Rollbar).to have_received(:error)
25
+ .with(LHC::BadRequest, hash_including(response: anything, request: anything))
26
+ end
27
+
28
+ context 'additional params' do
29
+ it 'does report errors to rollbar with additional data' do
30
+ stub_request(:get, 'http://local.ch')
31
+ .to_return(status: 400)
32
+ expect(-> { LHC.get('http://local.ch', rollbar: { additional: 'data' }) })
33
+ .to raise_error LHC::BadRequest
34
+ expect(::Rollbar).to have_received(:error)
35
+ .with(
36
+ LHC::BadRequest,
37
+ hash_including(
38
+ response: anything,
39
+ request: anything,
40
+ additional: 'data'
41
+ )
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc-core-interceptors
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -119,23 +119,24 @@ files:
119
119
  - ".gitignore"
120
120
  - ".rubocop.localch.yml"
121
121
  - ".rubocop.yml"
122
+ - ".ruby-version"
122
123
  - Gemfile
123
124
  - README.md
124
125
  - Rakefile
125
126
  - cider-ci.yml
127
+ - cider-ci/bin/bundle
128
+ - cider-ci/bin/ruby_install
129
+ - cider-ci/bin/ruby_version
126
130
  - cider-ci/jobs/rspec.yml
127
- - cider-ci/jobs/rubocop.yml
128
- - cider-ci/scripts/bundle.yml
129
- - cider-ci/scripts/github_comment.yml
130
- - cider-ci/scripts/rspec.yml
131
- - cider-ci/scripts/rubocop.yml
132
- - cider-ci/scripts/ruby-version.yml
133
- - cider-ci/scripts/tmp-cache.yml
131
+ - cider-ci/task_components/bundle.yml
132
+ - cider-ci/task_components/rspec.yml
133
+ - cider-ci/task_components/ruby.yml
134
134
  - lhc-core-interceptors.gemspec
135
135
  - lib/lhc-core-interceptors.rb
136
136
  - lib/lhc-core-interceptors/auth.rb
137
137
  - lib/lhc-core-interceptors/caching.rb
138
138
  - lib/lhc-core-interceptors/monitoring.rb
139
+ - lib/lhc-core-interceptors/rollbar.rb
139
140
  - lib/lhc-core-interceptors/version.rb
140
141
  - spec/auth/basic_auth_spec.rb
141
142
  - spec/auth/bearer_spec.rb
@@ -185,6 +186,7 @@ files:
185
186
  - spec/dummy/tmp/cache/.gitkeep
186
187
  - spec/monitoring/main_spec.rb
187
188
  - spec/rails_helper.rb
189
+ - spec/rollbar/main_spec.rb
188
190
  - spec/spec_helper.rb
189
191
  - spec/support/cleanup_configuration.rb
190
192
  homepage: https://github.com/local-ch/lhc-core-interceptors
@@ -261,5 +263,6 @@ test_files:
261
263
  - spec/dummy/tmp/cache/.gitkeep
262
264
  - spec/monitoring/main_spec.rb
263
265
  - spec/rails_helper.rb
266
+ - spec/rollbar/main_spec.rb
264
267
  - spec/spec_helper.rb
265
268
  - spec/support/cleanup_configuration.rb
@@ -1,55 +0,0 @@
1
- rubocop:
2
- name: 'Rubocop analysis'
3
-
4
- run-on:
5
- - type: branch
6
- include-match: ^.*$
7
-
8
- context:
9
- task-defaults:
10
- environment-variables:
11
- GIT_REPOSITORY: local-ch/location-app
12
- RESULT_PATH: 'tmp/checkstyle.json'
13
-
14
- scripts:
15
- rubocop:
16
- start-when:
17
- - script: bundle
18
- - script: ruby-version
19
- - script: tmp-cache
20
-
21
-
22
- github_comment:
23
- start-when:
24
- - script: rubocop
25
- states: [failed]
26
-
27
-
28
- _cider-ci_include:
29
- - cider-ci/scripts/bundle.yml
30
- - cider-ci/scripts/tmp-cache.yml
31
- - cider-ci/scripts/ruby-version.yml
32
- - cider-ci/scripts/rubocop.yml
33
-
34
- - cider-ci/scripts/github_comment.yml
35
-
36
-
37
- max-auto-trials: 1
38
-
39
- trial-attachments:
40
- logs:
41
- include-match: tmp\/checkstyle.json$
42
- content-type: application/json
43
-
44
- tree-attachments:
45
- logs:
46
- include-match: tmp\/checkstyle.json$
47
- content-type: application/json
48
-
49
- tasks:
50
- rubocop:
51
- scripts:
52
- rubocop: {}
53
-
54
- github_comment: {}
55
-
@@ -1,3 +0,0 @@
1
- bundle:
2
- exclusive-executor-resource: bundler
3
- body: sed 's/^source.*/source "http\:\/\/52.29.7.59:9292"/g' Gemfile > Gemfile.tmp ; mv Gemfile.tmp Gemfile && bundle install
@@ -1,6 +0,0 @@
1
- github_comment:
2
- ignore-state: true
3
- body: |
4
- #!/usr/bin/env bash
5
-
6
- bundle exec rake checkstyle
@@ -1,4 +0,0 @@
1
- rspec:
2
- body: |
3
- #!/usr/bin/env bash
4
- bundle exec rspec $CIDER_CI_TASK_FILE
@@ -1,5 +0,0 @@
1
- rubocop:
2
- body: |
3
- #!/usr/bin/env bash
4
-
5
- bundle exec rubocop --config .rubocop.yml --format json --out $RESULT_PATH --format progress
@@ -1,2 +0,0 @@
1
- ruby-version:
2
- body: ruby --version
@@ -1,2 +0,0 @@
1
- tmp-cache:
2
- body: mkdir -p tmp/cache