authz_jurnal_client 0.0.5 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d451a03c29d40d2db74d2e4ecb7a3af61869f0851603f588ab17fe7f7ff79c0f
4
- data.tar.gz: 196c69edecba8d9151f1040b3d99d5501a29bacae2758e305aea4e0c78881e06
3
+ metadata.gz: cce433a0abf6a809cf51a500be0f95a23c581af6bc2b05ce56ff7514e4af6d9e
4
+ data.tar.gz: 3c67c5b9589d9c351df4e6d1c6ee6e4a9454957caa5fdcc50cae0b370760131f
5
5
  SHA512:
6
- metadata.gz: 03dc07308fdd976ca844f90790ff12bd1259d26db55b048206d4aa85b75aefa9d3f63fc919afd9e491630fdb2bdc60db56b6230de6fa54540d6f4ef695a6401d
7
- data.tar.gz: 034cdd2ba58fe841bf15e21b8a024e79f700e686d7824120e5622ac60b39283a50337a1fa6be8e3dcade4180c09d932275a8d6ec1a77102d66a7bdda498c588c
6
+ metadata.gz: 6edc9d4d7222acd96f9c46225edb44228b1c9e2dcc25666250d02a8e5c2ebbba6b7ab0989d05ab998f9e3611107d843e838ca750abf6c0f0a52602183c5b860b
7
+ data.tar.gz: 44e59bb6cd13a5c813d220e023be9f97a50062b3259d662c5b78ea5cd0a7e7265948c3cc7b96bc23b1370357cfff051aa01d3b0b29e28189057c6d565e370aee
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.8)
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
 
@@ -20,7 +20,7 @@ TODO: Write usage instructions here
20
20
 
21
21
  ``` Ruby
22
22
  Default :
23
- AuthzJurnalClient::UserRoles.config(authorization: "Basic ApiToken")
23
+ AuthzJurnalClient::UserRoles.config(authorization: "Basic ApiToken") or AuthzJurnalClient::UserRoles.config(username: nil, password: nil)
24
24
  roles = AuthzJurnalClient::UserRoles.call(uid, cid)
25
25
  puts roles
26
26
 
@@ -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.8"
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,34 +10,51 @@ 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, :username, :password, :expiry, :cache
15
14
  def config(opts = {})
16
- @authorization = opts[:authorization]
17
- @headers = {"Authorization" => @authorization}
15
+ @username = opts[:username]
16
+ @password = opts[:password]
17
+ @authorization = init_auth(opts)
18
+ @headers = { "Authorization": @authorization }
18
19
  @domain = opts[:domain] || 'http://localhost:3000'
19
20
  redis_path = opts[:redis] || 'redis://localhost:6379'
20
21
  @redis = Redis.new(url: redis_path)
21
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]
28
+
29
+ if @username && @password
30
+ @authorization = "Basic #{Base64.encode64("#{@username}:#{@password}")}"
31
+ end
32
+
33
+ @authorization
22
34
  end
23
35
 
24
36
  def call(id, cid)
25
- if @redis
37
+ return get_errors({ errors: { messages: "uid or cid cannot be blank!" } }) if id.nil? || cid.nil?
38
+
39
+ if @redis && @cache
26
40
  cached = @redis.get(make_key(id, cid))
27
- return get_roles(cached) if cached
41
+ return get_response(cached) if cached
28
42
  end
29
43
 
30
44
  response = backend_request(id, cid)
31
- return unless response.success?
45
+ return get_errors(JSON.parse(response.body)) if !response.success?
32
46
 
33
47
  @redis&.setex(make_key(id, cid), @expiry, response.body)
34
- get_roles(response.body)
48
+ get_response(response.body)
35
49
  rescue Redis::CannotConnectError
36
50
  response = backend_request(id, cid)
37
- get_roles(response.body)
51
+ get_response(response.body)
38
52
  end
39
53
 
40
54
  def backend_request(id, cid)
41
55
  conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
56
+ f.options.open_timeout = 10
57
+ f.options.timeout = 60
42
58
  f.adapter :net_http
43
59
  end
44
60
 
@@ -49,9 +65,15 @@ module AuthzJurnalClient
49
65
  "manage_roles:#{id}-#{cid}"
50
66
  end
51
67
 
52
- def get_roles(j)
68
+ def get_response(j)
53
69
  data = eval(j)
54
- JSON.parse( data.to_json, object_class: OpenStruct).data.roles
70
+ response = JSON.parse(data.to_json, object_class: OpenStruct)
71
+ response.data.roles
72
+ end
73
+
74
+ def get_errors(e)
75
+ data = e.is_a?(Hash) ? e : eval(e)
76
+ JSON.parse(data.to_json, object_class: OpenStruct)
55
77
  end
56
78
  end
57
79
  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.8
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-13 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