lhc 15.1.1 → 15.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/lhc.gemspec +2 -2
- data/lib/lhc/interceptors/auth.rb +6 -3
- data/lib/lhc/interceptors/rollbar.rb +12 -3
- data/lib/lhc/version.rb +1 -1
- data/spec/error/to_s_spec.rb +2 -2
- data/spec/interceptors/auth/reauthentication_spec.rb +21 -0
- data/spec/interceptors/rollbar/main_spec.rb +20 -1
- metadata +17 -138
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b791317124325a44a99ca08c5cfabb611affd67d38603476151c106b84d924
|
4
|
+
data.tar.gz: 198d4f707ab907c7209ea1f8bbf41452f46fb3079dbf14a73f243ed37b09d6dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6955a082a0e31f564f7b4c6243bfd8274e684cb392702f38d81f044d9ccbc9ff20085428d2529e6a48bd3f194ff69c99686c7744ce681ac8234942f1d4830f5
|
7
|
+
data.tar.gz: 5b11847bfb5f8a9e00797e7c8d87dbd5f9784c6f60cb926d414723fc16faf0fba871ffc6917e63475a6a6a3ae8b49b112b7c6f8fc716a6ee61deaa42d2a040f0
|
data/.rubocop.yml
CHANGED
@@ -26,6 +26,9 @@ require:
|
|
26
26
|
Bundler/OrderedGems:
|
27
27
|
Enabled: false
|
28
28
|
|
29
|
+
Gemspec/RequireMFA:
|
30
|
+
Enabled: false
|
31
|
+
|
29
32
|
Lint/SuppressedException:
|
30
33
|
Exclude:
|
31
34
|
- spec/**/*
|
@@ -260,7 +263,7 @@ Style/CaseLikeIf:
|
|
260
263
|
Enabled: false
|
261
264
|
|
262
265
|
Style/HashEachMethods:
|
263
|
-
Enabled: false
|
266
|
+
Enabled: false
|
264
267
|
|
265
268
|
Style/HashConversion: # (new in 1.10)
|
266
269
|
Enabled: false
|
@@ -268,6 +271,9 @@ Style/HashConversion: # (new in 1.10)
|
|
268
271
|
Style/NilLambda: # (new in 1.3)
|
269
272
|
Enabled: false
|
270
273
|
|
274
|
+
Style/OpenStructUse:
|
275
|
+
Enabled: false
|
276
|
+
|
271
277
|
RSpec/DescribeClass:
|
272
278
|
Exclude:
|
273
279
|
- spec/views/**/*
|
data/lhc.gemspec
CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.summary = 'Advanced HTTP Client for Ruby, fueled with interceptors'
|
16
16
|
s.description = 'LHC is an extended/advanced HTTP client. Implementing basic http-communication enhancements like interceptors, exception handling, format handling, accessing response data, configuring endpoints and placeholders and fully compatible, RFC-compliant URL-template support.'
|
17
17
|
|
18
|
-
s.files
|
19
|
-
s.test_files = `git ls-files -- spec/*`.split("\n")
|
18
|
+
s.files = `git ls-files`.split("\n")
|
20
19
|
s.require_paths = ['lib']
|
21
20
|
|
22
21
|
s.requirements << 'Ruby >= 2.0.0'
|
@@ -36,6 +35,7 @@ Gem::Specification.new do |s|
|
|
36
35
|
s.add_development_dependency 'rubocop', '~> 1.0'
|
37
36
|
s.add_development_dependency 'rubocop-performance', '~> 1.0'
|
38
37
|
s.add_development_dependency 'rubocop-rspec', '~> 1.26.0'
|
38
|
+
s.add_development_dependency 'sprockets-rails'
|
39
39
|
s.add_development_dependency 'timecop'
|
40
40
|
s.add_development_dependency 'webmock'
|
41
41
|
|
@@ -39,7 +39,7 @@ class LHC::Auth < LHC::Interceptor
|
|
39
39
|
set_bearer_authorization_header(token)
|
40
40
|
end
|
41
41
|
|
42
|
-
# rubocop:disable
|
42
|
+
# rubocop:disable Naming/AccessorMethodName
|
43
43
|
def set_authorization_header(value)
|
44
44
|
request.headers['Authorization'] = value
|
45
45
|
end
|
@@ -50,10 +50,13 @@ class LHC::Auth < LHC::Interceptor
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def set_bearer_authorization_header(token)
|
53
|
-
request.options[:auth]
|
53
|
+
auth_options = request.options[:auth] || {}
|
54
|
+
auth_options.merge!(bearer_token: token)
|
55
|
+
request.options[:auth] = auth_options unless request.options.key?(:auth)
|
56
|
+
|
54
57
|
set_authorization_header("Bearer #{token}")
|
55
58
|
end
|
56
|
-
# rubocop:enable
|
59
|
+
# rubocop:enable Naming/AccessorMethodName
|
57
60
|
|
58
61
|
def reauthenticate!
|
59
62
|
# refresh token and update header
|
@@ -7,8 +7,8 @@ class LHC::Rollbar < LHC::Interceptor
|
|
7
7
|
include LHC::FixInvalidEncodingConcern
|
8
8
|
|
9
9
|
def after_response
|
10
|
-
return unless Object.const_defined?(
|
11
|
-
return
|
10
|
+
return unless Object.const_defined?(:Rollbar)
|
11
|
+
return unless report?
|
12
12
|
|
13
13
|
request = response.request
|
14
14
|
additional_params = request.options.fetch(:rollbar, {})
|
@@ -29,9 +29,18 @@ class LHC::Rollbar < LHC::Interceptor
|
|
29
29
|
}.merge additional_params
|
30
30
|
begin
|
31
31
|
Rollbar.warning("Status: #{response.code} URL: #{request.url}", data)
|
32
|
-
rescue Encoding::UndefinedConversionError
|
32
|
+
rescue JSON::GeneratorError, Encoding::UndefinedConversionError
|
33
33
|
sanitized_data = data.deep_transform_values { |value| self.class.fix_invalid_encoding(value) }
|
34
34
|
Rollbar.warning("Status: #{response.code} URL: #{request.url}", sanitized_data)
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def report?
|
41
|
+
return false if response.success?
|
42
|
+
return false if response.request.error_ignored?
|
43
|
+
|
44
|
+
true
|
45
|
+
end
|
37
46
|
end
|
data/lib/lhc/version.rb
CHANGED
data/spec/error/to_s_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe LHC::Error do
|
|
15
15
|
expect { "#{valid} #{invalid}" }.to raise_error Encoding::CompatibilityError
|
16
16
|
end
|
17
17
|
it 'to_json on an array raises an error' do
|
18
|
-
expect { [valid, invalid].to_json }.to raise_error
|
18
|
+
expect { [valid, invalid].to_json }.to raise_error JSON::GeneratorError
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'to_s on a hash does not raise an error' do
|
@@ -23,7 +23,7 @@ describe LHC::Error do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'to_json on a hash does raise an error' do
|
26
|
-
expect { { valid: valid, invalid: invalid }.to_json }.to raise_error
|
26
|
+
expect { { valid: valid, invalid: invalid }.to_json }.to raise_error JSON::GeneratorError
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -27,6 +27,27 @@ describe LHC::Auth do
|
|
27
27
|
expect(auth_suceeding_after_recovery).to have_been_made.once
|
28
28
|
end
|
29
29
|
|
30
|
+
context 'without `auth` options' do
|
31
|
+
let(:headers) do
|
32
|
+
{ 'Authorization' => "Bearer #{initial_token}" }
|
33
|
+
end
|
34
|
+
|
35
|
+
before do
|
36
|
+
LHC::Auth.refresh_client_token = -> { refresh_token }
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
LHC::Auth.refresh_client_token = -> { nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'recovery is attempted' do
|
44
|
+
LHC.config.endpoint(:local, 'http://local.ch')
|
45
|
+
# the retried request (with updated Bearer), that should work
|
46
|
+
LHC.get(:local, { headers: headers })
|
47
|
+
expect(auth_suceeding_after_recovery).to have_been_made.once
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
30
51
|
it "recovery is not attempted again when the request has reauthenticated: true " do
|
31
52
|
LHC.config.endpoint(:local, 'http://local.ch', auth: options.merge(reauthenticated: true))
|
32
53
|
expect { LHC.get(:local) }.to raise_error(LHC::Unauthorized)
|
@@ -9,7 +9,7 @@ describe LHC::Rollbar do
|
|
9
9
|
|
10
10
|
context 'Rollbar is undefined' do
|
11
11
|
before(:each) do
|
12
|
-
Object.send(:remove_const, 'Rollbar') if Object.const_defined?(
|
12
|
+
Object.send(:remove_const, 'Rollbar') if Object.const_defined?(:Rollbar)
|
13
13
|
end
|
14
14
|
it 'does not report' do
|
15
15
|
stub_request(:get, 'http://local.ch').to_return(status: 400)
|
@@ -65,5 +65,24 @@ describe LHC::Rollbar do
|
|
65
65
|
request: hash_including(url: anything, method: anything, headers: hash_including(private_key: LHC::Scrubber::SCRUB_DISPLAY), params: { api_key: LHC::Scrubber::SCRUB_DISPLAY })
|
66
66
|
)
|
67
67
|
end
|
68
|
+
|
69
|
+
context 'ignored errors' do
|
70
|
+
it 'does not report to rollbar if the error is ignored' do
|
71
|
+
stub_request(:get, 'http://local.ch').to_return(status: 404)
|
72
|
+
LHC.get('http://local.ch', ignore: [LHC::NotFound])
|
73
|
+
expect(::Rollbar).not_to have_received(:warning)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'does report to rollbar' do
|
77
|
+
stub_request(:get, 'http://local.ch').to_return(status: 400)
|
78
|
+
expect(-> { LHC.get('http://local.ch', ignore: [LHC::NotFound]) }).to raise_error LHC::BadRequest
|
79
|
+
expect(::Rollbar).not_to have_received(:warning)
|
80
|
+
.with(
|
81
|
+
'Status: 400 URL: http://local.ch',
|
82
|
+
response: hash_including(body: anything, code: anything, headers: anything, time: anything, timeout?: anything),
|
83
|
+
request: hash_including(url: anything, method: anything, headers: hash_including(private_key: LHC::Scrubber::SCRUB_DISPLAY), params: { api_key: LHC::Scrubber::SCRUB_DISPLAY })
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
68
87
|
end
|
69
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 15.
|
4
|
+
version: 15.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: 1.26.0
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: sprockets-rails
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
- !ruby/object:Gem::Dependency
|
196
210
|
name: timecop
|
197
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -453,139 +467,4 @@ rubygems_version: 3.1.4
|
|
453
467
|
signing_key:
|
454
468
|
specification_version: 4
|
455
469
|
summary: Advanced HTTP Client for Ruby, fueled with interceptors
|
456
|
-
test_files:
|
457
|
-
- spec/basic_methods/delete_spec.rb
|
458
|
-
- spec/basic_methods/get_spec.rb
|
459
|
-
- spec/basic_methods/post_spec.rb
|
460
|
-
- spec/basic_methods/put_spec.rb
|
461
|
-
- spec/basic_methods/request_spec.rb
|
462
|
-
- spec/basic_methods/request_without_rails_spec.rb
|
463
|
-
- spec/config/endpoints_spec.rb
|
464
|
-
- spec/config/placeholders_spec.rb
|
465
|
-
- spec/config/scrubs_spec.rb
|
466
|
-
- spec/core_ext/hash/deep_transform_values_spec.rb
|
467
|
-
- spec/dummy/README.rdoc
|
468
|
-
- spec/dummy/Rakefile
|
469
|
-
- spec/dummy/app/assets/config/manifest.js
|
470
|
-
- spec/dummy/app/assets/images/.keep
|
471
|
-
- spec/dummy/app/assets/javascripts/application.js
|
472
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
473
|
-
- spec/dummy/app/controllers/application_controller.rb
|
474
|
-
- spec/dummy/app/controllers/concerns/.keep
|
475
|
-
- spec/dummy/app/helpers/application_helper.rb
|
476
|
-
- spec/dummy/app/mailers/.keep
|
477
|
-
- spec/dummy/app/models/.keep
|
478
|
-
- spec/dummy/app/models/concerns/.keep
|
479
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
480
|
-
- spec/dummy/bin/bundle
|
481
|
-
- spec/dummy/bin/rails
|
482
|
-
- spec/dummy/bin/rake
|
483
|
-
- spec/dummy/config.ru
|
484
|
-
- spec/dummy/config/application.rb
|
485
|
-
- spec/dummy/config/boot.rb
|
486
|
-
- spec/dummy/config/environment.rb
|
487
|
-
- spec/dummy/config/environments/development.rb
|
488
|
-
- spec/dummy/config/environments/production.rb
|
489
|
-
- spec/dummy/config/environments/test.rb
|
490
|
-
- spec/dummy/config/initializers/assets.rb
|
491
|
-
- spec/dummy/config/initializers/backtrace_silencers.rb
|
492
|
-
- spec/dummy/config/initializers/cookies_serializer.rb
|
493
|
-
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
494
|
-
- spec/dummy/config/initializers/inflections.rb
|
495
|
-
- spec/dummy/config/initializers/mime_types.rb
|
496
|
-
- spec/dummy/config/initializers/session_store.rb
|
497
|
-
- spec/dummy/config/initializers/wrap_parameters.rb
|
498
|
-
- spec/dummy/config/locales/en.yml
|
499
|
-
- spec/dummy/config/routes.rb
|
500
|
-
- spec/dummy/config/secrets.yml
|
501
|
-
- spec/dummy/lib/assets/.keep
|
502
|
-
- spec/dummy/log/.keep
|
503
|
-
- spec/dummy/public/404.html
|
504
|
-
- spec/dummy/public/422.html
|
505
|
-
- spec/dummy/public/500.html
|
506
|
-
- spec/dummy/public/favicon.ico
|
507
|
-
- spec/dummy/tmp/cache/.gitkeep
|
508
|
-
- spec/endpoint/compile_spec.rb
|
509
|
-
- spec/endpoint/match_spec.rb
|
510
|
-
- spec/endpoint/placeholders_spec.rb
|
511
|
-
- spec/endpoint/remove_interpolated_params_spec.rb
|
512
|
-
- spec/endpoint/values_as_params_spec.rb
|
513
|
-
- spec/error/dup_spec.rb
|
514
|
-
- spec/error/find_spec.rb
|
515
|
-
- spec/error/response_spec.rb
|
516
|
-
- spec/error/timeout_spec.rb
|
517
|
-
- spec/error/to_s_spec.rb
|
518
|
-
- spec/formats/form_spec.rb
|
519
|
-
- spec/formats/json_spec.rb
|
520
|
-
- spec/formats/multipart_spec.rb
|
521
|
-
- spec/formats/plain_spec.rb
|
522
|
-
- spec/interceptors/after_request_spec.rb
|
523
|
-
- spec/interceptors/after_response_spec.rb
|
524
|
-
- spec/interceptors/auth/basic_auth_spec.rb
|
525
|
-
- spec/interceptors/auth/bearer_spec.rb
|
526
|
-
- spec/interceptors/auth/body_spec.rb
|
527
|
-
- spec/interceptors/auth/long_basic_auth_credentials_spec.rb
|
528
|
-
- spec/interceptors/auth/no_instance_var_for_options_spec.rb
|
529
|
-
- spec/interceptors/auth/reauthentication_configuration_spec.rb
|
530
|
-
- spec/interceptors/auth/reauthentication_spec.rb
|
531
|
-
- spec/interceptors/before_request_spec.rb
|
532
|
-
- spec/interceptors/before_response_spec.rb
|
533
|
-
- spec/interceptors/caching/hydra_spec.rb
|
534
|
-
- spec/interceptors/caching/main_spec.rb
|
535
|
-
- spec/interceptors/caching/methods_spec.rb
|
536
|
-
- spec/interceptors/caching/multilevel_cache_spec.rb
|
537
|
-
- spec/interceptors/caching/options_spec.rb
|
538
|
-
- spec/interceptors/caching/parameters_spec.rb
|
539
|
-
- spec/interceptors/caching/response_status_spec.rb
|
540
|
-
- spec/interceptors/caching/to_cache_spec.rb
|
541
|
-
- spec/interceptors/default_interceptors_spec.rb
|
542
|
-
- spec/interceptors/default_timeout/main_spec.rb
|
543
|
-
- spec/interceptors/define_spec.rb
|
544
|
-
- spec/interceptors/dup_spec.rb
|
545
|
-
- spec/interceptors/logging/main_spec.rb
|
546
|
-
- spec/interceptors/monitoring/caching_spec.rb
|
547
|
-
- spec/interceptors/monitoring/main_spec.rb
|
548
|
-
- spec/interceptors/prometheus_spec.rb
|
549
|
-
- spec/interceptors/response_competition_spec.rb
|
550
|
-
- spec/interceptors/retry/main_spec.rb
|
551
|
-
- spec/interceptors/return_response_spec.rb
|
552
|
-
- spec/interceptors/rollbar/invalid_encoding_spec.rb
|
553
|
-
- spec/interceptors/rollbar/main_spec.rb
|
554
|
-
- spec/interceptors/throttle/main_spec.rb
|
555
|
-
- spec/interceptors/throttle/reset_track_spec.rb
|
556
|
-
- spec/interceptors/zipkin/distributed_tracing_spec.rb
|
557
|
-
- spec/rails_helper.rb
|
558
|
-
- spec/request/body_spec.rb
|
559
|
-
- spec/request/encoding_spec.rb
|
560
|
-
- spec/request/error_handling_spec.rb
|
561
|
-
- spec/request/headers_spec.rb
|
562
|
-
- spec/request/ignore_errors_spec.rb
|
563
|
-
- spec/request/option_dup_spec.rb
|
564
|
-
- spec/request/parallel_requests_spec.rb
|
565
|
-
- spec/request/params_encoding_spec.rb
|
566
|
-
- spec/request/request_without_rails_spec.rb
|
567
|
-
- spec/request/scrubbed_headers_spec.rb
|
568
|
-
- spec/request/scrubbed_options_spec.rb
|
569
|
-
- spec/request/scrubbed_params_spec.rb
|
570
|
-
- spec/request/url_patterns_spec.rb
|
571
|
-
- spec/request/user_agent_spec.rb
|
572
|
-
- spec/request/user_agent_without_rails_spec.rb
|
573
|
-
- spec/response/body_spec.rb
|
574
|
-
- spec/response/code_spec.rb
|
575
|
-
- spec/response/data_accessor_spec.rb
|
576
|
-
- spec/response/data_spec.rb
|
577
|
-
- spec/response/effective_url_spec.rb
|
578
|
-
- spec/response/headers_spec.rb
|
579
|
-
- spec/response/options_spec.rb
|
580
|
-
- spec/response/scrubbed_options_spec.rb
|
581
|
-
- spec/response/success_spec.rb
|
582
|
-
- spec/response/time_spec.rb
|
583
|
-
- spec/spec_helper.rb
|
584
|
-
- spec/support/fixtures/json/feedback.json
|
585
|
-
- spec/support/fixtures/json/feedbacks.json
|
586
|
-
- spec/support/fixtures/json/localina_content_ad.json
|
587
|
-
- spec/support/load_json.rb
|
588
|
-
- spec/support/reset_config.rb
|
589
|
-
- spec/support/zipkin_mock.rb
|
590
|
-
- spec/timeouts/no_signal_spec.rb
|
591
|
-
- spec/timeouts/timings_spec.rb
|
470
|
+
test_files: []
|