zaikio-jwt_auth 0.5.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zaikio/jwt_auth/directory_cache.rb +20 -18
- data/lib/zaikio/jwt_auth/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: 5246d95da7085c56dce3719ba3bdba4c102c3b4dd01c941cacb5de5d9e813eb0
|
4
|
+
data.tar.gz: 354e97d2ef3972049e103fa0afea9e047f9990ab816ca8b7afec7c3671e0d90b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8025ca7934fac9df869afde1fd23287208fb9edbd1970e3d065d9591062a1557a435f6cb0d7d8147d8f8f2fdbb476ae00dead2d89bb232951489de785df0e248
|
7
|
+
data.tar.gz: 89431f5cdf4ad50dff018a35530fb95d97d2a9a91a1908566b8d9de187dff65f1203bfb76a7eef79fcc3fca116f336ab194c18b8bd583d830098481678a53aa8
|
@@ -5,6 +5,13 @@ require "logger"
|
|
5
5
|
module Zaikio
|
6
6
|
module JWTAuth
|
7
7
|
class DirectoryCache
|
8
|
+
class UpdateJob < ::ActiveJob::Base
|
9
|
+
def perform(directory_path)
|
10
|
+
DirectoryCache.fetch(directory_path)
|
11
|
+
true # This job will always re-queue until it succeeds.
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
BadResponseError = Class.new(StandardError)
|
9
16
|
|
10
17
|
class << self
|
@@ -14,7 +21,8 @@ module Zaikio
|
|
14
21
|
json = Oj.load(cache) if cache
|
15
22
|
|
16
23
|
if !cache || options[:invalidate] || cache_expired?(json, options[:expires_after])
|
17
|
-
|
24
|
+
new_values = reload_or_enqueue(directory_path)
|
25
|
+
return new_values || json["data"]
|
18
26
|
end
|
19
27
|
|
20
28
|
json["data"]
|
@@ -39,24 +47,18 @@ module Zaikio
|
|
39
47
|
DateTime.strptime(json["fetched_at"].to_s, "%s") < Time.now.utc - (expires_after || 1.hour)
|
40
48
|
end
|
41
49
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
data
|
47
|
-
|
48
|
-
fetched_at: Time.now.to_i,
|
49
|
-
data: data
|
50
|
-
}.to_json)
|
51
|
-
|
52
|
-
data
|
53
|
-
rescue Errno::ECONNREFUSED, Net::ReadTimeout, BadResponseError => e
|
54
|
-
raise unless (retries += 1) <= 3
|
50
|
+
def reload_or_enqueue(directory_path)
|
51
|
+
data = fetch_from_directory(directory_path)
|
52
|
+
Zaikio::JWTAuth.configuration.redis.set("zaikio::jwt_auth::#{directory_path}", {
|
53
|
+
fetched_at: Time.now.to_i,
|
54
|
+
data: data
|
55
|
+
}.to_json)
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
data
|
58
|
+
rescue Errno::ECONNREFUSED, Net::ReadTimeout, BadResponseError
|
59
|
+
Zaikio::JWTAuth.configuration.logger.info("Error updating DirectoryCache(#{directory_path}), enqueueing job to update")
|
60
|
+
UpdateJob.set(wait: 10.seconds).perform_later(directory_path)
|
61
|
+
nil
|
60
62
|
end
|
61
63
|
|
62
64
|
def fetch_from_directory(directory_path)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-04-
|
13
|
+
date: 2021-04-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oj
|