authz_jurnal_client 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2e2671a51a6d5e329bcca54d12ec3dd4586f1da11ad2e075caa588a7f186e2d
4
- data.tar.gz: 1664e4e21b152ec7f0b82027f4535ee02608782b16249394edd63fc0335e4be0
3
+ metadata.gz: f666ee3dfcb96b541d4d42723339c94c355604d621e63b38ccc6df3a538650c0
4
+ data.tar.gz: f284cda68f01a13f457a8d82da96c29c33e41ebba867b542ecf96277f35522bb
5
5
  SHA512:
6
- metadata.gz: 50c70026e1e0af20ca6d41aeff01652ed8e2928bfd27e41406753f9de56926d0f197a3f0a5232f19b5ed5a59b672f300852dce27f99d71b62f56709656d230db
7
- data.tar.gz: bcbe211f73cf946608e353d01cd4bbbff8a6739d832bcc07991c5838b4dbf59c9bed35f22de16eecbca550c1e14df06e7603f1663261d1aec2750228140484c4
6
+ metadata.gz: a52f1516d6fda62d895c46e84fa9f18ebcc7c91a3a593e0b788fe7b04d2416a8258e0a3794fbd091b5b581ca198c4948c6639b31184db2ae3b847316e1d1113d
7
+ data.tar.gz: b83d991c7bf622a46f6579e4dbf4b168b48b8d879aeb6f9c042c5903b6c310b242c8d9aeec0340160ddb4fbda427adf55c2892db212d3d4746f67a6371309f93
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.4)
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/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AuthzJurnalClient
4
+ VERSION = "0.0.4"
5
+ end
@@ -0,0 +1,56 @@
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, :authorization, :expiry
14
+ def config(opts = {})
15
+ @headers = {"Authorization" => "#{opts[:authorization]}"}
16
+ @domain = opts[:domain] || 'http://localhost:3000'
17
+ redis_path = opts[:redis] || 'redis://localhost:6379'
18
+ @redis = Redis.new(url: redis_path)
19
+ @expiry = opts[:expiry] || 3600 * 5
20
+ end
21
+
22
+ def call(id, cid)
23
+ if @redis
24
+ cached = @redis.get(make_key(id, cid))
25
+ return get_roles(cached) if cached
26
+ end
27
+
28
+ response = backend_request(id, cid)
29
+ return unless response.success?
30
+
31
+ @redis&.setex(make_key(id, cid), @expiry, response.body)
32
+ get_roles(response.body)
33
+ rescue Redis::CannotConnectError
34
+ response = backend_request(id, cid)
35
+ get_roles(response.body)
36
+ end
37
+
38
+ def backend_request(id, cid)
39
+ conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
40
+ f.adapter :net_http
41
+ end
42
+
43
+ conn.get('roles', { company_id: cid }, @headers)
44
+ end
45
+
46
+ def make_key(id, cid)
47
+ "manage_roles:#{id}-#{cid}"
48
+ end
49
+
50
+ def get_roles(j)
51
+ res = JSON.parse(j)
52
+ res['data']['roles'] if res['data'] && res['data']['roles']
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module AuthzJurnalClient
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ 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.2
4
+ version: 0.0.4
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-01 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,8 +17,17 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - Gemfile
21
+ - Gemfile.lock
20
22
  - README.md
21
- homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/master/
23
+ - Rakefile
24
+ - authz_jurnal_client-0.0.1.gem
25
+ - authz_jurnal_client-0.0.2.gem
26
+ - authz_jurnal_client-0.0.3.gem
27
+ - lib/authz_jurnal_client.rb
28
+ - lib/authz_jurnal_client/version.rb
29
+ - lib/sig/authz_jurnal_client.rbs
30
+ homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/nat-dev/
22
31
  licenses: []
23
32
  metadata: {}
24
33
  post_install_message: