dina 0.5.9.1 → 0.6.1.0

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: 7dce66cc9ad35b27eaf11fd314027b06def22bab64025b4ee79de9b3a8b22f1a
4
- data.tar.gz: 6bf96dfc20327ca42e450c42e2dd8a0c1d5c2a025f09127a118077b3ff742968
3
+ metadata.gz: fce6aa7545f2fe1bb7a340fd5ef64fb85ed56e50ad12b970a37cad5d0ba3bfc2
4
+ data.tar.gz: 532c2e30e916fe27a13b3739efccd5adb770f12e4b6706f2fed7eec4276b80b8
5
5
  SHA512:
6
- metadata.gz: 476b81d9353c5c05f5f1c744cf4b00555bd7a9337ee6a2569689c270fdd280c521c696c84ab2df466350e52f502a6c728a920f958d55ce358b7e836266ae5439
7
- data.tar.gz: fb0f7c3f96d1576c7a0c211d20640a429b51c6d69dab3c8a15d62a4ce1fa3231b2491d5410c134948e9355aaadda29f600bd94b6588a8a090779780eeb0430da
6
+ metadata.gz: 2e7ff2cd1b927195c3c17d7986e31bc60fad738dff9f7198029af2e822673b05d8ea5748db0e7aeb330fd1cd59366a5e75870556fd7cf7b74d8160b8558fa79b
7
+ data.tar.gz: 95f10aa0889f8eb03b782925458398ba1ed7c066df7cb5ff94c630710170a1fd567381334207242381d6e4736cb960c4fd4edad29b047ba7328ff86aa40ae5b1
@@ -61,6 +61,31 @@ module Dina
61
61
  "Bearer " + access_token
62
62
  end
63
63
 
64
+ # Flushes instance variables from memory
65
+ # but token store file content remains intact
66
+ def self.flush_variables
67
+ @token = nil
68
+ @token_store_file = nil
69
+ @user = nil
70
+ @password = nil
71
+ @server_name = nil
72
+ @client_id = nil
73
+ @endpoint_url = nil
74
+ Keycloak.auth_server_url = nil
75
+ Keycloak.realm = nil
76
+ end
77
+
78
+ # Saves default values in token store file
79
+ def self.flush_token
80
+ create_empty_token
81
+ end
82
+
83
+ # Flush instance variables and save default values in token store file
84
+ def self.flush
85
+ flush_variables
86
+ flush_token
87
+ end
88
+
64
89
  class << self
65
90
  attr_accessor :endpoint_url
66
91
 
@@ -68,7 +93,7 @@ module Dina
68
93
 
69
94
  def access_token
70
95
  begin
71
- read_token[@server_name.to_sym][:access_token]
96
+ token[@server_name.to_sym][:access_token]
72
97
  rescue
73
98
  raise TokenStoreContentInvalid
74
99
  end
@@ -76,7 +101,7 @@ module Dina
76
101
 
77
102
  def refresh_token
78
103
  begin
79
- read_token[@server_name.to_sym][:refresh_token]
104
+ token[@server_name.to_sym][:refresh_token]
80
105
  rescue
81
106
  raise TokenStoreContentInvalid
82
107
  end
@@ -84,7 +109,7 @@ module Dina
84
109
 
85
110
  def auth_expiry
86
111
  begin
87
- read_token[@server_name.to_sym][:auth_expiry]
112
+ token[@server_name.to_sym][:auth_expiry]
88
113
  rescue
89
114
  raise TokenStoreContentInvalid
90
115
  end
@@ -119,28 +144,33 @@ module Dina
119
144
  end
120
145
  end
121
146
 
122
- def read_token
123
- JSON.parse(::File.read(@token_store_file), symbolize_names: true)
147
+ def token
148
+ @token ||= JSON.parse(::File.read(@token_store_file), symbolize_names: true)
124
149
  end
125
150
 
126
151
  def create_empty_token
127
- data_hash = {}
128
- data_hash[@server_name.to_sym] = {
152
+ data = {}
153
+ data[@server_name.to_sym] = {
129
154
  access_token: nil,
130
155
  refresh_token: nil,
131
156
  auth_expiry: nil
132
157
  }
133
- ::File.write(@token_store_file, JSON.dump(data_hash))
158
+ write_token(data: data)
134
159
  end
135
160
 
136
161
  def save_token(access_token:, refresh_token:, auth_expiry:)
137
- data_hash = JSON.parse(::File.read(@token_store_file), symbolize_names: true) rescue {}
138
- data_hash[@server_name.to_sym] = {
162
+ data = JSON.parse(::File.read(@token_store_file), symbolize_names: true) rescue {}
163
+ data[@server_name.to_sym] = {
139
164
  access_token: access_token,
140
165
  refresh_token: refresh_token,
141
166
  auth_expiry: auth_expiry
142
167
  }
143
- ::File.write(@token_store_file, JSON.dump(data_hash))
168
+ write_token(data: data)
169
+ end
170
+
171
+ def write_token(data:)
172
+ ::File.write(@token_store_file, JSON.dump(data))
173
+ @token = data
144
174
  end
145
175
 
146
176
  end
@@ -8,21 +8,28 @@ module Dina
8
8
  before_create :on_before_create
9
9
  before_save :on_before_save
10
10
 
11
+ # Required by json_api_client
12
+ # Set by all child classes
11
13
  def self.endpoint_path
12
14
  end
13
15
 
16
+ # Required by json_api_client
14
17
  def self.site
18
+ raise ConfigItemMissing, "Missing endpoint_url from config. Perhaps Dina::Authentication.config has not yet been called." unless Dina::Authentication.endpoint_url
15
19
  Dina::Authentication.endpoint_url + "/" + endpoint_path
16
20
  end
17
21
 
22
+ # injects keybloak bearer token with all json_api_client calls
18
23
  def self.custom_headers
19
24
  { content_type: "application/vnd.api+json", authorization: Dina::Authentication.header }
20
25
  end
21
26
 
27
+ # helper method for all child classes to retrieve records by group
22
28
  def self.find_by_group(group, page: 1, per: 50)
23
29
  self.where("group.groupName": group).page(page).per(per)
24
30
  end
25
31
 
32
+ # helper method to retrieve all properties for a class
26
33
  def self.properties
27
34
  self.schema.instance_values["properties"]
28
35
  end
data/lib/dina/version.rb CHANGED
@@ -2,9 +2,9 @@ module Dina
2
2
  class Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 5
6
- PATCH = 9
7
- BUILD = 1
5
+ MINOR = 6
6
+ PATCH = 1
7
+ BUILD = 0
8
8
 
9
9
  def self.version
10
10
  [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
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.5.9.1
4
+ version: 0.6.1.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-22 00:00:00.000000000 Z
11
+ date: 2022-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client