dina 0.4.3.0 → 0.5.0.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: 32052c3bba673462b3f37308893e0e75a2d6b90c8cf83bb015afdb114605079f
4
- data.tar.gz: d907470232863681e01a113f55a968d092dc76dd059471906f39c72151ab6837
3
+ metadata.gz: cee08dca65cf1c04b4c2b03aa08e9686a4684ea96b484fe6a4b1a9e32d8001a8
4
+ data.tar.gz: c247128c86df604291f3ec985254e59bc676b120481e8a8736c1033d3adfb063
5
5
  SHA512:
6
- metadata.gz: 459d73f40c8133a76ae7596d4aa8aa58665337fac57e591dfc10a76b4a0ef03398ff1331c537d98be2434182af0b35e216477e424e3ef2532ef70853cfe6ed96
7
- data.tar.gz: 6386e868c47a886466ff7fd905c9854f1f3ff701cf99fd58243fc37966a233e2bb4758c84e8b20bf0914dfac6a34f26e0e4dd656ac0681068e3ab9627a98ee59
6
+ metadata.gz: 78ea88a086216ae6a5d27c6121cc6d345537a17902a9cd2c0dd4caaf4748a9c45d3c5243ea8d06d4ffa7d09c57a7da0092677bc20e3187d16f7517782ef3af2e
7
+ data.tar.gz: da1011c76dcd1fb72f1cd26623cb0cf02835535b091bb19e3bcd76cc393343e238b3ffde0419ff98c53f90a5278d0d0908ccff481f9e10ffe6f6a46c11cca580
@@ -11,23 +11,34 @@ module Dina
11
11
  # password: "password provided by DINA admin in Keycloak",
12
12
  # server_name: "used locally to reference the token",
13
13
  # client_id: "provided by DINA admin in Keycloak",
14
- # endpoint_url: "DINA API URL",
15
- # authorization_url: "Keycloak authorization URL".
14
+ # endpoint_url: "DINA API URL without terminating slash",
15
+ # authorization_url: "Keycloak authorization URL without terminating slash".
16
16
  # realm: "provided by DINA admin in Keycloak"
17
17
  # }
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
@@ -12,7 +12,7 @@ module Dina
12
12
  end
13
13
 
14
14
  def self.site
15
- Dina::Authentication.endpoint_url + endpoint_path
15
+ Dina::Authentication.endpoint_url + "/" + endpoint_path
16
16
  end
17
17
 
18
18
  def self.custom_headers
data/lib/dina/version.rb CHANGED
@@ -2,8 +2,8 @@ module Dina
2
2
  class Version
3
3
 
4
4
  MAJOR = 0
5
- MINOR = 4
6
- PATCH = 3
5
+ MINOR = 5
6
+ PATCH = 0
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.3.0
4
+ version: 0.5.0.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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client