zaikio-jwt_auth 0.4.3 → 1.0.1
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 +29 -19
- data/lib/zaikio/jwt_auth/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4103bf1e59a9fa8a68a868c33d785082993255fe24616a01c1113a5a8026dcfe
|
4
|
+
data.tar.gz: e0be8641749a07f97620c73a56a97211ba51e9fe4f9dc6e1bdbaa5dd0422b0e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28c8d6ea0b394450f7ae0027e9388fca1a9bd449213b6825356c65452e8a3efa4ab670802537cf9e08146d8a6980b5cbb22f2efa5cdec4c4b271b4c02b759fcf
|
7
|
+
data.tar.gz: 647aa957f6e7d82ca26b50169fd265b30e144dcef5a26a8273e786c388569ac09babed909a1ddf295255df404f097bc5a867ff5520920d81f37ae4a48a5c60da
|
@@ -5,6 +5,15 @@ 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
|
+
|
15
|
+
BadResponseError = Class.new(StandardError)
|
16
|
+
|
8
17
|
class << self
|
9
18
|
def fetch(directory_path, options = {})
|
10
19
|
cache = Zaikio::JWTAuth.configuration.redis.get("zaikio::jwt_auth::#{directory_path}")
|
@@ -12,7 +21,8 @@ module Zaikio
|
|
12
21
|
json = Oj.load(cache) if cache
|
13
22
|
|
14
23
|
if !cache || options[:invalidate] || cache_expired?(json, options[:expires_after])
|
15
|
-
|
24
|
+
new_values = reload_or_enqueue(directory_path)
|
25
|
+
return new_values || json["data"]
|
16
26
|
end
|
17
27
|
|
18
28
|
json["data"]
|
@@ -37,29 +47,29 @@ module Zaikio
|
|
37
47
|
DateTime.strptime(json["fetched_at"].to_s, "%s") < Time.now.utc - (expires_after || 1.hour)
|
38
48
|
end
|
39
49
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
data
|
45
|
-
|
46
|
-
fetched_at: Time.now.to_i,
|
47
|
-
data: data
|
48
|
-
}.to_json)
|
49
|
-
|
50
|
-
data
|
51
|
-
rescue Errno::ECONNREFUSED, Net::ReadTimeout => e
|
52
|
-
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)
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
58
62
|
end
|
59
63
|
|
60
64
|
def fetch_from_directory(directory_path)
|
61
65
|
uri = URI("#{Zaikio::JWTAuth.configuration.host}/#{directory_path}")
|
62
|
-
|
66
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
67
|
+
http.use_ssl = uri.scheme == "https"
|
68
|
+
response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
69
|
+
raise BadResponseError unless (200..299).cover?(response.code.to_i)
|
70
|
+
raise BadResponseError unless response["content-type"].to_s.include?("application/json")
|
71
|
+
|
72
|
+
Oj.load(response.body)
|
63
73
|
end
|
64
74
|
end
|
65
75
|
end
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-04-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activejob
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: oj
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -27,7 +41,7 @@ dependencies:
|
|
27
41
|
- !ruby/object:Gem::Version
|
28
42
|
version: 3.0.0
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
44
|
+
name: railties
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
32
46
|
requirements:
|
33
47
|
- - ">="
|