soar-registry-identity 4.0.3 → 5.0.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
  SHA1:
3
- metadata.gz: a84bab4718cef4c398bc0006cf5d726999aa4f67
4
- data.tar.gz: 270e3edf5048e84fe90ac88a4f9024cf9e0ef5fb
3
+ metadata.gz: 821dd803bad9432b1c2206c11c46708bed15d4e0
4
+ data.tar.gz: baea63429adf243703b68e74f9b3d0d46aac8d41
5
5
  SHA512:
6
- metadata.gz: 4dd8a44902cf4dd770f973fd48a2b49af45c1833ddc7bf251e3fc09f92f042c9626f98226be0ce68f8a513a6ad8c856f962a525f5c6a968464cc9892b93e69ad
7
- data.tar.gz: 83ab95c63f1410be7a7a6756b543b6c4e7dd7c72a2bc5f5e842ce3ff31741ebf1a85ee659e5e04a5fdab2b48ac22b2a0bd23e30714589fc1e06ee00663483440
6
+ metadata.gz: bf1e42b3b28c05e5f01c0b72a77fc82c287c9cfd2d8334b25dae439b3cae1663a06b6710acebb500d69659f3cf9669ed8f9fa13706324f31d2db21218ce0c09e
7
+ data.tar.gz: b577f82ccedd6db4a7b8d4a5b5f8f5798d4001623a67ad006defac2de9af286f71333f244e543684b731392e9832b13b60139820093c3027bc86766ee0b028c0
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  ## Quickstart
4
4
 
5
5
  ### Example data
6
+
6
7
  ```javascript
7
8
  identities = [{
8
9
  "uuid": "62936e70-1815-439b-bf89-8492855a7e6b",
@@ -23,6 +24,7 @@ Create a directory provider
23
24
  ```
24
25
 
25
26
  Create a directory
27
+
26
28
  ```ruby
27
29
  > directory = Soar::Registry::Directory.new(directory_provider)
28
30
  ```
@@ -32,7 +34,7 @@ Create a directory
32
34
  #### Manual instantiation
33
35
 
34
36
  ##### Staff Email IDR
35
- Search for identifiers by email address. Used by [soar-authentication-identity](https://github.com/hetznerZA/soar-authentication-identity) to translate an authenticated identifier to an UUID.
37
+ Search for identifiers by email address. Used by [soar-authentication-identity_uuid_translator](https://github.com/hetznerZA/soar-authentication-identity_uuid_translator) to translate an authenticated identifier to an UUID.
36
38
  ```ruby
37
39
  require 'soar/registry/identity'
38
40
  identity_provider = Soar::Registry::Identity::Provider::Staff::Email.new({
@@ -48,7 +50,8 @@ identity_provider = Soar::Registry::Identity::Provider::Staff::Email.new({
48
50
 
49
51
  #### Factory instantiation
50
52
 
51
- ##### Create a selector
53
+ Create a selector
54
+
52
55
  ```ruby
53
56
  > require 'object_selector'
54
57
  > selector = ObjectSelector.new(
@@ -83,7 +86,8 @@ identity_provider = Soar::Registry::Identity::Provider::Staff::Email.new({
83
86
  )
84
87
  ```
85
88
 
86
- ##### Get an IDR
89
+ Get an IDR
90
+
87
91
  ```ruby
88
92
  > selector_value = 'your-string-here'
89
93
  idr = Soar::Registry::Identity::Factory.create({
@@ -94,14 +98,16 @@ idr = Soar::Registry::Identity::Factory.create({
94
98
 
95
99
  ### Use your IDR
96
100
 
97
- ##### Getting a list of identifiers
101
+ Getting a list of identifiers
102
+
98
103
  ```ruby
99
104
  > identifiers = @email_idr.get_identifiers("admin@hetzner.co.za")
100
105
  > puts identifiers.inspect
101
106
  ["admin@hetzner.co.za", "identity-820d5660-2204-4f7d-8c04-746313439b81"]
102
107
  ```
103
108
 
104
- ### Getting a list of roles
109
+ Getting a list of roles
110
+
105
111
  ```ruby
106
112
  > roles = @uuid_idr.get_roles("identity-820d5660-2204-4f7d-8c04-746313439b81")
107
113
  > # get_roles is not applicable to staff email idr
@@ -109,7 +115,8 @@ idr = Soar::Registry::Identity::Factory.create({
109
115
  ["staff", "configuration_publisher", "configuration_consumer"]
110
116
  ```
111
117
 
112
- ### Getting a hash of attributes for a role
118
+ Getting a hash of attributes for a role
119
+
113
120
  ```ruby
114
121
  > role = 'staff'
115
122
  > attributes = @uuid_idr.get_attributes("identity-820d5660-2204-4f7d-8c04-746313439b81", role)
@@ -123,7 +130,8 @@ idr = Soar::Registry::Identity::Factory.create({
123
130
 
124
131
  ```
125
132
 
126
- ### Getting a hash of all attributes
133
+ Getting a hash of all attributes
134
+
127
135
  ```ruby
128
136
  > attributes = @uuid_idr.get_attributes("identity-820d5660-2204-4f7d-8c04-746313439b81")
129
137
  > # get_attributes is not applicate to staff email idr
@@ -154,15 +162,102 @@ idr = Soar::Registry::Identity::Factory.create({
154
162
  ## Tests
155
163
 
156
164
  ### Local
165
+
166
+ Start container dependencies
167
+
168
+ ```bash
169
+ $ docker-compose up --build --remove-orphans --force-recreate
170
+ ```
171
+
172
+ Soar::Registry::Identity::Provider::Customer::Uuid
173
+
157
174
  ```bash
158
- $ bundle exec rspec
175
+ $ CUSTOMER_DIRECTORY_CONFIG_FILE=config.mysql.yml ROLES_DIRECTORY_CONFIG_FILE=config.dynamo_db.yml TEST_ORCHESTRATION_PROVIDER=Customer::Uuid bundle exec cucumber
176
+ ```
177
+
178
+ Soar::Registry::Identity::Provider::Staff::Uuid
179
+
180
+ ```bash
181
+ $ STAFF_DIRECTORY_CONFIG_FILE=config.ldap.yml ROLES_DIRECTORY_CONFIG_FILE=config.dynamo_db.yml TEST_ORCHESTRATION_PROVIDER=Staff::Uuid bundle exec cucumber
182
+ ```
183
+
184
+ Soar::Registry::Identity::Provider::Staff::Email
185
+
186
+ ```bash
187
+ $ bundle exec rspec spec/staff/email_spec.rb
188
+ ```
189
+
190
+ Soar::Registry::Identity::Provider::Customer::Email
191
+
192
+ ```bash
193
+ $ bundle exec rspec spec/customer/email_spec.rb
194
+ ```
195
+
196
+ Soar::Registry::Identity::Provider::Customer::ClientNumber
197
+
198
+ ```bash
199
+ $ bundle exec rspec spec/customer/client_number_spec.rb
200
+ ```
201
+
202
+ Soar::Registry::Identity::Factory
203
+
204
+ ```bash
205
+ $ bundle exec rspec spec/authenticated_identity_factory_spec.rb spec/identity_uuid_factory_spec.rb
159
206
  ```
160
207
 
161
208
  ### CI
209
+
210
+ Soar::Registry::Identity::Provider::Staff::Email
211
+
212
+ ```bash
213
+ docker-compose --file docker-compose.ci.staff-email.yml --project-name soar-registry-identity-provider-staff-email up --abort-on-container-exit --remove-orphans --build --force-recreate
214
+ EXIT_CODE=$(docker ps -a -f "name=soarregistryidentityproviderstaffemail_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
215
+ docker-compose --file docker-compose.ci.staff-email.yml --project-name soar-registry-identity-provider-staff-email down --rmi local
216
+ exit $EXIT_CODE;
217
+ ```
218
+
219
+ Soar::Registry::Identity::Provider::Customer::Email
220
+
221
+ ```bash
222
+ docker-compose --file docker-compose.ci.customer-email.yml --project-name soar-registry-identity-provider-customer-email up --abort-on-container-exit --remove-orphans --build --force-recreate
223
+ EXIT_CODE=$(docker ps -a -f "name=soarregistryidentityprovidercustomeremail_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
224
+ docker-compose --file docker-compose.ci.customer-email.yml --project-name soar-registry-identity-provider-customer-email down --rmi local
225
+ exit $EXIT_CODE;
226
+ ```
227
+
228
+ Soar::Registry::Identity::Provider::Customer::ClientNumber
229
+
230
+ ```bash
231
+ docker-compose --file docker-compose.ci.customer-client_number.yml --project-name soar-registry-identity-provider-customer-client_number up --abort-on-container-exit --remove-orphans --build --force-recreate
232
+ EXIT_CODE=$(docker ps -a -f "name=soarregistryidentityprovidercustomerclientnumber_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
233
+ docker-compose --file docker-compose.ci.customer-client_number.yml --project-name soar-registry-identity-provider-customer-client_number down --rmi local
234
+ exit $EXIT_CODE;
235
+ ```
236
+
237
+ Soar::Registry::Identity::Factory
238
+
239
+ ```bash
240
+ docker-compose --file docker-compose.ci.factory.yml --project-name soar-registry-identity-factory up --abort-on-container-exit --remove-orphans --build --force-recreate
241
+ EXIT_CODE=$(docker ps -a -f "name=soarregistryidentityfactory_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
242
+ docker-compose --file docker-compose.ci.factory.yml --project-name soar-registry-identity-factory down --rmi local
243
+ exit $EXIT_CODE;
244
+ ```
245
+
246
+ Soar::Registry::Identity::Provider::Staff::Uuid
247
+
248
+ ```bash
249
+ docker-compose --file docker-compose.ci.staff-uuid.yml --project-name soar-registry-identity-provider-staff-uuid up --abort-on-container-exit --remove-orphans --build --force-recreate
250
+ EXIT_CODE=$(docker ps -a -f "name=soarregistryidentityproviderstaffuuid_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
251
+ docker-compose --file docker-compose.ci.staff-uuid.yml --project-name soar-registry-identity-provider-staff-uuid down --rmi local
252
+ exit $EXIT_CODE;
253
+ ```
254
+
255
+ Soar::Registry::Identity::Provider::Customer::Uuid
256
+
162
257
  ```bash
163
- docker-compose --file docker-compose.ci.yml --project-name soar-registry-identity up --abort-on-container-exit --remove-orphans --build --force-recreate
164
- EXIT_CODE=$(docker ps -a -f "name=soarregistryidentity_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
165
- docker-compose --file docker-compose.ci.yml --project-name soar-registry-identity down --rmi local
258
+ docker-compose --file docker-compose.ci.customer-uuid.yml --project-name soar-registry-identity-provider-customer-uuid up --abort-on-container-exit --remove-orphans --build --force-recreate
259
+ EXIT_CODE=$(docker ps -a -f "name=soarregistryidentityprovidercustomeruuid_tests" -q | xargs docker inspect -f "{{ .State.ExitCode }}");
260
+ docker-compose --file docker-compose.ci.customer-uuid.yml --project-name soar-registry-identity-provider-customer-uuid down --rmi local
166
261
  exit $EXIT_CODE;
167
262
  ```
168
263
 
@@ -6,7 +6,7 @@ module Soar
6
6
  class Factory
7
7
 
8
8
  ##
9
- # @param [String] value
9
+ # @param [String,Array] value
10
10
  # @param [ObjectSelector] selector
11
11
  # @raise [ObjectSelector::Error::NoMatchError]
12
12
  # @return [Soar::Registry::Identity]
@@ -2,6 +2,7 @@ require 'soar/registry/identity/provider/staff/email'
2
2
  require 'soar/registry/identity/provider/staff/uuid'
3
3
  require 'soar/registry/identity/provider/customer/client_number'
4
4
  require 'soar/registry/identity/provider/customer/email'
5
+ require 'soar/registry/identity/provider/customer/uuid'
5
6
 
6
7
  module Soar
7
8
  module Registry
@@ -15,7 +16,7 @@ module Soar
15
16
  end
16
17
 
17
18
  ##
18
- # @param [String] identifier
19
+ # @param [String] identifier
19
20
  # @return [Array<String>] list of roles
20
21
  ##
21
22
  def get_roles(identifier)
@@ -25,7 +26,8 @@ module Soar
25
26
  ##
26
27
  # @param [String] identifier
27
28
  # @param [String] role
28
- # @return [Hash] if a role is specified the returned hash is keyed by role
29
+ # @return [Hash{String => String, Hash, Number}]
30
+ # if a role is specified the returned hash is keyed by role
29
31
  # else it's keyed by attribute name
30
32
  ##
31
33
  def get_attributes(identifier, role = nil)
@@ -34,7 +36,8 @@ module Soar
34
36
 
35
37
  ##
36
38
  # @param [String] identifier
37
- # @return [Array<String>] list of identifiers
39
+ # @return [Array<String>]
40
+ # array of identity identifiers
38
41
  ##
39
42
  def get_identifiers(identifier)
40
43
  @provider.get_identifiers(identifier)
@@ -9,6 +9,8 @@ module Soar
9
9
 
10
10
  ##
11
11
  # @param [Soar::Registry::Directory] directory
12
+ # @param [String] fetch_index
13
+ # @param [String] search_index
12
14
  ##
13
15
  def initialize(directory:, fetch_index: , search_index: )
14
16
  @directory = directory
@@ -17,12 +19,15 @@ module Soar
17
19
  end
18
20
 
19
21
  ##
20
- # @param [String] identifier, an email address that uniquely identifies an identity
22
+ # @param [String] identity_identifier
23
+ # a client_number that uniquely identifies an identity
21
24
  # @return [Hash] an identity
22
25
  ##
23
26
  def calculate_identities(identity_identifier)
27
+ return @identities if not @identities.nil?
24
28
  entries = @directory.search(@search_index, identity_identifier)
25
- return entries.empty? ? [] : [entries[0]]
29
+ @identities = entries.empty? ? [] : [entries[0]]
30
+ return @identities
26
31
  end
27
32
 
28
33
  ##
@@ -17,12 +17,15 @@ module Soar
17
17
  end
18
18
 
19
19
  ##
20
- # @param [String] identifier, an email address that uniquely identifies an identity
20
+ # @param [String] identity_identifier
21
+ # an email address that uniquely identifies an identity
21
22
  # @return [Hash] an identity
22
23
  ##
23
24
  def calculate_identities(identity_identifier)
25
+ return @identities if not @identities.nil?
24
26
  entries = @directory.search(@search_index, identity_identifier)
25
- return entries.empty? ? [] : [entries[0]]
27
+ @identities = entries.empty? ? [] : [entries[0]]
28
+ return @identities
26
29
  end
27
30
 
28
31
  ##
@@ -12,11 +12,124 @@ module Soar
12
12
  class Uuid < SoarIdm::IdmApi
13
13
 
14
14
  ##
15
- # @param [String] identifier, a primary key that uniquely identifies an identity
16
- # @return [Hash] an identity
15
+ # @param [Hash] identity
16
+ # @option identity [Soar::Registry::Directory] :directory
17
+ # @option identity [String] :fetch_index
18
+ # @option identity [String] :search_index
19
+ #
20
+ # @param [Hash] roles
21
+ # @option roles [Soar::Registry::Directory] :directory
22
+ # @option roles [String] :fetch_index
23
+ # @option roles [String] :search_index
24
+ #
25
+ # @raise [ArgumentError]
26
+ ##
27
+ def initialize(identity:, roles:)
28
+ raise ArgumentError if not identity.key?(:directory) or not identity.key?(:fetch_index) or not identity.key?(:search_index)
29
+ raise ArgumentError if not roles.key?(:directory) or not roles.key?(:fetch_index) or not roles.key?(:search_index)
30
+ @identity = identity
31
+ @roles = roles
32
+ end
33
+
34
+ ##
35
+ # @param [Hash{String => String,Number}] identity
36
+ # @return [Array<String>] list of roles
37
+ ##
38
+ def calculate_roles(identity)
39
+ entries = @roles[:directory].search(@roles[:search_index], identity[@roles[:search_index]])
40
+ roles = []
41
+ entries.each do |entry|
42
+ roles << entry[@roles[:fetch_index][1]]
43
+ end
44
+ return roles
45
+ end
46
+
47
+ ##
48
+ # @param [Hash{String => String, Number}] identity
49
+ # @return [Array<String,Number>] list of identifiers
50
+ ##
51
+ def calculate_identifiers(identity)
52
+ indexes = @identity[:directory].index
53
+ #indexes.delete(@identity[:directory])
54
+ identifiers = []
55
+ indexes.each { |index|
56
+ identifiers << identity[index.to_s]
57
+ }
58
+ identifiers << identity[@roles[:fetch_index][0]]
59
+ return identifiers.reverse
60
+ end
61
+
62
+ ##
63
+ # @param [Hash{String => String, Number}] identity
64
+ # @param [String] role
65
+ # @return [Hash{String => String, Number, Hash, Array}] A hash of attributes
66
+ ##
67
+ def calculate_attributes(identity, role)
68
+ primary_key = {
69
+ @roles[:fetch_index][0] => identity[@roles[:fetch_index][0]],
70
+ @roles[:fetch_index][1] => role
71
+ }
72
+ result = @roles[:directory].fetch(primary_key)
73
+ attributes = {
74
+ role => result.key?('identity_role_attributes') ? result['identity_role_attributes'] : {}
75
+ }
76
+ return attributes
77
+ end
78
+
79
+ ##
80
+ # @param [Hash{String => String, Number}] identity
81
+ # @return [Hash{String => String, Number, Hash, Array}] A hash of attributes
82
+ def calculate_all_attributes(identity)
83
+ identity = Marshal.load(Marshal.dump(identity))
84
+ identity_uuid = identity[@roles[:search_index]]
85
+ role_entries = @roles[:directory].search(@roles[:search_index], identity_uuid)
86
+ roles = {}
87
+ role_entries.each do |role_entry|
88
+ roles[role_entry['identity_role']] = role_entry.key?('identity_role_attributes') ? role_entry['identity_role_attributes'] : {}
89
+ end
90
+ identity[:roles] = roles
91
+ attributes = Hashie.stringify_keys(identity)
92
+ return attributes
93
+ end
94
+
95
+ ##
96
+ # @param [String] identifier a string that uniquely identifies an identity
97
+ # @return [Array<Hash{String => String, Number }>] identities
17
98
  ##
18
99
  def calculate_identities(identifier)
19
- return [@translator.get_identity(@directory.fetch(identifier))]
100
+ return @identities if not @identities.nil?
101
+ identities = @roles[:directory].search(@roles[:search_index], identifier)
102
+ identity = { @roles[:search_index] => identifier }
103
+ return [identity] if identities.length == 0
104
+ identity_source = get_identity_source(identities)
105
+ identity_id = get_identity_id(identity_source) if not identity_source.nil?
106
+ #raise SoarIdm::IdentityError if identity_id.nil?
107
+ begin
108
+ identity = @identity[:directory].fetch(identity_id)
109
+ identity = {
110
+ "email" => identity[:Notifyemail_Invoice],
111
+ "firstname" => identity[:First_Name],
112
+ "lastname" =>identity[:Surname]
113
+ }
114
+ rescue Soar::Registry::Directory::Error::NoEntriesFoundError
115
+ end
116
+ identity[@roles[:search_index]] = identifier
117
+ @identities = [identity]
118
+ return @identities
119
+ end
120
+
121
+ private
122
+
123
+ def get_identity_id(identity_source)
124
+ result = identity_source.split(":")
125
+ return result.last.to_i if result[0] === "mysql" and result[1] === "genie" and result[2] === "client" and result[3] === "id"
126
+ end
127
+
128
+ def get_identity_source(identities)
129
+ identity_source = identities.each { |identity|
130
+ break identity["identity_source"] if identity.key?("identity_source")
131
+ }
132
+ return identity_source if identity_source.is_a?(String)
20
133
  end
21
134
 
22
135
  end
@@ -17,12 +17,15 @@ module Soar
17
17
  end
18
18
 
19
19
  ##
20
- # @param [String] identifier, an email address that uniquely identifies an identity
20
+ # @param [String] identity_identifier
21
+ # an email address that uniquely identifies an identity
21
22
  # @return [Hash] an identity
22
23
  ##
23
24
  def calculate_identities(identity_identifier)
25
+ return @identities if not @identities.nil?
24
26
  entries = @directory.search(@search_index, identity_identifier)
25
- return entries.empty? ? [] : [entries[0]]
27
+ @identities = entries.empty? ? [] : [entries[0]]
28
+ return @identities
26
29
  end
27
30
 
28
31
  ##
@@ -1,4 +1,5 @@
1
1
  require 'soar_idm/soar_idm'
2
+ require 'hashie'
2
3
 
3
4
  module Soar
4
5
  module Registry
@@ -6,71 +7,107 @@ module Soar
6
7
  module Provider
7
8
  module Staff
8
9
 
9
- ##
10
- # Work in progress. Do not use.
11
- ##
12
10
  class Uuid < SoarIdm::IdmApi
13
11
 
14
12
  ##
15
- # @param [Hash] directories
16
- # @option directories [Object] :identity
17
- # @option directories [Object] :role
13
+ # @param [Hash] identity
14
+ # @option identity [Soar::Registry::Directory] :directory
15
+ # @option identity [String] :fetch_index
16
+ # @option identity [String] :search_index
17
+ #
18
+ # @param [Hash] roles
19
+ # @option roles [Soar::Registry::Directory] :directory
20
+ # @option roles [String] :fetch_index
21
+ # @option roles [String] :search_index
22
+ #
23
+ # @raise [ArgumentError]
18
24
  ##
19
- def initialize(directories:, fetch_index: "entryuuid")
20
- raise Soar::Registry::Identity::Error::MissingRequiredDirectoryError, ':identity key is required' if not directories.key?(:identity)
21
- @identity_directory = directories[:identity]
22
- @roles_directory = directories.key?(:roles) ? directories[:roles] : directories[:identity]
25
+ def initialize(identity:, roles:)
26
+ raise ArgumentError if not identity.key?(:directory) or not identity.key?(:fetch_index) or not identity.key?(:search_index)
27
+ raise ArgumentError if not roles.key?(:directory) or not roles.key?(:fetch_index) or not roles.key?(:search_index)
28
+ @identity = identity
29
+ @roles = roles
23
30
  end
24
31
 
25
32
  ##
26
- # @param [Hash] identity
27
- # @return [Array] list of roles
33
+ # @param [Hash{String => String}] identity
34
+ # @return [Array<String>] list of roles
35
+ ##
28
36
  def calculate_roles(identity)
29
- entry = @roles_directory.fetch(identity[@roles_directory.index[0]])
30
- return nil if not entry
37
+ entries = @roles[:directory].search(@roles[:search_index], identity[@identity[:fetch_index]])
31
38
  roles = []
32
- entry['roles'].each do |role, attributes|
33
- roles << role
39
+ entries.each do |entry|
40
+ roles << entry[@roles[:fetch_index][1]]
34
41
  end
35
- roles
42
+ #raise SoarIdm::IdentityError if identity.nil? and roles.length == 0
43
+ return roles
36
44
  end
37
45
 
38
46
  ##
39
- # @param [Hash] identity
40
- # @return [Array] list of identifiers
47
+ # @param [Hash{String => String, Number}] identity
48
+ # @return [Array<String,Number>] list of identifiers
41
49
  ##
42
50
  def calculate_identifiers(identity)
43
- indexes = @identity_directory.index
51
+ indexes = @identity[:directory].index
44
52
  identifiers = []
45
53
  indexes.each { |index|
46
- identifiers << identity[index]
54
+ identifiers << identity[index.to_s]
47
55
  }
48
56
  identifiers
49
57
  end
50
58
 
51
59
  ##
52
- # @param [Hash] identity
60
+ # @param [Hash{String => String, Number}] identity
53
61
  # @param [String] role
54
- # @return [Hash] A hash of attributes
62
+ # @return [Hash{String => String, Number, Hash, Array}] A hash of attributes
63
+ ##
55
64
  def calculate_attributes(identity, role)
56
- entry = @roles_directory.fetch(identity[@roles_directory.index[0]])
57
- return nil if not entry
58
- { role => entry['roles'][role] }
65
+ primary_key = {
66
+ @roles[:fetch_index][0] => identity[@identity[:fetch_index]],
67
+ @roles[:fetch_index][1] => role
68
+ }
69
+ result = @roles[:directory].fetch(primary_key)
70
+ attributes = {
71
+ role => result.key?('identity_role_attributes') ? result['identity_role_attributes'] : {}
72
+ }
73
+ return attributes
59
74
  end
60
75
 
76
+ ##
77
+ # @param [Hash{String => String, Number}] identity
78
+ # @return [Hash{String => String, Number, Hash, Array}] A hash of attributes
61
79
  ##
62
- # @param [Hash] identity
63
- # @return [Hash] Hash of attributes keyed by role
64
80
  def calculate_all_attributes(identity)
65
- @directory.fetch(identity[@roles_directory.index[0]])
81
+ identity_uuid = identity[@identity[:fetch_index]]
82
+ role_entries = @roles[:directory].search(@roles[:search_index], identity_uuid)
83
+ roles = {}
84
+ role_entries.each do |role_entry|
85
+ roles[role_entry['identity_role']] = role_entry.key?('identity_role_attributes') ? role_entry['identity_role_attributes'] : {}
86
+ end
87
+ attributes = {
88
+ identity_uuid: identity_uuid,
89
+ firstname: identity['givenName'],
90
+ lastname: identity['sn'],
91
+ email: identity[@identity[:search_index]],
92
+ roles: roles
93
+ }
94
+ return attributes.stringify_keys
66
95
  end
67
96
 
68
97
  ##
69
- # @param [String] identifier, a primary key that uniquely identifies an identity
70
- # @return [Hash] an identity
98
+ # @param [String] identifier a string that uniquely identifies an identity
99
+ # @return [Array<Hash{String => String}>] identities
100
+ # @raise [Soar::Registry::Directory::Error::NoEntriesFoundError]
71
101
  ##
72
102
  def calculate_identities(identifier)
73
- return [@identity_directory.fetch(identifier)]
103
+ return @identities if not @identities.nil?
104
+ begin
105
+ result = @identity[:directory].fetch(identifier)
106
+ @identities = [Hashie.stringify_keys(result)]
107
+ return @identities
108
+ rescue Soar::Registry::Directory::Error::NoEntriesFoundError => e
109
+ raise SoarIdm::IdentityError
110
+ end
74
111
  end
75
112
 
76
113
  end