authz_jurnal_client 0.0.7 → 0.0.8

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: d069465c6785118e6e04894f5e8b876d782d240db6a0202086f9891e8cba5e10
4
- data.tar.gz: c2c16f5fe8092437ad332a843544fd284865ba291509f10fd8d586740eaf03e0
3
+ metadata.gz: cce433a0abf6a809cf51a500be0f95a23c581af6bc2b05ce56ff7514e4af6d9e
4
+ data.tar.gz: 3c67c5b9589d9c351df4e6d1c6ee6e4a9454957caa5fdcc50cae0b370760131f
5
5
  SHA512:
6
- metadata.gz: d041033d4ee886da9f2568f34b4737252b8c996dd29b47f143bd80682b8cb67a2f0b16691550860c0ea649e8cf39437a46918e4643751c58b17f809ef6f17fb2
7
- data.tar.gz: a7fc7343a40bba4805b8d0796f9db0b3d7fafe5e7654938eae98d92548aa4676c6b6136bb1fa48555cba40659a4b6c128333c7399e0ecb05fbb676d1516c78ba
6
+ metadata.gz: 6edc9d4d7222acd96f9c46225edb44228b1c9e2dcc25666250d02a8e5c2ebbba6b7ab0989d05ab998f9e3611107d843e838ca750abf6c0f0a52602183c5b860b
7
+ data.tar.gz: 44e59bb6cd13a5c813d220e023be9f97a50062b3259d662c5b78ea5cd0a7e7265948c3cc7b96bc23b1370357cfff051aa01d3b0b29e28189057c6d565e370aee
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authz_jurnal_client (0.0.7)
4
+ authz_jurnal_client (0.0.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuthzJurnalClient
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8"
5
5
  end
@@ -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
- @authorization = opts[:authorization]
16
- @headers = {"Authorization" => @authorization}
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( data.to_json, object_class: OpenStruct)
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
- response = JSON.parse( data.to_json, object_class: OpenStruct)
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.7
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-09 00:00:00.000000000 Z
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: