active_record_api-request 0.3.10 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07723fe8a0e7ef8a09d646992c72e93f334473b2f90a86e74af704beb1e8b054
|
4
|
+
data.tar.gz: a6a7af0c05535d34ee363e455b3f3162d27a9f8c9990e8e4349cded201e7335b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35c489d8cb6613b5b933b7a1cfdd258085a490d8cc76ad9efb908db450d27409566af8c05d5b83eabb0ddc07a57fd1c99ec9102c7b1a880979b50f6979b198b6
|
7
|
+
data.tar.gz: 4b4ad95507d5af98fc3a0061e3f97807d84f873c3de8e4d4bd6f35708fedbb5295e6a5f4295eda01e220d50c6df6957fcba86e628b747c23b41be81980b7c69d
|
@@ -27,15 +27,15 @@ module ActiveRecordApi
|
|
27
27
|
end
|
28
28
|
@app.call(env)
|
29
29
|
rescue Faraday::ClientError => error
|
30
|
-
if error.respond_to?(:response) && error.response.try(:[], :status)
|
30
|
+
if error.respond_to?(:response) && [401, 403].include?(error.response.try(:[], :status)) && env.request_headers['Retries'] != '5'
|
31
31
|
if @debug
|
32
|
-
Honeybadger.notify(error, {
|
32
|
+
Honeybadger.notify(error, {context: {message: 'faraday error, flushing'}})
|
33
33
|
end
|
34
34
|
token_cache.flush
|
35
35
|
call(env)
|
36
36
|
else
|
37
37
|
if @debug
|
38
|
-
Honeybadger.notify(error, {
|
38
|
+
Honeybadger.notify(error, {context: {message: 'faraday error, not flushing'}})
|
39
39
|
end
|
40
40
|
raise error
|
41
41
|
end
|
@@ -8,12 +8,12 @@ module ActiveRecordApi
|
|
8
8
|
def flush
|
9
9
|
return unless defined? AUTH_REDIS_POOL
|
10
10
|
debug_log 'flushing token cache'
|
11
|
-
Honeybadger.notify(StandardError.new('token cache has been flushed'))
|
12
11
|
AUTH_REDIS_POOL.with do |client|
|
13
12
|
@redis_client = client
|
14
13
|
@redis_client.del('auth_token')
|
15
14
|
release_lock
|
16
15
|
end
|
16
|
+
debug_log 'token cache has been flushed'
|
17
17
|
end
|
18
18
|
|
19
19
|
def fetch_token(token_proc)
|
@@ -21,13 +21,13 @@ module ActiveRecordApi
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def retrieve_token_from_redis(token_proc)
|
24
|
-
debug_log 'looking
|
24
|
+
debug_log 'looking for token in cache'
|
25
25
|
unless defined? AUTH_REDIS_POOL
|
26
|
-
debug_log 'no auth redis pool'
|
27
|
-
|
28
|
-
|
26
|
+
debug_log 'no auth redis pool. getting new token'
|
27
|
+
token = token_proc.call
|
28
|
+
raise "no token returned! #{token}" if token.nil?
|
29
|
+
return token
|
29
30
|
end
|
30
|
-
debug_log 'looking for token in cache'
|
31
31
|
AUTH_REDIS_POOL.with do |client|
|
32
32
|
@redis_client = client
|
33
33
|
@token = nil
|
@@ -37,12 +37,11 @@ module ActiveRecordApi
|
|
37
37
|
@token = @redis_client.get('auth_token')
|
38
38
|
debug_log "retry ##{@retry}"
|
39
39
|
debug_log "found token: #{@token}"
|
40
|
-
if @token.nil?
|
40
|
+
if @token.nil? || session_missing_for?(@token)
|
41
41
|
if acquire_lock
|
42
42
|
begin
|
43
|
-
debug_log "acquired lock"
|
44
|
-
|
45
|
-
@token = token_proc.call()
|
43
|
+
debug_log "acquired lock and fetching token for cache"
|
44
|
+
@token = token_proc.call
|
46
45
|
raise "no token returned! #{@token}" if @token.nil?
|
47
46
|
@redis_client.set 'auth_token', @token
|
48
47
|
ensure
|
@@ -60,14 +59,36 @@ module ActiveRecordApi
|
|
60
59
|
@token
|
61
60
|
end
|
62
61
|
|
62
|
+
def redis_session_impossible?
|
63
|
+
return true unless defined? Redis
|
64
|
+
ENV['REDIS_SESSION_HOST'].nil? || ENV['REDIS_SESSION'].nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
def redis_session
|
68
|
+
if redis_session_impossible?
|
69
|
+
debug_log 'Redis session environment variables not present.'
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
|
73
|
+
@redis_session ||= Redis.new({url: "redis://#{ENV['REDIS_SESSION_HOST']}", db: ENV['REDIS_SESSION']})
|
74
|
+
end
|
75
|
+
|
76
|
+
def session_missing_for?(token)
|
77
|
+
return false if redis_session.nil?
|
78
|
+
session = (redis_session.send(:get, token) if redis_session.respond_to?(:get))
|
79
|
+
debug_log("Session located for token #{token}") unless session.nil?
|
80
|
+
debug_log("Session could not be located for token #{token}") if session.nil?
|
81
|
+
session.nil?
|
82
|
+
end
|
83
|
+
|
63
84
|
def debug_log(message)
|
64
|
-
Rails.logger.info message if debug
|
85
|
+
Rails.logger.info message if debug && defined? Rails
|
65
86
|
end
|
66
87
|
|
67
88
|
def acquire_lock
|
68
89
|
@redis_client.set 'auth_token_lock', unique_key, nx: true, ex: 60
|
69
90
|
current_lock_value = @redis_client.get 'auth_token_lock'
|
70
|
-
|
91
|
+
debug_log "#{current_lock_value} == #{unique_key}"
|
71
92
|
current_lock_value == unique_key
|
72
93
|
end
|
73
94
|
|
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.
|
4
|
+
version: 0.3.15
|
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:
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_attr
|