lhc 13.2.0 → 13.4.0.pre.pro1766.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubocop.yml +3 -15
- data/.github/workflows/test.yml +3 -15
- data/.rubocop.yml +341 -19
- data/README.md +45 -0
- data/lhc.gemspec +3 -1
- data/lib/lhc/concerns/lhc/fix_invalid_encoding_concern.rb +1 -0
- data/lib/lhc/config.rb +16 -0
- data/lib/lhc/endpoint.rb +3 -0
- data/lib/lhc/error.rb +4 -2
- data/lib/lhc/interceptors/auth.rb +10 -1
- data/lib/lhc/interceptors/caching.rb +5 -0
- data/lib/lhc/interceptors/logging.rb +4 -2
- data/lib/lhc/interceptors/monitoring.rb +7 -1
- data/lib/lhc/interceptors/retry.rb +2 -0
- data/lib/lhc/interceptors/rollbar.rb +3 -2
- data/lib/lhc/interceptors/throttle.rb +7 -2
- data/lib/lhc/interceptors/zipkin.rb +2 -0
- data/lib/lhc/interceptors.rb +1 -0
- data/lib/lhc/request.rb +30 -1
- data/lib/lhc/response/data.rb +1 -1
- data/lib/lhc/response.rb +1 -0
- data/lib/lhc/scrubber.rb +45 -0
- data/lib/lhc/scrubbers/auth_scrubber.rb +32 -0
- data/lib/lhc/scrubbers/body_scrubber.rb +30 -0
- data/lib/lhc/scrubbers/headers_scrubber.rb +40 -0
- data/lib/lhc/scrubbers/params_scrubber.rb +14 -0
- data/lib/lhc/version.rb +1 -1
- data/lib/lhc.rb +70 -59
- data/spec/config/scrubs_spec.rb +108 -0
- data/spec/error/to_s_spec.rb +6 -6
- data/spec/formats/multipart_spec.rb +1 -1
- data/spec/interceptors/caching/multilevel_cache_spec.rb +1 -1
- data/spec/interceptors/define_spec.rb +1 -0
- data/spec/interceptors/logging/main_spec.rb +21 -1
- data/spec/interceptors/rollbar/main_spec.rb +27 -15
- data/spec/request/scrubbed_headers_spec.rb +101 -0
- data/spec/request/scrubbed_options_spec.rb +185 -0
- data/spec/request/scrubbed_params_spec.rb +25 -0
- data/spec/response/data_spec.rb +2 -2
- data/spec/support/zipkin_mock.rb +1 -0
- metadata +34 -8
- data/.rubocop.localch.yml +0 -325
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14253d5b4b5d91f3ab982f01967045ecdbe49003e4c992544315a2fd0fdc1827
|
4
|
+
data.tar.gz: 7c8e6561080375d1a8cc3d8f5e6ef36ab6c5a09ba15dd0585544e66768336a27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20d7c5716b979647de9c84b0117ff17495ae55abc8d4ba20bc01d9deee37100335c0fc2a4a674ba4883f87c4fbcfa88e274da92aadc972c0385f6930c29db8f9
|
7
|
+
data.tar.gz: f41c9f8302517137811020d2337c2922de8b0cd471f3b744cf80b3ea3d4dad62d2c735305090d5f23912735b07840b92abf01ae2fb801b3b6b7f1e4139ebcccc
|
@@ -8,20 +8,8 @@ jobs:
|
|
8
8
|
|
9
9
|
steps:
|
10
10
|
- uses: actions/checkout@v2
|
11
|
-
- uses:
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
|
-
|
14
|
-
- name: Cache Ruby Gems
|
15
|
-
uses: actions/cache@v2
|
16
|
-
with:
|
17
|
-
path: /.tmp/vendor/bundle
|
18
|
-
key: ${{ runner.os }}-gems-latest-${{ hashFiles('**/Gemfile.lock') }}
|
19
|
-
restore-keys: |
|
20
|
-
${{ runner.os }}-gems-latest-
|
21
|
-
- name: Bundle Install
|
22
|
-
run: |
|
23
|
-
bundle config path /.tmp/vendor/bundle
|
24
|
-
bundle install --jobs 4 --retry 3
|
13
|
+
bundler-cache: true
|
25
14
|
- name: Run Rubocop
|
26
|
-
run:
|
27
|
-
bundle exec rubocop
|
15
|
+
run: bundle exec rubocop
|
data/.github/workflows/test.yml
CHANGED
@@ -8,20 +8,8 @@ jobs:
|
|
8
8
|
|
9
9
|
steps:
|
10
10
|
- uses: actions/checkout@v2
|
11
|
-
- uses:
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
12
|
with:
|
13
|
-
|
14
|
-
- name: Cache Ruby Gems
|
15
|
-
uses: actions/cache@v2
|
16
|
-
with:
|
17
|
-
path: /.tmp/vendor/bundle
|
18
|
-
key: ${{ runner.os }}-gems-latest-${{ hashFiles('**/Gemfile.lock') }}
|
19
|
-
restore-keys: |
|
20
|
-
${{ runner.os }}-gems-latest-
|
21
|
-
- name: Bundle Install
|
22
|
-
run: |
|
23
|
-
bundle config path /.tmp/vendor/bundle
|
24
|
-
bundle install --jobs 4 --retry 3
|
13
|
+
bundler-cache: true
|
25
14
|
- name: Run Tests
|
26
|
-
run:
|
27
|
-
bundle exec rspec
|
15
|
+
run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
@@ -1,64 +1,386 @@
|
|
1
|
-
# This is project specific rubocop configuration file.
|
2
|
-
# You can tweak project settings here
|
3
|
-
inherit_from:
|
4
|
-
- ./.rubocop.localch.yml
|
5
|
-
|
6
1
|
AllCops:
|
7
|
-
|
2
|
+
DisplayCopNames: true
|
3
|
+
DisplayStyleGuide: true
|
4
|
+
TargetRubyVersion: '2.7'
|
5
|
+
NewCops: enable
|
6
|
+
SuggestExtensions: false
|
8
7
|
Exclude:
|
8
|
+
- 'db/**/*'
|
9
|
+
- 'script/**/*'
|
10
|
+
- 'vendor/bundle/**/*'
|
11
|
+
- 'vendor/assets/**/*'
|
12
|
+
- 'bin/**/*'
|
13
|
+
- 'config/unicorn.rb'
|
14
|
+
- 'config/compass.rb'
|
15
|
+
- 'Rakefile'
|
16
|
+
- 'app/controllers/error_trap_controller.rb'
|
17
|
+
- 'app/controllers/hsts_controller.rb'
|
18
|
+
- 'spec/lib/util_spec.rb'
|
9
19
|
- vendor/**
|
10
20
|
- vendor/**/.*
|
11
21
|
|
22
|
+
require:
|
23
|
+
- rubocop-rspec
|
24
|
+
- rubocop-performance
|
25
|
+
|
26
|
+
Bundler/OrderedGems:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Lint/SuppressedException:
|
30
|
+
Exclude:
|
31
|
+
- spec/**/*
|
32
|
+
|
33
|
+
Lint/UriEscapeUnescape:
|
34
|
+
Enabled: false
|
35
|
+
|
12
36
|
Lint/IneffectiveAccessModifier:
|
13
37
|
Enabled: false
|
14
38
|
|
15
|
-
|
39
|
+
Lint/ConstantDefinitionInBlock:
|
16
40
|
Enabled: false
|
17
41
|
|
18
|
-
|
42
|
+
Lint/ToJSON:
|
19
43
|
Enabled: false
|
20
44
|
|
21
|
-
|
45
|
+
Lint/NonDeterministicRequireOrder:
|
22
46
|
Enabled: false
|
23
47
|
|
24
|
-
|
48
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
25
49
|
Enabled: false
|
26
50
|
|
27
|
-
|
51
|
+
Lint/EmptyBlock: # (new in 1.1)
|
28
52
|
Enabled: false
|
29
53
|
|
30
|
-
|
54
|
+
Lint/EmptyClass: # (new in 1.3)
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Lint/OrAssignmentToConstant: # (new in 1.9)
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Lint/SymbolConversion: # (new in 1.9)
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Metrics/AbcSize:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Metrics/MethodLength:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Metrics/CyclomaticComplexity:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Metrics/PerceivedComplexity:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Metrics/ClassLength:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Metrics/ModuleLength:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
Metrics/BlockLength:
|
82
|
+
Enabled: false
|
83
|
+
|
84
|
+
Metrics/ParameterLists:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
Metrics/BlockNesting:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
Layout/MultilineOperationIndentation:
|
91
|
+
EnforcedStyle: indented
|
92
|
+
|
93
|
+
Layout/DotPosition:
|
94
|
+
EnforcedStyle: leading
|
95
|
+
|
96
|
+
Layout/ParameterAlignment:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
Layout/EmptyLinesAroundClassBody:
|
100
|
+
Enabled: false
|
101
|
+
|
102
|
+
Layout/FirstArrayElementIndentation:
|
103
|
+
EnforcedStyle: consistent
|
104
|
+
|
105
|
+
Layout/MultilineMethodCallIndentation:
|
106
|
+
EnforcedStyle: indented
|
107
|
+
|
108
|
+
Layout/MultilineMethodCallBraceLayout:
|
109
|
+
EnforcedStyle: symmetrical
|
110
|
+
|
111
|
+
Layout/EmptyLinesAroundBlockBody:
|
112
|
+
EnforcedStyle: no_empty_lines
|
113
|
+
|
114
|
+
Layout/HeredocIndentation:
|
115
|
+
Enabled: false
|
116
|
+
|
117
|
+
Layout/MultilineArrayBraceLayout:
|
118
|
+
EnforcedStyle: symmetrical
|
119
|
+
|
120
|
+
Layout/MultilineHashBraceLayout:
|
121
|
+
EnforcedStyle: symmetrical
|
122
|
+
|
123
|
+
Layout/LineLength:
|
124
|
+
Enabled: false
|
125
|
+
|
126
|
+
Style/RescueStandardError:
|
127
|
+
Enabled: false
|
128
|
+
|
129
|
+
Style/StringLiterals:
|
130
|
+
Enabled: false
|
131
|
+
|
132
|
+
Style/NumericLiterals:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
Style/WordArray:
|
136
|
+
Enabled: false
|
137
|
+
|
138
|
+
Style/Next:
|
139
|
+
Enabled: false
|
140
|
+
|
141
|
+
Style/PercentLiteralDelimiters:
|
142
|
+
Enabled: false
|
143
|
+
|
144
|
+
Style/GlobalVars:
|
145
|
+
Enabled: false
|
146
|
+
|
147
|
+
Style/CommentAnnotation:
|
148
|
+
Enabled: false
|
149
|
+
|
150
|
+
Style/SymbolProc:
|
151
|
+
Enabled: false
|
152
|
+
|
153
|
+
Style/DoubleNegation:
|
154
|
+
Enabled: false
|
155
|
+
|
156
|
+
Style/FormatString:
|
157
|
+
Enabled: false
|
158
|
+
|
159
|
+
Style/AsciiComments:
|
160
|
+
Enabled: false
|
161
|
+
|
162
|
+
Style/BarePercentLiterals:
|
163
|
+
Enabled: false
|
164
|
+
|
165
|
+
Style/SingleLineBlockParams:
|
166
|
+
Enabled: false
|
167
|
+
|
168
|
+
Style/MultilineBlockChain:
|
169
|
+
Enabled: false
|
170
|
+
|
171
|
+
Style/RedundantCapitalW:
|
172
|
+
Enabled: false
|
173
|
+
|
174
|
+
Style/RedundantPercentQ:
|
175
|
+
Enabled: false
|
176
|
+
|
177
|
+
Style/BlockDelimiters:
|
178
|
+
Exclude:
|
179
|
+
- spec/**/*
|
180
|
+
|
181
|
+
Style/IfUnlessModifier:
|
182
|
+
Enabled: false
|
183
|
+
|
184
|
+
Style/ClassAndModuleChildren:
|
185
|
+
Enabled: false
|
186
|
+
|
187
|
+
Style/Documentation:
|
188
|
+
Enabled: false
|
189
|
+
|
190
|
+
Style/GuardClause:
|
191
|
+
Enabled: false
|
192
|
+
|
193
|
+
|
194
|
+
Style/NegatedIf:
|
195
|
+
Enabled: false
|
196
|
+
|
197
|
+
Style/MutableConstant:
|
198
|
+
Enabled: false
|
199
|
+
|
200
|
+
Style/ConditionalAssignment:
|
31
201
|
Enabled: false
|
32
202
|
|
33
203
|
Style/Lambda:
|
34
204
|
Enabled: false
|
35
205
|
|
36
|
-
|
206
|
+
Style/SymbolArray:
|
37
207
|
Enabled: false
|
38
208
|
|
39
|
-
|
209
|
+
Style/HashSyntax:
|
210
|
+
EnforcedStyle: ruby19
|
211
|
+
|
212
|
+
Style/FormatStringToken:
|
213
|
+
Enabled: false
|
214
|
+
|
215
|
+
Style/TernaryParentheses:
|
216
|
+
EnforcedStyle: require_parentheses_when_complex
|
217
|
+
|
218
|
+
Style/PerlBackrefs:
|
219
|
+
Enabled: false
|
220
|
+
|
221
|
+
Style/RegexpLiteral:
|
222
|
+
AllowInnerSlashes: false
|
223
|
+
Exclude:
|
224
|
+
- spec/**/*
|
225
|
+
|
226
|
+
Style/BlockComments:
|
227
|
+
Enabled: false
|
228
|
+
|
229
|
+
Style/RedundantParentheses:
|
230
|
+
Enabled: false
|
231
|
+
|
232
|
+
Style/NumericPredicate:
|
40
233
|
Enabled: false
|
41
234
|
|
42
235
|
Style/RedundantReturn:
|
43
236
|
Enabled: false
|
44
237
|
|
45
|
-
|
238
|
+
Style/EmptyMethod:
|
239
|
+
EnforcedStyle: compact
|
240
|
+
|
241
|
+
Style/ExpandPathArguments:
|
46
242
|
Enabled: false
|
47
243
|
|
48
244
|
Style/FrozenStringLiteralComment:
|
49
245
|
Enabled: true
|
50
246
|
|
51
|
-
|
247
|
+
Style/RedundantBegin:
|
248
|
+
Enabled: false
|
249
|
+
|
250
|
+
Style/RedundantAssignment:
|
251
|
+
Enabled: false
|
252
|
+
|
253
|
+
Style/SingleArgumentDig:
|
254
|
+
Enabled: false
|
255
|
+
|
256
|
+
Style/OptionalBooleanParameter:
|
257
|
+
Enabled: false
|
258
|
+
|
259
|
+
Style/CaseLikeIf:
|
260
|
+
Enabled: false
|
261
|
+
|
262
|
+
Style/HashEachMethods:
|
263
|
+
Enabled: false
|
264
|
+
|
265
|
+
Style/HashConversion: # (new in 1.10)
|
266
|
+
Enabled: false
|
267
|
+
|
268
|
+
Style/NilLambda: # (new in 1.3)
|
269
|
+
Enabled: false
|
270
|
+
|
271
|
+
RSpec/DescribeClass:
|
272
|
+
Exclude:
|
273
|
+
- spec/views/**/*
|
274
|
+
- spec/routing/**/*
|
275
|
+
- spec/requests/**/*
|
276
|
+
- spec/features/**/*
|
277
|
+
|
278
|
+
RSpec/FilePath:
|
279
|
+
Enabled: false
|
280
|
+
|
281
|
+
RSpec/NamedSubject:
|
282
|
+
Enabled: false
|
283
|
+
|
284
|
+
RSpec/LeadingSubject:
|
285
|
+
Enabled: false
|
286
|
+
|
287
|
+
RSpec/ExpectInHook:
|
288
|
+
Enabled: false
|
289
|
+
|
290
|
+
RSpec/ReturnFromStub:
|
291
|
+
Enabled: false
|
292
|
+
|
293
|
+
RSpec/SubjectStub:
|
294
|
+
Enabled: false
|
295
|
+
|
296
|
+
RSpec/EmptyLineAfterSubject:
|
297
|
+
Enabled: false
|
298
|
+
|
299
|
+
RSpec/LetSetup:
|
300
|
+
Enabled: false
|
301
|
+
|
302
|
+
RSpec/ImplicitExpect:
|
303
|
+
EnforcedStyle: is_expected
|
304
|
+
|
305
|
+
RSpec/ScatteredLet:
|
306
|
+
Enabled: false
|
307
|
+
|
308
|
+
RSpec/ContextWording:
|
309
|
+
Enabled: false
|
310
|
+
|
311
|
+
RSpec/AnyInstance:
|
312
|
+
Enabled: false
|
313
|
+
|
314
|
+
RSpec/DescribedClass:
|
315
|
+
Enabled: false
|
316
|
+
|
317
|
+
RSpec/MultipleExpectations:
|
318
|
+
Enabled: false
|
319
|
+
|
320
|
+
RSpec/HookArgument:
|
321
|
+
Enabled: false
|
322
|
+
|
323
|
+
RSpec/ExampleLength:
|
324
|
+
Enabled: false
|
325
|
+
|
326
|
+
RSpec/NestedGroups:
|
327
|
+
Enabled: false
|
328
|
+
|
329
|
+
RSpec/VerifiedDoubles:
|
330
|
+
Enabled: false
|
331
|
+
|
332
|
+
RSpec/InstanceVariable:
|
52
333
|
Enabled: false
|
53
334
|
|
54
335
|
RSpec/MessageSpies:
|
55
336
|
Enabled: false
|
56
337
|
|
57
|
-
RSpec/
|
338
|
+
RSpec/FactoryBot/CreateList:
|
58
339
|
Enabled: false
|
59
340
|
|
60
|
-
|
61
|
-
|
341
|
+
RSpec/BeforeAfterAll:
|
342
|
+
Enabled: false
|
62
343
|
|
63
344
|
RSpec/RepeatedExample:
|
64
345
|
Enabled: false
|
346
|
+
|
347
|
+
Naming/FileName:
|
348
|
+
Exclude:
|
349
|
+
- Gemfile
|
350
|
+
- Brewfile
|
351
|
+
- Guardfile
|
352
|
+
|
353
|
+
Naming/AccessorMethodName:
|
354
|
+
Exclude:
|
355
|
+
- spec/support/pages/**/*
|
356
|
+
|
357
|
+
Naming/VariableNumber:
|
358
|
+
Enabled: false
|
359
|
+
|
360
|
+
Naming/MethodParameterName:
|
361
|
+
Enabled: false
|
362
|
+
|
363
|
+
Naming/MemoizedInstanceVariableName:
|
364
|
+
Enabled: false
|
365
|
+
|
366
|
+
|
367
|
+
Performance/StringReplacement:
|
368
|
+
Enabled: false
|
369
|
+
|
370
|
+
Performance/TimesMap:
|
371
|
+
Enabled: false
|
372
|
+
|
373
|
+
Performance/RedundantBlockCall:
|
374
|
+
Enabled: false
|
375
|
+
|
376
|
+
Performance/RedundantMatch:
|
377
|
+
Enabled: false
|
378
|
+
|
379
|
+
Performance/RedundantMerge:
|
380
|
+
Enabled: false
|
381
|
+
|
382
|
+
Performance/Casecmp:
|
383
|
+
Enabled: false
|
384
|
+
|
385
|
+
Performance/StringInclude: # (new in 1.7)
|
386
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -51,6 +51,7 @@ use it like:
|
|
51
51
|
* [Configuration](#configuration)
|
52
52
|
* [Configuring endpoints](#configuring-endpoints)
|
53
53
|
* [Configuring placeholders](#configuring-placeholders)
|
54
|
+
* [Configuring scrubs](#configuring-scrubs)
|
54
55
|
* [Interceptors](#interceptors)
|
55
56
|
* [Quick start: Configure/Enable Interceptors](#quick-start-configureenable-interceptors)
|
56
57
|
* [Interceptors on local request level](#interceptors-on-local-request-level)
|
@@ -491,6 +492,50 @@ You can configure global placeholders, that are used when generating urls from u
|
|
491
492
|
LHC.get(:feedbacks) # http://datastore/v2/feedbacks
|
492
493
|
```
|
493
494
|
|
495
|
+
### Configuring scrubs
|
496
|
+
|
497
|
+
You can filter out sensitive request data from your log files and rollbar by appending them to `LHS.config.scrubs`. These values will be marked `[FILTERED]` in the log and on rollbar. Also nested parameters are being filtered.
|
498
|
+
The scrubbing configuration affects all request done by LHC independent of the endpoint. You can scrub any attribute within `params`, `headers` or `body`. For auth you either can choose `:bearer` or `:auth` (default is both).
|
499
|
+
|
500
|
+
LHS scrubs per default:
|
501
|
+
- Bearer Token within the request header
|
502
|
+
- Basic Auth username and password within the request header
|
503
|
+
- password and password_confirmation within the request body
|
504
|
+
|
505
|
+
Enhance the default scrubbing by pushing the name of the parameter, which should get scrubbed, as string to the existing configuration.
|
506
|
+
You can also add multiple parameters at once by pushing multiple strings.
|
507
|
+
|
508
|
+
Example:
|
509
|
+
```ruby
|
510
|
+
LHC.configure do |c|
|
511
|
+
c.scrubs[:params] << 'api_key'
|
512
|
+
c.scrubs[:body].push('user_token', 'secret_key')
|
513
|
+
end
|
514
|
+
```
|
515
|
+
|
516
|
+
For disabling scrubbing, add following configuration:
|
517
|
+
```ruby
|
518
|
+
LHC.configure do |c|
|
519
|
+
c.scrubs = {}
|
520
|
+
end
|
521
|
+
```
|
522
|
+
|
523
|
+
If you want to turn off `:bearer` or `:auth` scrubbing, then just overwrite the auth configuration.
|
524
|
+
|
525
|
+
Example:
|
526
|
+
```ruby
|
527
|
+
LHC.configure do |c|
|
528
|
+
c.scrubs[:auth] = [:bearer]
|
529
|
+
end
|
530
|
+
```
|
531
|
+
|
532
|
+
If your app has a different authentication strategy than Bearer Authentication or Basic Authentication then you can filter the data by scrubbing the whole header:
|
533
|
+
```ruby
|
534
|
+
LHC.configure do |c|
|
535
|
+
c.scrubs[:headers] << 'Authorization'
|
536
|
+
end
|
537
|
+
```
|
538
|
+
|
494
539
|
## Interceptors
|
495
540
|
|
496
541
|
To monitor and manipulate the HTTP communication done with LHC, you can define interceptors that follow the (Inteceptor Pattern)[https://en.wikipedia.org/wiki/Interceptor_pattern].
|
data/lhc.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ['lib']
|
21
21
|
|
22
22
|
s.requirements << 'Ruby >= 2.0.0'
|
23
|
+
s.required_ruby_version = '>= 2.7' # Needed for rubocop
|
23
24
|
|
24
25
|
s.add_dependency 'activesupport', '>= 5.2'
|
25
26
|
s.add_dependency 'addressable'
|
@@ -31,7 +32,8 @@ Gem::Specification.new do |s|
|
|
31
32
|
s.add_development_dependency 'rails', '>= 5.2'
|
32
33
|
s.add_development_dependency 'redis'
|
33
34
|
s.add_development_dependency 'rspec-rails', '>= 3.0.0'
|
34
|
-
s.add_development_dependency 'rubocop', '~> 0
|
35
|
+
s.add_development_dependency 'rubocop', '~> 1.0'
|
36
|
+
s.add_development_dependency 'rubocop-performance', '~> 1.0'
|
35
37
|
s.add_development_dependency 'rubocop-rspec', '~> 1.26.0'
|
36
38
|
s.add_development_dependency 'timecop'
|
37
39
|
s.add_development_dependency 'webmock'
|
data/lib/lhc/config.rb
CHANGED
@@ -5,14 +5,18 @@ require 'singleton'
|
|
5
5
|
class LHC::Config
|
6
6
|
include Singleton
|
7
7
|
|
8
|
+
attr_accessor :scrubs
|
9
|
+
|
8
10
|
def initialize
|
9
11
|
@endpoints = {}
|
10
12
|
@placeholders = {}
|
13
|
+
@scrubs = default_scrubs
|
11
14
|
end
|
12
15
|
|
13
16
|
def endpoint(name, url, options = {})
|
14
17
|
name = name.to_sym
|
15
18
|
raise 'Endpoint already exists for that name' if @endpoints[name]
|
19
|
+
|
16
20
|
@endpoints[name] = LHC::Endpoint.new(url, options)
|
17
21
|
end
|
18
22
|
|
@@ -23,6 +27,7 @@ class LHC::Config
|
|
23
27
|
def placeholder(name, value)
|
24
28
|
name = name.to_sym
|
25
29
|
raise 'Placeholder already exists for that name' if @placeholders[name]
|
30
|
+
|
26
31
|
@placeholders[name] = value
|
27
32
|
end
|
28
33
|
|
@@ -36,12 +41,23 @@ class LHC::Config
|
|
36
41
|
|
37
42
|
def interceptors=(interceptors)
|
38
43
|
raise 'Default interceptors already set and can only be set once' if @interceptors
|
44
|
+
|
39
45
|
@interceptors = interceptors
|
40
46
|
end
|
41
47
|
|
48
|
+
def default_scrubs
|
49
|
+
{
|
50
|
+
auth: [:bearer, :basic],
|
51
|
+
params: [],
|
52
|
+
headers: [],
|
53
|
+
body: ['password', 'password_confirmation']
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
42
57
|
def reset
|
43
58
|
@endpoints = {}
|
44
59
|
@placeholders = {}
|
45
60
|
@interceptors = nil
|
61
|
+
@scrubs = default_scrubs
|
46
62
|
end
|
47
63
|
end
|
data/lib/lhc/endpoint.rb
CHANGED
@@ -55,6 +55,7 @@ class LHC::Endpoint
|
|
55
55
|
# Example: {+datastore}/contracts/{id} == http://local.ch/contracts/1
|
56
56
|
def match?(url)
|
57
57
|
return true if url == uri.pattern
|
58
|
+
|
58
59
|
match_data = match_data(url)
|
59
60
|
return false if match_data.nil?
|
60
61
|
|
@@ -75,6 +76,7 @@ class LHC::Endpoint
|
|
75
76
|
def values_as_params(url)
|
76
77
|
match_data = match_data(url)
|
77
78
|
return if match_data.nil?
|
79
|
+
|
78
80
|
Hash[match_data.variables.map(&:to_sym).zip(match_data.values)]
|
79
81
|
end
|
80
82
|
|
@@ -103,6 +105,7 @@ class LHC::Endpoint
|
|
103
105
|
# creates params according to template
|
104
106
|
def self.values_as_params(template, url)
|
105
107
|
raise("#{url} does not match the template: #{template}") if !match?(url, template)
|
108
|
+
|
106
109
|
new(template).values_as_params(url)
|
107
110
|
end
|
108
111
|
|
data/lib/lhc/error.rb
CHANGED
@@ -43,6 +43,7 @@ class LHC::Error < StandardError
|
|
43
43
|
|
44
44
|
def self.find(response)
|
45
45
|
return LHC::Timeout if response.timeout?
|
46
|
+
|
46
47
|
status_code = response.code.to_s[0..2].to_i
|
47
48
|
error = map[status_code]
|
48
49
|
error ||= LHC::UnknownError
|
@@ -65,13 +66,14 @@ class LHC::Error < StandardError
|
|
65
66
|
|
66
67
|
def to_s
|
67
68
|
return response.to_s unless response.is_a?(LHC::Response)
|
69
|
+
|
68
70
|
request = response.request
|
69
71
|
return unless request.is_a?(LHC::Request)
|
70
72
|
|
71
73
|
debug = []
|
72
74
|
debug << [request.method, request.url].map { |str| self.class.fix_invalid_encoding(str) }.join(' ')
|
73
|
-
debug << "Options: #{request.
|
74
|
-
debug << "Headers: #{request.
|
75
|
+
debug << "Options: #{request.scrubbed_options}"
|
76
|
+
debug << "Headers: #{request.scrubbed_headers}"
|
75
77
|
debug << "Response Code: #{response.code} (#{response.options[:return_code]})"
|
76
78
|
debug << "Response Options: #{response.options}"
|
77
79
|
debug << response.body
|
@@ -16,6 +16,7 @@ class LHC::Auth < LHC::Interceptor
|
|
16
16
|
def after_response
|
17
17
|
return unless configuration_correct?
|
18
18
|
return unless reauthenticate?
|
19
|
+
|
19
20
|
reauthenticate!
|
20
21
|
end
|
21
22
|
|
@@ -29,7 +30,7 @@ class LHC::Auth < LHC::Interceptor
|
|
29
30
|
def basic_authentication!
|
30
31
|
auth = auth_options[:basic]
|
31
32
|
credentials = "#{auth[:username]}:#{auth[:password]}"
|
32
|
-
|
33
|
+
set_basic_authorization_header(Base64.strict_encode64(credentials).chomp)
|
33
34
|
end
|
34
35
|
|
35
36
|
def bearer_authentication!
|
@@ -43,7 +44,13 @@ class LHC::Auth < LHC::Interceptor
|
|
43
44
|
request.headers['Authorization'] = value
|
44
45
|
end
|
45
46
|
|
47
|
+
def set_basic_authorization_header(base_64_encoded_credentials)
|
48
|
+
request.options[:auth][:basic] = request.options[:auth][:basic].merge(base_64_encoded_credentials: base_64_encoded_credentials)
|
49
|
+
set_authorization_header("Basic #{base_64_encoded_credentials}")
|
50
|
+
end
|
51
|
+
|
46
52
|
def set_bearer_authorization_header(token)
|
53
|
+
request.options[:auth] = request.options[:auth].merge(bearer_token: token)
|
47
54
|
set_authorization_header("Bearer #{token}")
|
48
55
|
end
|
49
56
|
# rubocop:enable Style/AccessorMethodName
|
@@ -86,11 +93,13 @@ class LHC::Auth < LHC::Interceptor
|
|
86
93
|
|
87
94
|
def refresh_client_token?
|
88
95
|
return true if refresh_client_token_option.is_a?(Proc)
|
96
|
+
|
89
97
|
warn("[WARNING] The given refresh_client_token must be a Proc for reauthentication.")
|
90
98
|
end
|
91
99
|
|
92
100
|
def retry_interceptor?
|
93
101
|
return true if all_interceptor_classes.include?(LHC::Retry) && all_interceptor_classes.index(LHC::Retry) > all_interceptor_classes.index(self.class)
|
102
|
+
|
94
103
|
warn("[WARNING] Your interceptors must include LHC::Retry after LHC::Auth.")
|
95
104
|
end
|
96
105
|
end
|