authz_jurnal_client 0.0.4 → 0.0.7

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: f666ee3dfcb96b541d4d42723339c94c355604d621e63b38ccc6df3a538650c0
4
- data.tar.gz: f284cda68f01a13f457a8d82da96c29c33e41ebba867b542ecf96277f35522bb
3
+ metadata.gz: d069465c6785118e6e04894f5e8b876d782d240db6a0202086f9891e8cba5e10
4
+ data.tar.gz: c2c16f5fe8092437ad332a843544fd284865ba291509f10fd8d586740eaf03e0
5
5
  SHA512:
6
- metadata.gz: a52f1516d6fda62d895c46e84fa9f18ebcc7c91a3a593e0b788fe7b04d2416a8258e0a3794fbd091b5b581ca198c4948c6639b31184db2ae3b847316e1d1113d
7
- data.tar.gz: b83d991c7bf622a46f6579e4dbf4b168b48b8d879aeb6f9c042c5903b6c310b242c8d9aeec0340160ddb4fbda427adf55c2892db212d3d4746f67a6371309f93
6
+ metadata.gz: d041033d4ee886da9f2568f34b4737252b8c996dd29b47f143bd80682b8cb67a2f0b16691550860c0ea649e8cf39437a46918e4643751c58b17f809ef6f17fb2
7
+ data.tar.gz: a7fc7343a40bba4805b8d0796f9db0b3d7fafe5e7654938eae98d92548aa4676c6b6136bb1fa48555cba40659a4b6c128333c7399e0ecb05fbb676d1516c78ba
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
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.4)
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
@@ -0,0 +1,54 @@
1
+ # AuthzJurnalClient
2
+
3
+ AuthzJurnalClient allows you to access the user roles API directly. It also provides the advantage of managing the caching
4
+
5
+
6
+ ## Installation
7
+
8
+
9
+
10
+ Install the gem thusly in the gemfile
11
+
12
+ ``` markdown
13
+ gem 'authz_jurnal_client', git: 'git@bitbucket.org:jurnal/authz-jurnal-client.git', tag: 'v0.0.1'
14
+ ```
15
+
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ``` Ruby
22
+ Default :
23
+ AuthzJurnalClient::UserRoles.config(authorization: "Basic ApiToken")
24
+ roles = AuthzJurnalClient::UserRoles.call(uid, cid)
25
+ puts roles
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
31
+ ```
32
+
33
+ The response is a json parsed Openstruct
34
+
35
+ See tests for more details.
36
+
37
+
38
+
39
+ ### For hacking on the GEM
40
+
41
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/authz_jurnal_client`. To experiment with that code, run `bin/console` for an interactive prompt.
42
+
43
+
44
+
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem into your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/authz_jurnal_client.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuthzJurnalClient
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.7"
5
5
  end
@@ -10,33 +10,41 @@ module AuthzJurnalClient
10
10
 
11
11
  class UserRoles
12
12
  class << self
13
- attr_accessor :redis, :domain, :authorization, :expiry
13
+ attr_accessor :redis, :domain, :authorization, :expiry, :cache
14
14
  def config(opts = {})
15
- @headers = {"Authorization" => "#{opts[:authorization]}"}
15
+ @authorization = opts[:authorization]
16
+ @headers = {"Authorization" => @authorization}
16
17
  @domain = opts[:domain] || 'http://localhost:3000'
17
18
  redis_path = opts[:redis] || 'redis://localhost:6379'
18
19
  @redis = Redis.new(url: redis_path)
19
- @expiry = opts[:expiry] || 3600 * 5
20
+ @expiry = opts[:expiry] || 3600
21
+ @cache = opts[:cache].nil? ? true : opts[:cache]
20
22
  end
21
23
 
22
24
  def call(id, cid)
23
- if @redis
25
+ return get_errors({errors: { messages: "uid or cid cannot be blank!"}}) if id.nil? || cid.nil?
26
+
27
+ if @redis && @cache
24
28
  cached = @redis.get(make_key(id, cid))
25
- return get_roles(cached) if cached
29
+ return get_response(cached) if cached
26
30
  end
27
31
 
28
32
  response = backend_request(id, cid)
29
- return unless response.success?
33
+ if !response.success?
34
+ return get_errors({errors: { messages: "request failed to fetch data!"}})
35
+ end
30
36
 
31
37
  @redis&.setex(make_key(id, cid), @expiry, response.body)
32
- get_roles(response.body)
38
+ get_response(response.body)
33
39
  rescue Redis::CannotConnectError
34
40
  response = backend_request(id, cid)
35
- get_roles(response.body)
41
+ get_response(response.body)
36
42
  end
37
43
 
38
44
  def backend_request(id, cid)
39
45
  conn = Faraday.new("#{@domain}/api/v1/users/#{id}") do |f|
46
+ f.options.open_timeout = 10
47
+ f.options.timeout = 60
40
48
  f.adapter :net_http
41
49
  end
42
50
 
@@ -47,9 +55,15 @@ module AuthzJurnalClient
47
55
  "manage_roles:#{id}-#{cid}"
48
56
  end
49
57
 
50
- def get_roles(j)
51
- res = JSON.parse(j)
52
- res['data']['roles'] if res['data'] && res['data']['roles']
58
+ def get_response(j)
59
+ data = eval(j)
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)
53
67
  end
54
68
  end
55
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.4
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-02 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,17 +17,15 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".rspec"
20
21
  - Gemfile
21
22
  - Gemfile.lock
22
23
  - README.md
23
24
  - 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
25
  - lib/authz_jurnal_client.rb
28
26
  - lib/authz_jurnal_client/version.rb
29
27
  - lib/sig/authz_jurnal_client.rbs
30
- homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/nat-dev/
28
+ homepage: https://bitbucket.org/jurnal/authz-jurnal-client/src/master/
31
29
  licenses: []
32
30
  metadata: {}
33
31
  post_install_message:
Binary file
Binary file
Binary file