erp_integration 0.55.0 → 0.56.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/.ruby-version +1 -1
- data/README.md +3 -0
- data/lib/erp_integration/configuration.rb +11 -1
- data/lib/erp_integration/fulfil/client.rb +8 -1
- data/lib/erp_integration/middleware/api_keys_rotation.rb +9 -2
- data/lib/erp_integration/middleware/logger.rb +1 -1
- data/lib/erp_integration/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55974d4e2c7b76ca461070fe996522e0b7fa06391760549f8959000ed07b2a9e
|
4
|
+
data.tar.gz: 43683efd68525709be0fcba1537051830f52d7c0663779a7ab5b4c24b0a6e2e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0943cc3b1047ef17259a1eeb039fdd65ee74cb3ebc6911ff431162f60058b89d8e26e3f742028b261c2979c304aab4b1a0fd155e5d72fd0f0063a3a3afa351f
|
7
|
+
data.tar.gz: 4a06481fb232e9ad506c0d038af4114169546d622eecec0e6d5b03877e6f85648777c278728f87f6cae52c3e695f382ec34e4c1a2adcfadf0d9af23fc354374f
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.2
|
data/README.md
CHANGED
@@ -44,10 +44,13 @@ end
|
|
44
44
|
To set up API key rotation, configure multiple keys.
|
45
45
|
Every time a Fulfil client receives a `404` or `429`, it will rotate an API key.
|
46
46
|
|
47
|
+
You can set the `api_key_rotation_threshold` option to automatically change the API key when requests are running low. If you don't want to use the `x-ratelimit-remaining` response header for rotation, set the `api_key_rotation_threshold` to 0 or ignore it. The minimum threshold is 1, meaning the key will rotate when there are 0 remaining requests.
|
48
|
+
|
47
49
|
```erb
|
48
50
|
# config/initializers/erp_integration.rb
|
49
51
|
ErpIntegration.configure do |config|
|
50
52
|
config.fulfil_api_keys = ['<your-api-key1>', '<your-api-key2>']
|
53
|
+
config.api_key_rotation_threshold = 1
|
51
54
|
...
|
52
55
|
end
|
53
56
|
```
|
@@ -22,6 +22,12 @@ module ErpIntegration
|
|
22
22
|
# @return [String] The base URL for Fulfil.
|
23
23
|
attr_accessor :fulfil_base_url
|
24
24
|
|
25
|
+
# The `api_key_rotation_threshold` is used by the `ApiKeysRotation` middleware
|
26
|
+
# it will rotate the API key when the remaining requests are less than the threshold.
|
27
|
+
#
|
28
|
+
# Set the `api_key_rotation_threshold` to 0, it you don't want to rotate by the remaining requests.
|
29
|
+
attr_reader :api_key_rotation_threshold
|
30
|
+
|
25
31
|
# Allows configuring an adapter for the `BillOfMaterial` resource. When
|
26
32
|
# none is configured, it will default to Fulfil.
|
27
33
|
# @return [Symbol] The configured adapter for the bill_of_material.
|
@@ -172,6 +178,10 @@ module ErpIntegration
|
|
172
178
|
end
|
173
179
|
end
|
174
180
|
|
181
|
+
def api_key_rotation_threshold=(threshold)
|
182
|
+
@api_key_rotation_threshold = threshold || 0
|
183
|
+
end
|
184
|
+
|
175
185
|
def carrier_adapter
|
176
186
|
@carrier_adapter || :fulfil
|
177
187
|
end
|
@@ -309,7 +319,7 @@ module ErpIntegration
|
|
309
319
|
# Sets the rate limiters that will be used
|
310
320
|
# @raise [MissingMethodError] if the rate limiter object doesn't respond to the required methods.
|
311
321
|
def rate_limiters=(rate_limiters)
|
312
|
-
@rate_limiters = rate_limiters.each { |limiter| RateLimiter.validate!(limiter) }
|
322
|
+
@rate_limiters = (rate_limiters || []).each { |limiter| RateLimiter.validate!(limiter) }
|
313
323
|
end
|
314
324
|
end
|
315
325
|
|
@@ -33,7 +33,7 @@ module ErpIntegration
|
|
33
33
|
# Custom error handling for the error response
|
34
34
|
faraday.use ErpIntegration::Middleware::ErrorHandling
|
35
35
|
# Custom middleware for rotating API keys
|
36
|
-
faraday.use ErpIntegration::Middleware::ApiKeysRotation,
|
36
|
+
faraday.use ErpIntegration::Middleware::ApiKeysRotation, rotation_options
|
37
37
|
# Custom middleware for logging requests and responses
|
38
38
|
faraday.use ErpIntegration::Middleware::Logger, @logger if @logger
|
39
39
|
|
@@ -76,6 +76,13 @@ module ErpIntegration
|
|
76
76
|
'Content-Type': 'application/json'
|
77
77
|
}
|
78
78
|
end
|
79
|
+
|
80
|
+
def rotation_options
|
81
|
+
{
|
82
|
+
api_keys_pool: api_keys_pool,
|
83
|
+
rotation_theshold: ErpIntegration.config.api_key_rotation_threshold
|
84
|
+
}
|
85
|
+
end
|
79
86
|
end
|
80
87
|
end
|
81
88
|
end
|
@@ -20,14 +20,21 @@ module ErpIntegration
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def on_request(env)
|
23
|
-
env
|
23
|
+
env.request_headers['X-API-KEY'] = options[:api_keys_pool].current_key
|
24
24
|
end
|
25
25
|
|
26
26
|
def on_complete(env)
|
27
|
-
return unless
|
27
|
+
return unless rotate?(env)
|
28
28
|
|
29
29
|
options[:api_keys_pool].rotate_key!
|
30
30
|
end
|
31
|
+
|
32
|
+
def rotate?(env)
|
33
|
+
return true if HTTP_ROTATE_CODES.include?(env.status)
|
34
|
+
return false unless env.response_headers['x-ratelimit-remaining'].present?
|
35
|
+
|
36
|
+
env.response_headers['x-ratelimit-remaining'].to_i < options[:rotation_theshold].to_i
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
@@ -19,7 +19,7 @@ module ErpIntegration
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def call(env)
|
22
|
-
api_key_fragment = sanitize_api_key(env
|
22
|
+
api_key_fragment = sanitize_api_key(env.request_headers['X-API-KEY']) || 'none'
|
23
23
|
|
24
24
|
if @logger.respond_to?(:tagged)
|
25
25
|
@logger.tagged("API key *#{api_key_fragment}") do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erp_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.56.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
@@ -369,7 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
369
369
|
- !ruby/object:Gem::Version
|
370
370
|
version: '0'
|
371
371
|
requirements: []
|
372
|
-
rubygems_version: 3.
|
372
|
+
rubygems_version: 3.5.6
|
373
373
|
signing_key:
|
374
374
|
specification_version: 4
|
375
375
|
summary: Connects Mejuri with third-party ERP vendors
|