dina 0.7.0.0 → 0.7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dina/authentication/authentication.rb +55 -42
- data/lib/dina/models/base_model.rb +2 -2
- data/lib/dina/models/object_store/file.rb +1 -1
- data/lib/dina/search/base_search.rb +2 -2
- data/lib/dina/version.rb +1 -1
- data/lib/dina.rb +14 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a0d3f25267c47fba2fa7e0cf5df80602065c1d182578d48522d0f1f81815fef
|
4
|
+
data.tar.gz: cf53d98747de1528002a5e4c9b88c8e245ff98e2beebfb5d1a9c3047f38bff33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f80d1a0565a76412d07a4367d4c6b1085c5042fcac24d83d231d5699c071da560219a11451a9928f01df4702233bfe70dfff7bfca267b7e1aac7a0f0b2c443bf
|
7
|
+
data.tar.gz: d462deb63117f46c998df5ff471d9a809289bce7f411c9b6a50447e71b87c9826e134e881812205003a6c8f03440d7506c33d46cb7401aa66e169ec8c606f1ac
|
@@ -4,8 +4,6 @@ module Dina
|
|
4
4
|
class Authentication
|
5
5
|
|
6
6
|
class << self
|
7
|
-
attr_accessor :endpoint_url
|
8
|
-
|
9
7
|
def instance
|
10
8
|
Thread.current[:dina_authentication] ||= new
|
11
9
|
end
|
@@ -13,12 +11,12 @@ module Dina
|
|
13
11
|
|
14
12
|
def initialize
|
15
13
|
@token = nil
|
16
|
-
@
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@
|
14
|
+
@config = nil
|
15
|
+
@opts = default_opts
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
@config ||= OpenStruct.new(@opts)
|
22
20
|
end
|
23
21
|
|
24
22
|
# Sets Authentication configuration
|
@@ -35,31 +33,27 @@ module Dina
|
|
35
33
|
# }
|
36
34
|
#
|
37
35
|
# @param options [Hash] the configuration options
|
38
|
-
def config(
|
39
|
-
raise ConfigItemMissing, "Missing token_store_file from config." unless
|
40
|
-
raise ConfigItemMissing, "Missing user from config." unless
|
41
|
-
raise ConfigItemMissing, "Missing password from config." unless
|
42
|
-
raise ConfigItemMissing, "Missing server_name from config." unless
|
43
|
-
raise ConfigItemMissing, "Missing client_id from config." unless
|
44
|
-
raise ConfigItemMissing, "Missing endpoint_url from config." unless
|
45
|
-
raise ConfigItemMissing, "Missing authorization_url from config." unless
|
46
|
-
raise ConfigItemMissing, "Missing realm from config." unless
|
47
|
-
|
48
|
-
if !
|
36
|
+
def config=(opts = {})
|
37
|
+
raise ConfigItemMissing, "Missing token_store_file from config." unless opts[:token_store_file]
|
38
|
+
raise ConfigItemMissing, "Missing user from config." unless opts[:user]
|
39
|
+
raise ConfigItemMissing, "Missing password from config." unless opts[:password]
|
40
|
+
raise ConfigItemMissing, "Missing server_name from config." unless opts[:server_name]
|
41
|
+
raise ConfigItemMissing, "Missing client_id from config." unless opts[:client_id]
|
42
|
+
raise ConfigItemMissing, "Missing endpoint_url from config." unless opts[:endpoint_url]
|
43
|
+
raise ConfigItemMissing, "Missing authorization_url from config." unless opts[:authorization_url]
|
44
|
+
raise ConfigItemMissing, "Missing realm from config." unless opts[:realm]
|
45
|
+
|
46
|
+
if !opts[:token_store_file].instance_of?(String) || !::File.exist?(opts[:token_store_file])
|
49
47
|
raise TokenStoreFileNotFound
|
50
48
|
end
|
51
49
|
|
52
50
|
@token = nil
|
53
|
-
@
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
Keycloak.auth_server_url = options[:authorization_url]
|
60
|
-
Keycloak.realm = options[:realm]
|
61
|
-
|
62
|
-
if ::File.zero?(@token_store_file)
|
51
|
+
@config = nil
|
52
|
+
@opts.merge!(opts)
|
53
|
+
Keycloak.auth_server_url = config.authorization_url
|
54
|
+
Keycloak.realm = config.realm
|
55
|
+
|
56
|
+
if ::File.zero?(config.token_store_file)
|
63
57
|
write_token(data: empty_token)
|
64
58
|
end
|
65
59
|
end
|
@@ -83,16 +77,35 @@ module Dina
|
|
83
77
|
"Bearer " + access_token
|
84
78
|
end
|
85
79
|
|
86
|
-
#
|
80
|
+
# Save default values in token store file
|
87
81
|
def flush
|
88
82
|
write_token(data: empty_token)
|
89
83
|
end
|
90
84
|
|
85
|
+
def flush_config
|
86
|
+
@opts = default_opts
|
87
|
+
@config = nil
|
88
|
+
@token = nil
|
89
|
+
end
|
90
|
+
|
91
91
|
private
|
92
92
|
|
93
|
+
def default_opts
|
94
|
+
{
|
95
|
+
token_store_file: nil,
|
96
|
+
user: nil,
|
97
|
+
password: nil,
|
98
|
+
server_name: nil,
|
99
|
+
client_id: nil,
|
100
|
+
endpoint_url: nil,
|
101
|
+
realm: nil,
|
102
|
+
authorization_url: nil
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
93
106
|
def access_token
|
94
107
|
begin
|
95
|
-
token[
|
108
|
+
token[config.server_name.to_sym][:access_token]
|
96
109
|
rescue
|
97
110
|
raise TokenStoreContentInvalid
|
98
111
|
end
|
@@ -100,7 +113,7 @@ module Dina
|
|
100
113
|
|
101
114
|
def refresh_token
|
102
115
|
begin
|
103
|
-
token[
|
116
|
+
token[config.server_name.to_sym][:refresh_token]
|
104
117
|
rescue
|
105
118
|
raise TokenStoreContentInvalid
|
106
119
|
end
|
@@ -108,7 +121,7 @@ module Dina
|
|
108
121
|
|
109
122
|
def auth_expiry
|
110
123
|
begin
|
111
|
-
token[
|
124
|
+
token[config.server_name.to_sym][:auth_expiry]
|
112
125
|
rescue
|
113
126
|
raise TokenStoreContentInvalid
|
114
127
|
end
|
@@ -116,9 +129,9 @@ module Dina
|
|
116
129
|
|
117
130
|
def get_token
|
118
131
|
response = Keycloak::Client.get_token(
|
119
|
-
|
120
|
-
|
121
|
-
client_id=
|
132
|
+
config.user,
|
133
|
+
config.password,
|
134
|
+
client_id= config.client_id,
|
122
135
|
secret='')
|
123
136
|
JSON.parse(response, symbolize_names: true)
|
124
137
|
end
|
@@ -133,7 +146,7 @@ module Dina
|
|
133
146
|
begin
|
134
147
|
response = Keycloak::Client.get_token_by_refresh_token(
|
135
148
|
refresh_token,
|
136
|
-
client_id=
|
149
|
+
client_id= config.client_id,
|
137
150
|
secret='')
|
138
151
|
json = JSON.parse(response, symbolize_names: true)
|
139
152
|
auth_expiry = (Time.now + json[:expires_in].seconds).to_s
|
@@ -144,12 +157,12 @@ module Dina
|
|
144
157
|
end
|
145
158
|
|
146
159
|
def token
|
147
|
-
@token ||= JSON.parse(::File.read(
|
160
|
+
@token ||= JSON.parse(::File.read(config.token_store_file), symbolize_names: true)
|
148
161
|
end
|
149
162
|
|
150
163
|
def empty_token
|
151
164
|
data = {}
|
152
|
-
data[
|
165
|
+
data[config.server_name.to_sym] = {
|
153
166
|
access_token: nil,
|
154
167
|
refresh_token: nil,
|
155
168
|
auth_expiry: nil
|
@@ -158,8 +171,8 @@ module Dina
|
|
158
171
|
end
|
159
172
|
|
160
173
|
def save_token(access_token:, refresh_token:, auth_expiry:)
|
161
|
-
data = JSON.parse(::File.read(
|
162
|
-
data[
|
174
|
+
data = JSON.parse(::File.read(config.token_store_file), symbolize_names: true) rescue {}
|
175
|
+
data[config.server_name.to_sym] = {
|
163
176
|
access_token: access_token,
|
164
177
|
refresh_token: refresh_token,
|
165
178
|
auth_expiry: auth_expiry
|
@@ -168,7 +181,7 @@ module Dina
|
|
168
181
|
end
|
169
182
|
|
170
183
|
def write_token(data:)
|
171
|
-
::File.write(
|
184
|
+
::File.write(config.token_store_file, JSON.dump(data))
|
172
185
|
@token = data
|
173
186
|
end
|
174
187
|
|
@@ -15,8 +15,8 @@ module Dina
|
|
15
15
|
|
16
16
|
# Required by json_api_client
|
17
17
|
def self.site
|
18
|
-
raise ConfigItemMissing, "Missing endpoint_url from config. Perhaps Dina.config has not yet been called." unless
|
19
|
-
|
18
|
+
raise ConfigItemMissing, "Missing endpoint_url from config. Perhaps Dina.config has not yet been called." unless Dina.config.endpoint_url
|
19
|
+
Dina.config.endpoint_url + "/" + endpoint_path
|
20
20
|
end
|
21
21
|
|
22
22
|
# injects keybloak bearer token with all json_api_client calls
|
@@ -10,7 +10,7 @@ module Dina
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.endpoint
|
13
|
-
Dina
|
13
|
+
Dina.config.endpoint_url
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.endpoint_path
|
@@ -43,7 +43,7 @@ module Dina
|
|
43
43
|
headers: {
|
44
44
|
accept: 'application/json',
|
45
45
|
content_type: 'application/json',
|
46
|
-
authorization: Dina
|
46
|
+
authorization: Dina.header
|
47
47
|
},
|
48
48
|
verify_ssl: verify_ssl
|
49
49
|
)
|
data/lib/dina/version.rb
CHANGED
data/lib/dina.rb
CHANGED
@@ -9,10 +9,10 @@ module Dina
|
|
9
9
|
|
10
10
|
JsonApiClient::Paginating::NestedParamPaginator.page_param = "offset"
|
11
11
|
JsonApiClient::Paginating::NestedParamPaginator.per_page_param = "limit"
|
12
|
-
JsonApiClient::Schema.register array:
|
13
|
-
JsonApiClient::Schema.register object:
|
14
|
-
JsonApiClient::Schema.register multilingual_title:
|
15
|
-
JsonApiClient::Schema.register multilingual_description:
|
12
|
+
JsonApiClient::Schema.register array: ArrayCaster
|
13
|
+
JsonApiClient::Schema.register object: ObjectCaster
|
14
|
+
JsonApiClient::Schema.register multilingual_title: MultilingualTitleCaster
|
15
|
+
JsonApiClient::Schema.register multilingual_description: MultilingualDescriptionCaster
|
16
16
|
|
17
17
|
module_function
|
18
18
|
|
@@ -20,8 +20,12 @@ module Dina
|
|
20
20
|
BaseModel.subclasses
|
21
21
|
end
|
22
22
|
|
23
|
-
def config
|
24
|
-
Authentication.instance.config
|
23
|
+
def config
|
24
|
+
Authentication.instance.config
|
25
|
+
end
|
26
|
+
|
27
|
+
def config=(options = {})
|
28
|
+
Authentication.instance.config = options
|
25
29
|
end
|
26
30
|
|
27
31
|
def header
|
@@ -32,4 +36,8 @@ module Dina
|
|
32
36
|
Authentication.instance.flush
|
33
37
|
end
|
34
38
|
|
39
|
+
def flush_config
|
40
|
+
Authentication.instance.flush_config
|
41
|
+
end
|
42
|
+
|
35
43
|
end
|
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.7.
|
4
|
+
version: 0.7.2.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: 2023-01-
|
11
|
+
date: 2023-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|