lhc 15.0.1 → 15.1.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 +4 -4
- data/README.md +11 -5
- data/lhc.gemspec +1 -0
- data/lib/lhc/error.rb +1 -1
- data/lib/lhc/request.rb +1 -0
- data/lib/lhc/response.rb +6 -0
- data/lib/lhc/scrubbers/cache_scrubber.rb +32 -0
- data/lib/lhc/scrubbers/effective_url_scrubber.rb +32 -0
- data/lib/lhc/version.rb +1 -1
- data/lib/lhc.rb +5 -0
- data/spec/error/to_s_spec.rb +3 -1
- data/spec/request/scrubbed_options_spec.rb +8 -1
- data/spec/response/scrubbed_options_spec.rb +20 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24396a7fdc614a0af2564a93a52b2ef4b644ad574b1cdf35e8a0d885d34f356d
|
4
|
+
data.tar.gz: d31c263bdfb9252352767a6dc59cc18dc47177739cd1713b4c3e0b0d01a66b82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a6e689b200144b2b1f154dfa773b0cd765f3fecca312ecbdfd599c317a16bd81eb089c74ee33679c0a065984dec34306aafa3884b41d256001e8d3a9f64d553
|
7
|
+
data.tar.gz: a782d7e841d55227fc2dd999f6ceb827717f332afdf776796e76097131681661710fa2cbf5bf934d83778ae2594a2b6b0127d6ceaf9899613aa9c94677173288
|
data/README.md
CHANGED
@@ -618,12 +618,18 @@ Adds the following to body of all requests:
|
|
618
618
|
|
619
619
|
##### Reauthenticate
|
620
620
|
|
621
|
-
The current implementation
|
622
|
-
|
623
|
-
|
624
|
-
|
621
|
+
The current implementation offers only reauthentication for _client access tokens_.
|
622
|
+
Make sure that your interceptors contain `LHC::Auth` and `LHC::Retry`, whereas `LHC::Retry` comes _after_ `LHC::Auth` in the chain.
|
623
|
+
Provide the refresh token as following:
|
624
|
+
```ruby
|
625
|
+
LHC.get('http://local.ch', auth: { bearer: -> { access_token }, refresh_client_token: -> { TokenRefreshUtil.client_access_token(true) })
|
626
|
+
```
|
627
|
+
Where `TokenRefreshUtil.client_access_token(true)` forces a refresh of the token and returns the new token. It is also expected that this implementation will handle invalidating caches if necessary.
|
625
628
|
|
626
|
-
|
629
|
+
You can also set a global `refresh_client_token`. This is not recommended for apps with multiple endpoint and different access tokens.
|
630
|
+
```ruby
|
631
|
+
LHC::Auth.refresh_client_token = -> { TokenRefreshUtil.client_access_token(true) }
|
632
|
+
```
|
627
633
|
|
628
634
|
Reauthentication will be initiated if:
|
629
635
|
|
data/lhc.gemspec
CHANGED
data/lib/lhc/error.rb
CHANGED
@@ -75,7 +75,7 @@ class LHC::Error < StandardError
|
|
75
75
|
debug << "Options: #{request.scrubbed_options}"
|
76
76
|
debug << "Headers: #{request.scrubbed_headers}"
|
77
77
|
debug << "Response Code: #{response.code} (#{response.options[:return_code]})"
|
78
|
-
debug << "Response Options: #{response.
|
78
|
+
debug << "Response Options: #{response.scrubbed_options}"
|
79
79
|
debug << response.body
|
80
80
|
debug << _message
|
81
81
|
debug.map { |str| self.class.fix_invalid_encoding(str) }.join("\n")
|
data/lib/lhc/request.rb
CHANGED
@@ -72,6 +72,7 @@ class LHC::Request
|
|
72
72
|
|
73
73
|
def scrubbed_options
|
74
74
|
scrubbed_options = options.deep_dup
|
75
|
+
scrubbed_options[:cache] = LHC::CacheScrubber.new(scrubbed_options[:cache]).scrubbed
|
75
76
|
scrubbed_options[:params] = LHC::ParamsScrubber.new(scrubbed_options[:params]).scrubbed
|
76
77
|
scrubbed_options[:headers] = LHC::HeadersScrubber.new(scrubbed_options[:headers], scrubbed_options[:auth]).scrubbed
|
77
78
|
scrubbed_options[:auth] = LHC::AuthScrubber.new(scrubbed_options[:auth]).scrubbed
|
data/lib/lhc/response.rb
CHANGED
@@ -54,6 +54,12 @@ class LHC::Response
|
|
54
54
|
request.format
|
55
55
|
end
|
56
56
|
|
57
|
+
def scrubbed_options
|
58
|
+
scrubbed_options = options.deep_dup
|
59
|
+
scrubbed_options[:effective_url] = LHC::EffectiveUrlScrubber.new(scrubbed_options[:effective_url]).scrubbed
|
60
|
+
scrubbed_options
|
61
|
+
end
|
62
|
+
|
57
63
|
private
|
58
64
|
|
59
65
|
attr_accessor :raw
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class LHC::CacheScrubber < LHC::Scrubber
|
4
|
+
def initialize(data)
|
5
|
+
super(data)
|
6
|
+
scrub_cache_options!
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def scrub_cache_options!
|
12
|
+
return if scrubbed.blank?
|
13
|
+
return if scrub_elements.blank?
|
14
|
+
|
15
|
+
scrub_cache_key!
|
16
|
+
end
|
17
|
+
|
18
|
+
def scrub_cache_key!
|
19
|
+
return if scrubbed[:key].blank?
|
20
|
+
|
21
|
+
scrub_elements.each do |scrub_element|
|
22
|
+
value = scrubbed[:key].match(/:#{scrub_element}=>"(.*?)"/)[-1]
|
23
|
+
scrubbed[:key].gsub!(value, SCRUB_DISPLAY)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def scrub_elements
|
28
|
+
# The cache key includes the whole request url inklusive params.
|
29
|
+
# We need to scrub those params from the cache key.
|
30
|
+
LHC.config.scrubs[:params]
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class LHC::EffectiveUrlScrubber < LHC::Scrubber
|
4
|
+
def initialize(data)
|
5
|
+
super(data)
|
6
|
+
scrub_effective_url_options!
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def scrub_effective_url_options!
|
12
|
+
return if scrubbed.blank?
|
13
|
+
return if scrub_elements.blank?
|
14
|
+
|
15
|
+
scrub_effective_url!
|
16
|
+
end
|
17
|
+
|
18
|
+
def scrub_effective_url!
|
19
|
+
return if scrubbed.blank?
|
20
|
+
|
21
|
+
scrub_elements.each do |scrub_element|
|
22
|
+
uri = LocalUri::URI.new(scrubbed)
|
23
|
+
self.scrubbed = CGI.unescape(uri.query.merge(scrub_element => SCRUB_DISPLAY).to_s)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def scrub_elements
|
28
|
+
# The effective url includes the params of the request
|
29
|
+
# so we need to scrub those params from the effective url.
|
30
|
+
LHC.config.scrubs[:params]
|
31
|
+
end
|
32
|
+
end
|
data/lib/lhc/version.rb
CHANGED
data/lib/lhc.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'local_uri'
|
3
4
|
require 'typhoeus'
|
4
5
|
require 'active_support/core_ext/object/blank'
|
5
6
|
require 'active_support/core_ext/hash/keys'
|
@@ -119,6 +120,10 @@ module LHC
|
|
119
120
|
'lhc/scrubbers/auth_scrubber'
|
120
121
|
autoload :BodyScrubber,
|
121
122
|
'lhc/scrubbers/body_scrubber'
|
123
|
+
autoload :CacheScrubber,
|
124
|
+
'lhc/scrubbers/cache_scrubber'
|
125
|
+
autoload :EffectiveUrlScrubber,
|
126
|
+
'lhc/scrubbers/effective_url_scrubber'
|
122
127
|
autoload :HeadersScrubber,
|
123
128
|
'lhc/scrubbers/headers_scrubber'
|
124
129
|
autoload :ParamsScrubber,
|
data/spec/error/to_s_spec.rb
CHANGED
@@ -55,10 +55,12 @@ describe LHC::Error do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
let(:response) do
|
58
|
+
options = { return_code: :internal_error, response_headers: "" }
|
58
59
|
double('LHC::Response',
|
59
60
|
request: request,
|
60
61
|
code: 500,
|
61
|
-
options:
|
62
|
+
options: options,
|
63
|
+
scrubbed_options: options,
|
62
64
|
body: '{"status":500,"message":"undefined"}')
|
63
65
|
end
|
64
66
|
|
@@ -18,9 +18,12 @@ describe LHC::Request do
|
|
18
18
|
let(:params) { { api_key: 'api-key-params' } }
|
19
19
|
let(:headers) { { private_key: 'private-key-header' } }
|
20
20
|
let(:body) { { user_token: 'user-token-body' } }
|
21
|
+
let(:cache) do
|
22
|
+
{ key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?#{params}" }
|
23
|
+
end
|
21
24
|
|
22
25
|
let(:request) do
|
23
|
-
response = LHC.post(:local, params: params, headers: headers, body: body)
|
26
|
+
response = LHC.post(:local, params: params, headers: headers, body: body, cache: cache)
|
24
27
|
response.request
|
25
28
|
end
|
26
29
|
|
@@ -30,6 +33,8 @@ describe LHC::Request do
|
|
30
33
|
expect(request.scrubbed_options[:body]).to include(user_token: LHC::Scrubber::SCRUB_DISPLAY)
|
31
34
|
expect(request.scrubbed_options[:auth][:bearer_token]).to eq(LHC::Scrubber::SCRUB_DISPLAY)
|
32
35
|
expect(request.scrubbed_options[:auth][:basic]).to be nil
|
36
|
+
expect(request.scrubbed_options[:cache])
|
37
|
+
.to include(key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?{:api_key=>\"[FILTERED]\"}")
|
33
38
|
end
|
34
39
|
|
35
40
|
context 'when bearer auth is not a proc' do
|
@@ -104,6 +109,8 @@ describe LHC::Request do
|
|
104
109
|
expect(request.scrubbed_options[:headers]).not_to include(private_key: LHC::Scrubber::SCRUB_DISPLAY)
|
105
110
|
expect(request.scrubbed_options[:body]).not_to include(user_token: LHC::Scrubber::SCRUB_DISPLAY)
|
106
111
|
expect(request.scrubbed_options[:auth][:bearer_token]).not_to eq(LHC::Scrubber::SCRUB_DISPLAY)
|
112
|
+
expect(request.scrubbed_options[:cache])
|
113
|
+
.not_to include(key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?{:api_key=>\"[FILTERED]\"}")
|
107
114
|
end
|
108
115
|
end
|
109
116
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHC::Response do
|
6
|
+
let(:options) do
|
7
|
+
{ effective_url: 'http://local.ch?api_key=api-key' }
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:raw_response) { OpenStruct.new(options: options) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
LHC.config.scrubs[:params] << 'api_key'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'scrubbes effective url' do
|
17
|
+
response = LHC::Response.new(raw_response, nil)
|
18
|
+
expect(response.scrubbed_options[:effective_url]).to eq "http://local.ch?api_key=#{LHC::Scrubber::SCRUB_DISPLAY}"
|
19
|
+
end
|
20
|
+
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.0
|
4
|
+
version: 15.1.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: 2021-
|
11
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: local_uri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: typhoeus
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,6 +287,8 @@ files:
|
|
273
287
|
- lib/lhc/scrubber.rb
|
274
288
|
- lib/lhc/scrubbers/auth_scrubber.rb
|
275
289
|
- lib/lhc/scrubbers/body_scrubber.rb
|
290
|
+
- lib/lhc/scrubbers/cache_scrubber.rb
|
291
|
+
- lib/lhc/scrubbers/effective_url_scrubber.rb
|
276
292
|
- lib/lhc/scrubbers/headers_scrubber.rb
|
277
293
|
- lib/lhc/scrubbers/params_scrubber.rb
|
278
294
|
- lib/lhc/test/cache_helper.rb
|
@@ -401,6 +417,7 @@ files:
|
|
401
417
|
- spec/response/effective_url_spec.rb
|
402
418
|
- spec/response/headers_spec.rb
|
403
419
|
- spec/response/options_spec.rb
|
420
|
+
- spec/response/scrubbed_options_spec.rb
|
404
421
|
- spec/response/success_spec.rb
|
405
422
|
- spec/response/time_spec.rb
|
406
423
|
- spec/spec_helper.rb
|
@@ -560,6 +577,7 @@ test_files:
|
|
560
577
|
- spec/response/effective_url_spec.rb
|
561
578
|
- spec/response/headers_spec.rb
|
562
579
|
- spec/response/options_spec.rb
|
580
|
+
- spec/response/scrubbed_options_spec.rb
|
563
581
|
- spec/response/success_spec.rb
|
564
582
|
- spec/response/time_spec.rb
|
565
583
|
- spec/spec_helper.rb
|