dina 0.4.2.0 → 0.4.4.0

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: 868b096ec196f62ae6cf4507cadf08c277b26f462957873140abc93ecf88a1a6
4
- data.tar.gz: 26c127ec2bf4e6e9c990b4361aff69d1ce9f6a5e578ae01065472e8ede524bf5
3
+ metadata.gz: 3a77888d0a10acb3970bf9591e736bc8659d4bd4df79d7da5635b59db1e6c26d
4
+ data.tar.gz: 1ba52d47cff3f85e4d0bed7ec62b388fc51f2e8a00f35dd7e578f310f0452a75
5
5
  SHA512:
6
- metadata.gz: 9fcd3ceca0594b95caaea14870a0ff6ebc9284fab58eac5e98bd236c04e8235b4fb542c720cba9c394b63b719a4883642f82e0871b347a9a18c5225c8e42e5b6
7
- data.tar.gz: 95d262c72d8955a9eb944886efcd0784af500f4f8235846bc062a69d5128652e0af0260d85f7243bd608e8d2bd3f895a309cc752baac6b742282f84db658f88e
6
+ metadata.gz: 7ff956f4b1fe2d20d22a2f98e9139e0812e54f1c05433a8a5bd8372880258662fdc27d81ccd75d55d5037f3f12a9490e1e1b7bc93faf33d4cd2a8bc47ca3b212
7
+ data.tar.gz: 8cc16fd12372ad0e50fd5b90b0ac25c83fb9b389e76f06e60cf4f613a3a5b44e0262e5ec0a379518d0be332d005e314de7457c600d033a4b8730745ac56ff996
@@ -18,16 +18,27 @@ module Dina
18
18
  #
19
19
  # @param options [Hash] the configuration options
20
20
  def self.config(options = {})
21
+ raise ConfigItemMissing, "Missing token_store_file from config." unless options[:token_store_file]
22
+ raise ConfigItemMissing, "Missing user from config." unless options[:user]
23
+ raise ConfigItemMissing, "Missing password from config." unless options[:password]
24
+ raise ConfigItemMissing, "Missing server_name from config." unless options[:server_name]
25
+ raise ConfigItemMissing, "Missing client_id from config." unless options[:client_id]
26
+ raise ConfigItemMissing, "Missing endpoint_url from config." unless options[:endpoint_url]
27
+ raise ConfigItemMissing, "Missing authorization_url from config." unless options[:authorization_url]
28
+ raise ConfigItemMissing, "Missing realm from config." unless options[:realm]
29
+
30
+ if !options[:token_store_file].instance_of?(String) || !::File.exist?(options[:token_store_file])
31
+ raise TokenStoreFileNotFound
32
+ end
33
+
21
34
  @token_store_file = options[:token_store_file]
22
35
  @user = options[:user]
23
36
  @password = options[:password]
24
37
  @server_name = options[:server_name]
25
38
  @client_id = options[:client_id]
26
39
  @endpoint_url = options[:endpoint_url]
27
- @authorization_url = options[:authorization_url]
28
- @realm = options[:realm]
29
- Keycloak.auth_server_url = @authorization_url
30
- Keycloak.realm = @realm
40
+ Keycloak.auth_server_url = options[:authorization_url]
41
+ Keycloak.realm = options[:realm]
31
42
  end
32
43
 
33
44
  # Gets, sets, and renews a Bearer access token as required
@@ -47,10 +58,34 @@ module Dina
47
58
  end
48
59
 
49
60
  class << self
50
- attr_accessor :token_store_file, :authorization_url, :endpoint_url, :client_id, :realm, :server_name
61
+ attr_accessor :endpoint_url
51
62
 
52
63
  private
53
64
 
65
+ def access_token
66
+ begin
67
+ read_token[@server_name.to_sym][:access_token]
68
+ rescue
69
+ raise TokenStoreContentInvalid
70
+ end
71
+ end
72
+
73
+ def refresh_token
74
+ begin
75
+ read_token[@server_name.to_sym][:refresh_token]
76
+ rescue
77
+ raise TokenStoreContentInvalid
78
+ end
79
+ end
80
+
81
+ def auth_expiry
82
+ begin
83
+ read_token[@server_name.to_sym][:auth_expiry]
84
+ rescue
85
+ raise TokenStoreContentInvalid
86
+ end
87
+ end
88
+
54
89
  def get_token
55
90
  response = Keycloak::Client.get_token(
56
91
  @user,
@@ -80,29 +115,11 @@ module Dina
80
115
  end
81
116
  end
82
117
 
83
- def access_token
84
- read_token[:access_token]
85
- end
86
-
87
- def refresh_token
88
- read_token[:refresh_token]
89
- end
90
-
91
- def auth_expiry
92
- read_token[:auth_expiry] rescue "9999-01-01 00:00:00 -0500"
93
- end
94
-
95
118
  def read_token
96
- raise TokenStoreFileNotFound unless @token_store_file.instance_of?(String) && ::File.exist?(@token_store_file)
97
- JSON.parse(::File.read(@token_store_file), symbolize_names: true)[@server_name.to_sym] rescue default_token
98
- end
99
-
100
- def default_token
101
- { access_token: nil, refresh_token: nil, auth_expiry: "9999-01-01 00:00:00 -0500" }
119
+ JSON.parse(::File.read(@token_store_file), symbolize_names: true)
102
120
  end
103
121
 
104
122
  def save_token(access_token:, refresh_token:, auth_expiry:)
105
- raise TokenStoreFileNotFound unless @token_store_file.instance_of?(String) && ::File.exist?(@token_store_file)
106
123
  data_hash = JSON.parse(::File.read(@token_store_file), symbolize_names: true) rescue {}
107
124
  data_hash[@server_name.to_sym] = {
108
125
  access_token: access_token,
@@ -1,6 +1,8 @@
1
1
  module Dina
2
2
  class DinaException < StandardError; end
3
3
  class TokenStoreFileNotFound < DinaException; end
4
+ class TokenStoreContentInvalid < DinaException; end
5
+ class ConfigItemMissing < DinaException; end
4
6
  class ObjectInvalid < DinaException; end
5
7
  class PropertyValueInvalid < ObjectInvalid; end
6
8
  end
@@ -3,7 +3,7 @@ module JsonApiClient
3
3
  module Associations
4
4
  class BaseAssociation
5
5
  def data(url)
6
- url.sub!("/api/v1/", "/api/#{association_class.requestor.instance_variable_get(:@klass).endpoint_path}")
6
+ url.sub!("/api/v1/", "/api/#{klass.endpoint_path}")
7
7
  from_result_set(association_class.requestor.linked(url))
8
8
  end
9
9
  end
data/lib/dina/version.rb CHANGED
@@ -3,7 +3,7 @@ module Dina
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- PATCH = 2
6
+ PATCH = 4
7
7
  BUILD = 0
8
8
 
9
9
  def self.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2.0
4
+ version: 0.4.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David P. Shorthouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2022-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client