authz_jurnal_client 0.0.8 → 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 +12 -51
- 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,65 +8,28 @@ module AuthzJurnalClient
|
|
10
8
|
|
11
9
|
class UserRoles
|
12
10
|
class << self
|
13
|
-
attr_accessor :
|
14
|
-
def config(opts = {})
|
15
|
-
@username = opts[:username]
|
16
|
-
@password = opts[:password]
|
17
|
-
@authorization = init_auth(opts)
|
18
|
-
@headers = { "Authorization": @authorization }
|
19
|
-
@domain = opts[:domain] || 'http://localhost:3000'
|
20
|
-
redis_path = opts[:redis] || 'redis://localhost:6379'
|
21
|
-
@redis = Redis.new(url: redis_path)
|
22
|
-
@expiry = opts[:expiry] || 3600
|
23
|
-
@cache = opts[:cache].nil? ? true : opts[:cache]
|
24
|
-
end
|
25
|
-
|
26
|
-
def init_auth(opts)
|
27
|
-
@authorization = opts[:authorization]
|
11
|
+
attr_accessor :headers
|
28
12
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
@authorization
|
34
|
-
end
|
13
|
+
def call(req)
|
14
|
+
@headers = r_headers(req.headers)
|
35
15
|
|
36
|
-
|
37
|
-
return get_errors({ errors: { messages: "uid or cid cannot be blank!" } }) if id.nil? || cid.nil?
|
16
|
+
return get_errors({ errors: { messages: "You are not authorized to access!" } }) if @headers == {} || @headers['Authorization'].nil?
|
38
17
|
|
39
|
-
if @
|
40
|
-
|
41
|
-
return get_response(cached) if cached
|
18
|
+
if @headers['X-Consumer-Roles'].nil?
|
19
|
+
return get_errors({ errors: { messages: "Roles not found on headers!" } })
|
42
20
|
end
|
43
21
|
|
44
|
-
|
45
|
-
return get_errors(JSON.parse(response.body)) if !response.success?
|
46
|
-
|
47
|
-
@redis&.setex(make_key(id, cid), @expiry, response.body)
|
48
|
-
get_response(response.body)
|
49
|
-
rescue Redis::CannotConnectError
|
50
|
-
response = backend_request(id, cid)
|
51
|
-
get_response(response.body)
|
22
|
+
roles
|
52
23
|
end
|
53
24
|
|
54
|
-
|
55
|
-
conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
|
56
|
-
f.options.open_timeout = 10
|
57
|
-
f.options.timeout = 60
|
58
|
-
f.adapter :net_http
|
59
|
-
end
|
60
|
-
|
61
|
-
conn.get('roles', { company_id: cid }, @headers)
|
62
|
-
end
|
25
|
+
private
|
63
26
|
|
64
|
-
def
|
65
|
-
|
27
|
+
def roles
|
28
|
+
@headers['X-Consumer-Roles'].split(',').collect { |e| e.strip }
|
66
29
|
end
|
67
30
|
|
68
|
-
def
|
69
|
-
|
70
|
-
response = JSON.parse(data.to_json, object_class: OpenStruct)
|
71
|
-
response.data.roles
|
31
|
+
def r_headers(h)
|
32
|
+
h.is_a?(Hash) ? JSON.parse(h.to_json) : h
|
72
33
|
end
|
73
34
|
|
74
35
|
def get_errors(e)
|
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:
|