authz_jurnal_client 0.0.7 → 0.0.9
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -9
- data/lib/authz_jurnal_client/version.rb +1 -1
- data/lib/authz_jurnal_client.rb +13 -42
- 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: 93c657e409a5a2c68bfd2d7bae8bd74cbcfb9ed65e0e0b5f271c385b5bb2f122
|
4
|
+
data.tar.gz: ec9383d9b8f0c274c391e8b6cf7dfee0df93b37651e222a7fecaa609a7b07d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f2557b899d5237e218e0e7277a2196bb7a85220c6636e75a758e402eee4e933294bd0c8d739ac3f9121ad20e80bc1ff6eb4c9e68e51b8c5cd9114dafe6f35b8
|
7
|
+
data.tar.gz: 5036d37930dcd53905e39665945e0beb0e0f420e0157f5274d4bcf76ac57f4b5d5ebe729da188e3c5b1a6149e4af84cf5f6a416f0c1ed59ec60d63f46b136a32
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@ AuthzJurnalClient allows you to access the user roles API directly. It also prov
|
|
10
10
|
Install the gem thusly in the gemfile
|
11
11
|
|
12
12
|
``` markdown
|
13
|
-
gem 'authz_jurnal_client', git: 'git@bitbucket.org:jurnal/authz-jurnal-client.git', tag: 'v0.0.
|
13
|
+
gem 'authz_jurnal_client', git: 'git@bitbucket.org:jurnal/authz-jurnal-client.git', tag: 'v0.0.9'
|
14
14
|
```
|
15
15
|
|
16
16
|
|
@@ -20,14 +20,9 @@ TODO: Write usage instructions here
|
|
20
20
|
|
21
21
|
``` Ruby
|
22
22
|
Default :
|
23
|
-
AuthzJurnalClient::UserRoles.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Customize :
|
28
|
-
AuthzJurnalClient::UserRoles.config(redis: "redis://localhost:6379", domain: 'http://mydomain.com', expiry: 3600, authorization: "Basic ApiToken")
|
29
|
-
roles = AuthzJurnalClient::UserRoles.call(uid, cid)
|
30
|
-
puts roles
|
23
|
+
AuthzJurnalClient::UserRoles.call(request)
|
24
|
+
ex: ['ultimate','admin']
|
25
|
+
|
31
26
|
```
|
32
27
|
|
33
28
|
The response is a json parsed Openstruct
|
data/lib/authz_jurnal_client.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require "ostruct"
|
2
2
|
require "json"
|
3
|
-
require "faraday"
|
4
|
-
require "redis"
|
5
3
|
|
6
4
|
require_relative "authz_jurnal_client/version"
|
7
5
|
|
@@ -10,60 +8,33 @@ module AuthzJurnalClient
|
|
10
8
|
|
11
9
|
class UserRoles
|
12
10
|
class << self
|
13
|
-
attr_accessor :
|
14
|
-
def config(opts = {})
|
15
|
-
@authorization = opts[:authorization]
|
16
|
-
@headers = {"Authorization" => @authorization}
|
17
|
-
@domain = opts[:domain] || 'http://localhost:3000'
|
18
|
-
redis_path = opts[:redis] || 'redis://localhost:6379'
|
19
|
-
@redis = Redis.new(url: redis_path)
|
20
|
-
@expiry = opts[:expiry] || 3600
|
21
|
-
@cache = opts[:cache].nil? ? true : opts[:cache]
|
22
|
-
end
|
11
|
+
attr_accessor :headers
|
23
12
|
|
24
|
-
def call(
|
25
|
-
|
13
|
+
def call(req)
|
14
|
+
@headers = r_headers(req.headers)
|
26
15
|
|
27
|
-
if @
|
28
|
-
cached = @redis.get(make_key(id, cid))
|
29
|
-
return get_response(cached) if cached
|
30
|
-
end
|
16
|
+
return get_errors({ errors: { messages: "You are not authorized to access!" } }) if @headers == {} || @headers['Authorization'].nil?
|
31
17
|
|
32
|
-
|
33
|
-
|
34
|
-
return get_errors({errors: { messages: "request failed to fetch data!"}})
|
18
|
+
if @headers['X-Consumer-Roles'].nil?
|
19
|
+
return get_errors({ errors: { messages: "Roles not found on headers!" } })
|
35
20
|
end
|
36
21
|
|
37
|
-
|
38
|
-
get_response(response.body)
|
39
|
-
rescue Redis::CannotConnectError
|
40
|
-
response = backend_request(id, cid)
|
41
|
-
get_response(response.body)
|
22
|
+
roles
|
42
23
|
end
|
43
24
|
|
44
|
-
|
45
|
-
conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
|
46
|
-
f.options.open_timeout = 10
|
47
|
-
f.options.timeout = 60
|
48
|
-
f.adapter :net_http
|
49
|
-
end
|
50
|
-
|
51
|
-
conn.get('roles', { company_id: cid }, @headers)
|
52
|
-
end
|
25
|
+
private
|
53
26
|
|
54
|
-
def
|
55
|
-
|
27
|
+
def roles
|
28
|
+
@headers['X-Consumer-Roles'].split(',').collect { |e| e.strip }
|
56
29
|
end
|
57
30
|
|
58
|
-
def
|
59
|
-
|
60
|
-
response = JSON.parse( data.to_json, object_class: OpenStruct)
|
61
|
-
response.data.roles
|
31
|
+
def r_headers(h)
|
32
|
+
h.is_a?(Hash) ? JSON.parse(h.to_json) : h
|
62
33
|
end
|
63
34
|
|
64
35
|
def get_errors(e)
|
65
36
|
data = e.is_a?(Hash) ? e : eval(e)
|
66
|
-
|
37
|
+
JSON.parse(data.to_json, object_class: OpenStruct)
|
67
38
|
end
|
68
39
|
end
|
69
40
|
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.9
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|