iron_bank 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +1 -8
- data/.reek +4 -0
- data/lib/iron_bank/client.rb +3 -1
- data/lib/iron_bank/{response → faraday_middleware}/raise_error.rb +3 -2
- data/lib/iron_bank/faraday_middleware/retriable_auth.rb +34 -0
- data/lib/iron_bank/faraday_middleware.rb +15 -0
- data/lib/iron_bank/version.rb +1 -1
- data/lib/iron_bank.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd43b9afdef13f46266c47a431904c61180c1444c1a31e927a199f423ed0fd4d
|
4
|
+
data.tar.gz: 519f3d3d3b33047f8647f00d5480e33c0c7d626656c458082e01d2b975875275
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b3367c199eec9ae32daaa5c444f8c578c8d14f639688c05b97fadffd9504df7a502d403f49ea8fc1650c61ab50b698928f2c9f51826e821633b019e4b5cea01
|
7
|
+
data.tar.gz: 01a91a2311290dbbb7fdffe7203f94d5c33e26124b5ad19a9b568ae3f6f4144f4bbfecec29a7b88d3b5f6d7059c31f18c80827b8f5a6db1f039680a537cc5a3a
|
@@ -1,5 +1,3 @@
|
|
1
|
-
cc: :whale2: @zendesk/billing
|
2
|
-
|
3
1
|
### Description
|
4
2
|
Describe what your changes are and what is the motivation behind them.
|
5
3
|
|
@@ -11,10 +9,5 @@ to be aware of.
|
|
11
9
|
- [ ] TODO item before it can be reviewed and/or merged
|
12
10
|
- [ ] Another TODO item
|
13
11
|
|
14
|
-
### References
|
15
|
-
- JIRA ticket or PR link
|
16
|
-
- Another JIRA ticket or PR link
|
17
|
-
|
18
12
|
### Risks
|
19
|
-
|
20
|
-
profile of the change.
|
13
|
+
Use **High**, **Medium**, or **Low** to indicate risk profile of the change.
|
data/.reek
CHANGED
data/lib/iron_bank/client.rb
CHANGED
@@ -44,8 +44,10 @@ module IronBank
|
|
44
44
|
@connection ||= Faraday.new(faraday_config) do |conn|
|
45
45
|
conn.use :ddtrace, open_tracing_options if open_tracing_enabled?
|
46
46
|
conn.use instrumenter, instrumenter_options if instrumenter
|
47
|
-
conn.use
|
47
|
+
conn.use :raise_error
|
48
48
|
conn.request :json
|
49
|
+
conn.request :retry, max: 2, retry_statuses: [401]
|
50
|
+
conn.request :retriable_auth, auth
|
49
51
|
conn.response :logger, IronBank.logger
|
50
52
|
conn.response :json, content_type: /\bjson$/
|
51
53
|
conn.adapter Faraday.default_adapter
|
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# IronBank main module
|
3
4
|
module IronBank
|
4
|
-
# Faraday
|
5
|
-
module
|
5
|
+
# IronBank Faraday middleware module
|
6
|
+
module FaradayMiddleware
|
6
7
|
# This class raises an exception based on the HTTP status code and the
|
7
8
|
# `success` flag (if present in the response) from Zuora.
|
8
9
|
class RaiseError < Faraday::Response::Middleware
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# IronBank main module
|
4
|
+
module IronBank
|
5
|
+
# IronBank Faraday middleware module
|
6
|
+
module FaradayMiddleware
|
7
|
+
# This middleware reauthorize the request on unauthorized request
|
8
|
+
class RetriableAuth < Faraday::Middleware
|
9
|
+
def initialize(app, auth)
|
10
|
+
@auth = auth
|
11
|
+
super(app)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
@env = env
|
16
|
+
renew_auth_header if env.status == 401
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :auth, :env
|
24
|
+
|
25
|
+
def renew_auth_header
|
26
|
+
auth.renew_session
|
27
|
+
|
28
|
+
# The :retry middleware use cached request's headers which doesn't retry
|
29
|
+
# the request headers automatically
|
30
|
+
env.request_headers = env.request_headers.merge(auth.header)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# IronBank main module
|
4
|
+
module IronBank
|
5
|
+
# IronBank Faraday middleware module
|
6
|
+
module FaradayMiddleware
|
7
|
+
if Faraday::Middleware.respond_to? :register_middleware
|
8
|
+
Faraday::Middleware.register_middleware \
|
9
|
+
raise_error: -> { RaiseError }
|
10
|
+
|
11
|
+
Faraday::Request.register_middleware \
|
12
|
+
retriable_auth: -> { RetriableAuth }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/iron_bank/version.rb
CHANGED
data/lib/iron_bank.rb
CHANGED
@@ -57,7 +57,9 @@ require 'iron_bank/utils'
|
|
57
57
|
require 'iron_bank/version'
|
58
58
|
require 'iron_bank/csv'
|
59
59
|
require 'iron_bank/error'
|
60
|
-
require 'iron_bank/
|
60
|
+
require 'iron_bank/faraday_middleware/raise_error'
|
61
|
+
require 'iron_bank/faraday_middleware/retriable_auth'
|
62
|
+
require 'iron_bank/faraday_middleware'
|
61
63
|
|
62
64
|
# Helpers
|
63
65
|
require 'iron_bank/open_tracing'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mickael Pham
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-10-
|
14
|
+
date: 2018-10-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bump
|
@@ -319,6 +319,9 @@ files:
|
|
319
319
|
- lib/iron_bank/describe/tenant.rb
|
320
320
|
- lib/iron_bank/endpoint.rb
|
321
321
|
- lib/iron_bank/error.rb
|
322
|
+
- lib/iron_bank/faraday_middleware.rb
|
323
|
+
- lib/iron_bank/faraday_middleware/raise_error.rb
|
324
|
+
- lib/iron_bank/faraday_middleware/retriable_auth.rb
|
322
325
|
- lib/iron_bank/instrumentation.rb
|
323
326
|
- lib/iron_bank/local.rb
|
324
327
|
- lib/iron_bank/local_records.rb
|
@@ -354,7 +357,6 @@ files:
|
|
354
357
|
- lib/iron_bank/resources/rate_plan_charge_tier.rb
|
355
358
|
- lib/iron_bank/resources/subscription.rb
|
356
359
|
- lib/iron_bank/resources/usage.rb
|
357
|
-
- lib/iron_bank/response/raise_error.rb
|
358
360
|
- lib/iron_bank/schema.rb
|
359
361
|
- lib/iron_bank/utils.rb
|
360
362
|
- lib/iron_bank/version.rb
|