active_record_api-request 0.3.14 → 0.3.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3ae3c4b01a5fcdf15167f2155ce8eb91b6ddeb09be9fbdd1c5b3c6e8ff3c32e
4
- data.tar.gz: 0675d8d722aec937f73b6cd197fe8242a2f1c2e458a415831722bce48691aa1c
3
+ metadata.gz: 4bf85446f65a2cdec067be322385b94966bdf4f6cb457fe7914a118e563b2a9e
4
+ data.tar.gz: 10b170ac1aeed7d5b95cb87fef0bba7e3975715413395cb2578d8222941f70aa
5
5
  SHA512:
6
- metadata.gz: 04a53111d32529814b3f3ac60cff067cd670672e77fd86f380161cf012c36ef1f2994a1208de4f94f6d8f3cb0436c0470d7591b844369236650dc80dc135a735
7
- data.tar.gz: 65bf626a5fe19420fd6924ecc44caaa2da90e027e3fb327fccc44d935412f3904f2865702ebb7173cbe3e96c6f80cca9e665f84d5f6994c92a10529ef982ad85
6
+ metadata.gz: 7b83ec91607f9c2e6d0df1319f0cb0aeb9e0d1e0d740655c8660e9ac57c77f29e62f887bb4e5ca4066600fae71191f904260d83812889ca12dd09492d7e408b1
7
+ data.tar.gz: 3ef8d895de630379c8e35afbc3a0d8bdeefd3318854ab97ff1cc524bef7270dec0661029829f375813be43393462daacfd34c7c91d24d6a5ebe0d438c5b54cc9
@@ -5,7 +5,7 @@ require 'faraday-http-cache'
5
5
  module ActiveRecordApi
6
6
  module Request
7
7
  class Connection < Credentials
8
- attr_accessor :debug, :path, :cache_store
8
+ attr_accessor :debug, :path, :cache_store, :timeout
9
9
  attr_writer :full_url
10
10
 
11
11
  def authenticated_connection
@@ -16,7 +16,7 @@ module ActiveRecordApi
16
16
  def connection
17
17
  @connection ||= Faraday.new do |builder|
18
18
  builder.options[:open_timeout] = 2
19
- builder.options[:timeout] = 5
19
+ builder.options[:timeout] = timeout || 5
20
20
  builder.request :json
21
21
  builder.request :url_encoded
22
22
  builder.request :retry, max: 5, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2, exceptions: [ActiveRecordApi::Request::AuthError]
@@ -24,7 +24,7 @@ module ActiveRecordApi
24
24
  builder.use :http_cache, http_cache_options
25
25
  builder.use FaradayFollowNextLinks, 5
26
26
  builder.use FaradayMiddleware::FollowRedirects, standards_compliant: true
27
- builder.use FaradayAuthTokenRetry, credentials: credentials, host: host, token_path: token_path, debug: debug
27
+ builder.use FaradayAuthTokenRetry, credentials: credentials, host: host, token_path: token_path, debug: debug, timeout: timeout
28
28
  builder.response :json, content_type: /\bjson$/
29
29
  builder.response :raise_error
30
30
  builder.response :logger if debug
@@ -6,14 +6,15 @@ module ActiveRecordApi
6
6
  class FaradayAuthTokenRetry < Faraday::Middleware
7
7
  AUTH_KEY = 'Authorization'.freeze
8
8
 
9
- attr_reader :credentials, :host, :token_path, :debug
9
+ attr_reader :credentials, :host, :token_path, :debug, :timeout
10
10
 
11
- def initialize(app, credentials: nil, host: nil, token_path: nil, debug: false)
11
+ def initialize(app, credentials: nil, host: nil, token_path: nil, debug: false, timeout: nil)
12
12
  super(app)
13
13
  @credentials = credentials
14
14
  @host = host
15
15
  @token_path = token_path
16
16
  @debug = debug
17
+ @timeout = nil
17
18
  end
18
19
 
19
20
  def call(env)
@@ -42,7 +43,7 @@ module ActiveRecordApi
42
43
  end
43
44
 
44
45
  def retrieve_token
45
- token_cache.fetch_token Proc.new { TokenRetriever.new(credentials: credentials, host: host, token_path: token_path, debug: debug).fetch_token }
46
+ token_cache.fetch_token Proc.new { TokenRetriever.new(credentials: credentials, host: host, token_path: token_path, debug: debug, timeout: timeout).fetch_token }
46
47
  end
47
48
 
48
49
  def token_cache
@@ -3,7 +3,7 @@ module ActiveRecordApi
3
3
  module Request
4
4
  class TokenCache
5
5
  include ActiveAttr::Model
6
- attr_accessor :debug
6
+ attr_accessor :debug
7
7
 
8
8
  def flush
9
9
  return unless defined? AUTH_REDIS_POOL
@@ -33,14 +33,14 @@ module ActiveRecordApi
33
33
  @token = nil
34
34
  @retry = 0
35
35
  while @token.nil? && @retry < 5
36
- @retry += 1
37
36
  @token = @redis_client.get('auth_token')
38
37
  debug_log "retry ##{@retry}"
39
38
  debug_log "found token: #{@token}"
39
+ @retry += 1
40
40
  if @token.nil? || session_missing_for?(@token)
41
41
  if acquire_lock
42
42
  begin
43
- debug_log "acquired lock and fetching token for cache"
43
+ debug_log 'acquired lock and fetching token for cache'
44
44
  @token = token_proc.call
45
45
  raise "no token returned! #{@token}" if @token.nil?
46
46
  @redis_client.set 'auth_token', @token
@@ -70,7 +70,7 @@ module ActiveRecordApi
70
70
  return nil
71
71
  end
72
72
 
73
- @redis_session ||= Redis.new({url: "redis://#{ENV['REDIS_SESSION_HOST']}", db: ENV['REDIS_SESSION']})
73
+ @redis_session ||= Redis.new({ url: "redis://#{ENV['REDIS_SESSION_HOST']}", db: ENV['REDIS_SESSION'] })
74
74
  end
75
75
 
76
76
  def session_missing_for?(token)
@@ -86,7 +86,7 @@ module ActiveRecordApi
86
86
  end
87
87
 
88
88
  def acquire_lock
89
- @redis_client.set 'auth_token_lock', unique_key, nx: true, ex: 60
89
+ @redis_client.set 'auth_token_lock', unique_key, nx: true, ex: 8
90
90
  current_lock_value = @redis_client.get 'auth_token_lock'
91
91
  debug_log "#{current_lock_value} == #{unique_key}"
92
92
  current_lock_value == unique_key
@@ -102,4 +102,5 @@ module ActiveRecordApi
102
102
  end
103
103
  end
104
104
  end
105
+
105
106
  #:nocov:#
@@ -1,5 +1,5 @@
1
1
  module ActiveRecordApi
2
2
  module Request
3
- VERSION = '0.3.14'.freeze
3
+ VERSION = '0.3.18'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_api-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Full Measure Education
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr