authz_jurnal_client 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/authz_jurnal_client/version.rb +1 -1
- data/lib/authz_jurnal_client.rb +19 -9
- 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: cce433a0abf6a809cf51a500be0f95a23c581af6bc2b05ce56ff7514e4af6d9e
|
4
|
+
data.tar.gz: 3c67c5b9589d9c351df4e6d1c6ee6e4a9454957caa5fdcc50cae0b370760131f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6edc9d4d7222acd96f9c46225edb44228b1c9e2dcc25666250d02a8e5c2ebbba6b7ab0989d05ab998f9e3611107d843e838ca750abf6c0f0a52602183c5b860b
|
7
|
+
data.tar.gz: 44e59bb6cd13a5c813d220e023be9f97a50062b3259d662c5b78ea5cd0a7e7265948c3cc7b96bc23b1370357cfff051aa01d3b0b29e28189057c6d565e370aee
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,7 +20,7 @@ TODO: Write usage instructions here
|
|
20
20
|
|
21
21
|
``` Ruby
|
22
22
|
Default :
|
23
|
-
AuthzJurnalClient::UserRoles.config(authorization: "Basic ApiToken")
|
23
|
+
AuthzJurnalClient::UserRoles.config(authorization: "Basic ApiToken") or AuthzJurnalClient::UserRoles.config(username: nil, password: nil)
|
24
24
|
roles = AuthzJurnalClient::UserRoles.call(uid, cid)
|
25
25
|
puts roles
|
26
26
|
|
data/lib/authz_jurnal_client.rb
CHANGED
@@ -10,10 +10,12 @@ module AuthzJurnalClient
|
|
10
10
|
|
11
11
|
class UserRoles
|
12
12
|
class << self
|
13
|
-
attr_accessor :redis, :domain, :authorization, :expiry, :cache
|
13
|
+
attr_accessor :redis, :domain, :authorization, :username, :password, :expiry, :cache
|
14
14
|
def config(opts = {})
|
15
|
-
@
|
16
|
-
@
|
15
|
+
@username = opts[:username]
|
16
|
+
@password = opts[:password]
|
17
|
+
@authorization = init_auth(opts)
|
18
|
+
@headers = { "Authorization": @authorization }
|
17
19
|
@domain = opts[:domain] || 'http://localhost:3000'
|
18
20
|
redis_path = opts[:redis] || 'redis://localhost:6379'
|
19
21
|
@redis = Redis.new(url: redis_path)
|
@@ -21,8 +23,18 @@ module AuthzJurnalClient
|
|
21
23
|
@cache = opts[:cache].nil? ? true : opts[:cache]
|
22
24
|
end
|
23
25
|
|
26
|
+
def init_auth(opts)
|
27
|
+
@authorization = opts[:authorization]
|
28
|
+
|
29
|
+
if @username && @password
|
30
|
+
@authorization = "Basic #{Base64.encode64("#{@username}:#{@password}")}"
|
31
|
+
end
|
32
|
+
|
33
|
+
@authorization
|
34
|
+
end
|
35
|
+
|
24
36
|
def call(id, cid)
|
25
|
-
return get_errors({errors: { messages: "uid or cid cannot be blank!"}}) if id.nil? || cid.nil?
|
37
|
+
return get_errors({ errors: { messages: "uid or cid cannot be blank!" } }) if id.nil? || cid.nil?
|
26
38
|
|
27
39
|
if @redis && @cache
|
28
40
|
cached = @redis.get(make_key(id, cid))
|
@@ -30,9 +42,7 @@ module AuthzJurnalClient
|
|
30
42
|
end
|
31
43
|
|
32
44
|
response = backend_request(id, cid)
|
33
|
-
if !response.success?
|
34
|
-
return get_errors({errors: { messages: "request failed to fetch data!"}})
|
35
|
-
end
|
45
|
+
return get_errors(JSON.parse(response.body)) if !response.success?
|
36
46
|
|
37
47
|
@redis&.setex(make_key(id, cid), @expiry, response.body)
|
38
48
|
get_response(response.body)
|
@@ -57,13 +67,13 @@ module AuthzJurnalClient
|
|
57
67
|
|
58
68
|
def get_response(j)
|
59
69
|
data = eval(j)
|
60
|
-
response = JSON.parse(
|
70
|
+
response = JSON.parse(data.to_json, object_class: OpenStruct)
|
61
71
|
response.data.roles
|
62
72
|
end
|
63
73
|
|
64
74
|
def get_errors(e)
|
65
75
|
data = e.is_a?(Hash) ? e : eval(e)
|
66
|
-
|
76
|
+
JSON.parse(data.to_json, object_class: OpenStruct)
|
67
77
|
end
|
68
78
|
end
|
69
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authz_jurnal_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alam Topani
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|