authz_jurnal_client 0.0.5 → 0.0.7

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: d451a03c29d40d2db74d2e4ecb7a3af61869f0851603f588ab17fe7f7ff79c0f
4
- data.tar.gz: 196c69edecba8d9151f1040b3d99d5501a29bacae2758e305aea4e0c78881e06
3
+ metadata.gz: d069465c6785118e6e04894f5e8b876d782d240db6a0202086f9891e8cba5e10
4
+ data.tar.gz: c2c16f5fe8092437ad332a843544fd284865ba291509f10fd8d586740eaf03e0
5
5
  SHA512:
6
- metadata.gz: 03dc07308fdd976ca844f90790ff12bd1259d26db55b048206d4aa85b75aefa9d3f63fc919afd9e491630fdb2bdc60db56b6230de6fa54540d6f4ef695a6401d
7
- data.tar.gz: 034cdd2ba58fe841bf15e21b8a024e79f700e686d7824120e5622ac60b39283a50337a1fa6be8e3dcade4180c09d932275a8d6ec1a77102d66a7bdda498c588c
6
+ metadata.gz: d041033d4ee886da9f2568f34b4737252b8c996dd29b47f143bd80682b8cb67a2f0b16691550860c0ea649e8cf39437a46918e4643751c58b17f809ef6f17fb2
7
+ data.tar.gz: a7fc7343a40bba4805b8d0796f9db0b3d7fafe5e7654938eae98d92548aa4676c6b6136bb1fa48555cba40659a4b6c128333c7399e0ecb05fbb676d1516c78ba
data/Gemfile CHANGED
@@ -15,5 +15,5 @@ gem "redis"
15
15
 
16
16
  gem "faraday"
17
17
 
18
- gem "byebug"
18
+ gem 'simplecov', require: false
19
19
 
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authz_jurnal_client (0.0.5)
4
+ authz_jurnal_client (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
- byebug (11.1.3)
11
10
  connection_pool (2.3.0)
12
11
  diff-lcs (1.5.0)
12
+ docile (1.4.0)
13
13
  faraday (2.7.4)
14
14
  faraday-net_http (>= 2.0, < 3.1)
15
15
  ruby2_keywords (>= 0.0.4)
@@ -24,13 +24,13 @@ GEM
24
24
  redis-client (>= 0.9.0)
25
25
  redis-client (0.12.1)
26
26
  connection_pool
27
- regexp_parser (2.6.2)
27
+ regexp_parser (2.7.0)
28
28
  rexml (3.2.5)
29
29
  rspec (3.12.0)
30
30
  rspec-core (~> 3.12.0)
31
31
  rspec-expectations (~> 3.12.0)
32
32
  rspec-mocks (~> 3.12.0)
33
- rspec-core (3.12.0)
33
+ rspec-core (3.12.1)
34
34
  rspec-support (~> 3.12.0)
35
35
  rspec-expectations (3.12.2)
36
36
  diff-lcs (>= 1.2.0, < 2.0)
@@ -39,7 +39,7 @@ GEM
39
39
  diff-lcs (>= 1.2.0, < 2.0)
40
40
  rspec-support (~> 3.12.0)
41
41
  rspec-support (3.12.0)
42
- rubocop (1.44.1)
42
+ rubocop (1.45.1)
43
43
  json (~> 2.3)
44
44
  parallel (~> 1.10)
45
45
  parser (>= 3.2.0.0)
@@ -53,6 +53,12 @@ GEM
53
53
  parser (>= 3.1.1.0)
54
54
  ruby-progressbar (1.11.0)
55
55
  ruby2_keywords (0.0.5)
56
+ simplecov (0.22.0)
57
+ docile (~> 1.1)
58
+ simplecov-html (~> 0.11)
59
+ simplecov_json_formatter (~> 0.1)
60
+ simplecov-html (0.12.3)
61
+ simplecov_json_formatter (0.1.4)
56
62
  unicode-display_width (2.4.2)
57
63
 
58
64
  PLATFORMS
@@ -60,12 +66,12 @@ PLATFORMS
60
66
 
61
67
  DEPENDENCIES
62
68
  authz_jurnal_client!
63
- byebug
64
69
  faraday
65
70
  rake (~> 13.0)
66
71
  redis
67
72
  rspec (~> 3.0)
68
73
  rubocop (~> 1.21)
74
+ simplecov
69
75
 
70
76
  BUNDLED WITH
71
77
  1.17.3
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' or gem install authz_jurnal_client
13
+ gem 'authz_jurnal_client', git: 'git@bitbucket.org:jurnal/authz-jurnal-client.git', tag: 'v0.0.1'
14
14
  ```
15
15
 
16
16
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuthzJurnalClient
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.7"
5
5
  end
@@ -2,7 +2,6 @@ require "ostruct"
2
2
  require "json"
3
3
  require "faraday"
4
4
  require "redis"
5
- require 'byebug'
6
5
 
7
6
  require_relative "authz_jurnal_client/version"
8
7
 
@@ -11,7 +10,7 @@ module AuthzJurnalClient
11
10
 
12
11
  class UserRoles
13
12
  class << self
14
- attr_accessor :redis, :domain, :authorization, :expiry
13
+ attr_accessor :redis, :domain, :authorization, :expiry, :cache
15
14
  def config(opts = {})
16
15
  @authorization = opts[:authorization]
17
16
  @headers = {"Authorization" => @authorization}
@@ -19,26 +18,33 @@ module AuthzJurnalClient
19
18
  redis_path = opts[:redis] || 'redis://localhost:6379'
20
19
  @redis = Redis.new(url: redis_path)
21
20
  @expiry = opts[:expiry] || 3600
21
+ @cache = opts[:cache].nil? ? true : opts[:cache]
22
22
  end
23
23
 
24
24
  def call(id, cid)
25
- if @redis
25
+ return get_errors({errors: { messages: "uid or cid cannot be blank!"}}) if id.nil? || cid.nil?
26
+
27
+ if @redis && @cache
26
28
  cached = @redis.get(make_key(id, cid))
27
- return get_roles(cached) if cached
29
+ return get_response(cached) if cached
28
30
  end
29
31
 
30
32
  response = backend_request(id, cid)
31
- return unless response.success?
33
+ if !response.success?
34
+ return get_errors({errors: { messages: "request failed to fetch data!"}})
35
+ end
32
36
 
33
37
  @redis&.setex(make_key(id, cid), @expiry, response.body)
34
- get_roles(response.body)
38
+ get_response(response.body)
35
39
  rescue Redis::CannotConnectError
36
40
  response = backend_request(id, cid)
37
- get_roles(response.body)
41
+ get_response(response.body)
38
42
  end
39
43
 
40
44
  def backend_request(id, cid)
41
45
  conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
46
+ f.options.open_timeout = 10
47
+ f.options.timeout = 60
42
48
  f.adapter :net_http
43
49
  end
44
50
 
@@ -49,9 +55,15 @@ module AuthzJurnalClient
49
55
  "manage_roles:#{id}-#{cid}"
50
56
  end
51
57
 
52
- def get_roles(j)
58
+ def get_response(j)
53
59
  data = eval(j)
54
- JSON.parse( data.to_json, object_class: OpenStruct).data.roles
60
+ response = JSON.parse( data.to_json, object_class: OpenStruct)
61
+ response.data.roles
62
+ end
63
+
64
+ def get_errors(e)
65
+ data = e.is_a?(Hash) ? e : eval(e)
66
+ response = JSON.parse( data.to_json, object_class: OpenStruct)
55
67
  end
56
68
  end
57
69
  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.5
4
+ version: 0.0.7
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-06 00:00:00.000000000 Z
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,21 +17,15 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - ".byebug_history"
21
20
  - ".rspec"
22
- - ".rspec_status"
23
21
  - Gemfile
24
22
  - Gemfile.lock
25
23
  - README.md
26
24
  - Rakefile
27
- - authz_jurnal_client-0.0.1.gem
28
- - authz_jurnal_client-0.0.2.gem
29
- - authz_jurnal_client-0.0.3.gem
30
- - authz_jurnal_client-0.0.4.gem
31
25
  - lib/authz_jurnal_client.rb
32
26
  - lib/authz_jurnal_client/version.rb
33
27
  - lib/sig/authz_jurnal_client.rbs
34
- homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/nat-dev/
28
+ homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/master/
35
29
  licenses: []
36
30
  metadata: {}
37
31
  post_install_message:
data/.byebug_history DELETED
@@ -1,11 +0,0 @@
1
- continue
2
- d.to_json
3
- d
4
- continue
5
- JSON.parse( j, object_class: OpenStruct).data.roles
6
- j
7
- continue
8
- JSON.parse( j, object_class: OpenStruct).data.roles
9
- j
10
- continue
11
- roles = AuthzJurnalClient::UserRoles.call(1, 1)
data/.rspec_status DELETED
@@ -1,9 +0,0 @@
1
- example_id | status | run_time |
2
- ----------------------------------------- | ------ | --------------- |
3
- ./spec/authz_jurnal_client_spec.rb[1:1:1] | passed | 0.0031 seconds |
4
- ./spec/authz_jurnal_client_spec.rb[1:2:1] | passed | 0.01582 seconds |
5
- ./spec/authz_jurnal_client_spec.rb[1:2:2] | passed | 0.00067 seconds |
6
- ./spec/authz_jurnal_client_spec.rb[1:3:1] | passed | 0.00443 seconds |
7
- ./spec/authz_jurnal_client_spec.rb[1:3:2] | passed | 0.00199 seconds |
8
- ./spec/authz_jurnal_client_spec.rb[1:4:1] | passed | 0.00143 seconds |
9
- ./spec/authz_jurnal_client_spec.rb[1:4:2] | passed | 0.00153 seconds |
Binary file
Binary file
Binary file
Binary file