dina 0.4.3.0 → 0.4.4.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: 3a77888d0a10acb3970bf9591e736bc8659d4bd4df79d7da5635b59db1e6c26d
4
+ data.tar.gz: 1ba52d47cff3f85e4d0bed7ec62b388fc51f2e8a00f35dd7e578f310f0452a75
5
5
  SHA512:
6
- metadata.gz: 459d73f40c8133a76ae7596d4aa8aa58665337fac57e591dfc10a76b4a0ef03398ff1331c537d98be2434182af0b35e216477e424e3ef2532ef70853cfe6ed96
7
- data.tar.gz: 6386e868c47a886466ff7fd905c9854f1f3ff701cf99fd58243fc37966a233e2bb4758c84e8b20bf0914dfac6a34f26e0e4dd656ac0681068e3ab9627a98ee59
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
data/lib/dina/version.rb CHANGED
@@ -3,7 +3,7 @@ module Dina
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- PATCH = 3
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.3.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