authz_jurnal_client 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +19 -0
- data/Gemfile.lock +71 -0
- data/README.md +0 -0
- data/Rakefile +12 -0
- data/authz_jurnal_client-0.0.1.gem +0 -0
- data/authz_jurnal_client-0.0.2.gem +0 -0
- data/lib/authz_jurnal_client/version.rb +5 -0
- data/lib/authz_jurnal_client.rb +59 -0
- data/lib/sig/authz_jurnal_client.rbs +4 -0
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8629db96453f7a2bcb57a10cc33e24225dc8d2c64887a73d1858f8f29c9d7e07
|
4
|
+
data.tar.gz: c3d079a6784968c0353a3cc379f98755228e72b2f8557e16685ee487f9f1cb58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 315f869e05b9640414729c70380fd582977def884d9cbb3072e93e17f280c376643ba72f65781b2808f0c82b4c20e51f2170f59abbfeef8a2b311abd727594d2
|
7
|
+
data.tar.gz: d01429920786ab9e8f54e8ebc4858df688c813789b9ca641db696534dae0fdd39d37df96a67a71339bd696a9301d7de5bc3767260371b7c0dfa4fcbc5cc22662
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in authz_service_jurnal.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
gem "redis"
|
15
|
+
|
16
|
+
gem "faraday"
|
17
|
+
|
18
|
+
gem "byebug"
|
19
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
authz_jurnal_client (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
byebug (11.1.3)
|
11
|
+
connection_pool (2.3.0)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
faraday (2.7.4)
|
14
|
+
faraday-net_http (>= 2.0, < 3.1)
|
15
|
+
ruby2_keywords (>= 0.0.4)
|
16
|
+
faraday-net_http (3.0.2)
|
17
|
+
json (2.6.3)
|
18
|
+
parallel (1.22.1)
|
19
|
+
parser (3.2.0.0)
|
20
|
+
ast (~> 2.4.1)
|
21
|
+
rainbow (3.1.1)
|
22
|
+
rake (13.0.6)
|
23
|
+
redis (5.0.6)
|
24
|
+
redis-client (>= 0.9.0)
|
25
|
+
redis-client (0.12.1)
|
26
|
+
connection_pool
|
27
|
+
regexp_parser (2.6.2)
|
28
|
+
rexml (3.2.5)
|
29
|
+
rspec (3.12.0)
|
30
|
+
rspec-core (~> 3.12.0)
|
31
|
+
rspec-expectations (~> 3.12.0)
|
32
|
+
rspec-mocks (~> 3.12.0)
|
33
|
+
rspec-core (3.12.0)
|
34
|
+
rspec-support (~> 3.12.0)
|
35
|
+
rspec-expectations (3.12.2)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.12.0)
|
38
|
+
rspec-mocks (3.12.3)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.12.0)
|
41
|
+
rspec-support (3.12.0)
|
42
|
+
rubocop (1.44.1)
|
43
|
+
json (~> 2.3)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 3.2.0.0)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
regexp_parser (>= 1.8, < 3.0)
|
48
|
+
rexml (>= 3.2.5, < 4.0)
|
49
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
50
|
+
ruby-progressbar (~> 1.7)
|
51
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
52
|
+
rubocop-ast (1.24.1)
|
53
|
+
parser (>= 3.1.1.0)
|
54
|
+
ruby-progressbar (1.11.0)
|
55
|
+
ruby2_keywords (0.0.5)
|
56
|
+
unicode-display_width (2.4.2)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
authz_jurnal_client!
|
63
|
+
byebug
|
64
|
+
faraday
|
65
|
+
rake (~> 13.0)
|
66
|
+
redis
|
67
|
+
rspec (~> 3.0)
|
68
|
+
rubocop (~> 1.21)
|
69
|
+
|
70
|
+
BUNDLED WITH
|
71
|
+
1.17.3
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "json"
|
3
|
+
require "faraday"
|
4
|
+
require "redis"
|
5
|
+
|
6
|
+
require_relative "authz_jurnal_client/version"
|
7
|
+
|
8
|
+
module AuthzJurnalClient
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class UserRoles
|
12
|
+
class << self
|
13
|
+
attr_accessor :redis, :domain, :token, :expiry
|
14
|
+
def config(opts = {})
|
15
|
+
@redis = if opts[:redis].is_a? Hash
|
16
|
+
Redis.new(opts[:redis])
|
17
|
+
else
|
18
|
+
opts[:redis]
|
19
|
+
end
|
20
|
+
@domain = opts[:domain]
|
21
|
+
@headers = {"Authorization" => "Basic #{token}"}
|
22
|
+
@expiry = opts[:expiry] || 3600 * 5
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(id, cid)
|
26
|
+
if @redis
|
27
|
+
cached = @redis.get(make_key(id, cid))
|
28
|
+
return get_roles(cached) if cached
|
29
|
+
end
|
30
|
+
|
31
|
+
response = backend_request(id, cid)
|
32
|
+
return unless response.success?
|
33
|
+
|
34
|
+
@redis&.setex(make_key(id, cid), @expiry, response.body)
|
35
|
+
get_roles(response.body)
|
36
|
+
rescue Redis::CannotConnectError
|
37
|
+
response = backend_request(id, cid)
|
38
|
+
get_roles(response.body)
|
39
|
+
end
|
40
|
+
|
41
|
+
def backend_request(id, cid)
|
42
|
+
conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
|
43
|
+
f.adapter :net_http
|
44
|
+
end
|
45
|
+
|
46
|
+
conn.get('roles', { company_id: cid }, @headers)
|
47
|
+
end
|
48
|
+
|
49
|
+
def make_key(id, cid)
|
50
|
+
"manage_role:#{id}-#{cid}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_roles(j)
|
54
|
+
res = JSON.parse(j)
|
55
|
+
res['data']['roles'] if res['data'] && res['data']['roles']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alam Topani
|
@@ -16,8 +16,17 @@ email:
|
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
|
-
files:
|
20
|
-
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- Gemfile.lock
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- authz_jurnal_client-0.0.1.gem
|
25
|
+
- authz_jurnal_client-0.0.2.gem
|
26
|
+
- lib/authz_jurnal_client.rb
|
27
|
+
- lib/authz_jurnal_client/version.rb
|
28
|
+
- lib/sig/authz_jurnal_client.rbs
|
29
|
+
homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/nat-dev/
|
21
30
|
licenses: []
|
22
31
|
metadata: {}
|
23
32
|
post_install_message:
|
@@ -28,7 +37,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
37
|
requirements:
|
29
38
|
- - ">="
|
30
39
|
- !ruby/object:Gem::Version
|
31
|
-
version: 2.6.
|
40
|
+
version: 2.6.5
|
32
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
42
|
requirements:
|
34
43
|
- - ">="
|