Class: Ucert::CitidirectBETracker

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/ucert/citidirect_be_tracker.rb

Overview

Class to handle Citidirect BE user entitlement report

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#file_2_list, #is_fqdn?, #is_ip?, #is_url?, #list_2_file, #load_known_user_map_from_file, #nslookup, #search_ad, #update_dn

Constructor Details

#initialize(params = {}) ⇒ CitidirectBETracker

Instance default variables



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ucert/citidirect_be_tracker.rb', line 20

def initialize (params ={})
   @verbose=params.fetch(:verbose, false)
   # Citidirect BE user entitlement report generation:
	# Navigate to the portal site https://portal.citidirect.com/; click 'Service' menu to lauch the java applet application;
	# In the applet windows, under 'User Administrtion' -> 'Access Management' -> 'User Entitlements', select and run
	# 'User Profile and Entitlements Report'; open the file then save as xlsx workbook format
	#
   @be_user_entitlement_report = File.dirname(__FILE__)+"/../../data/citidirect_be/UserProfileEntitlementsReport.xlsx"
   # Citidirect BE to AD user map file
   @file_be_user_map =  File.dirname(__FILE__)+"/../../data/citidirect_be/be_user_map.txt"
	# Load user map from the local cacsh file
	@be_2_ad_user=load_known_user_map_from_file(@file_be_user_map)
	# Load the user entitlement instance variable from the user report
	@be_user_entitlement=parse_be_user_entitlement_report_new(@be_user_entitlement_report)
	# Procedure to add DN foreign key to the @be_user_entitlement, by performing the AD search
	insert_dn
	# Save the user map to local cache file
	save!
end

Instance Attribute Details

#be_2_ad_userObject (readonly)

Returns the value of attribute be_2_ad_user.



17
18
19
# File 'lib/ucert/citidirect_be_tracker.rb', line 17

def be_2_ad_user
  @be_2_ad_user
end

#be_user_entitlementObject (readonly)

Returns the value of attribute be_user_entitlement.



17
18
19
# File 'lib/ucert/citidirect_be_tracker.rb', line 17

def be_user_entitlement
  @be_user_entitlement
end

#be_user_status_reportObject

Class constant variables



16
17
18
# File 'lib/ucert/citidirect_be_tracker.rb', line 16

def be_user_status_report
  @be_user_status_report
end

#file_be_user_mapObject

Class constant variables



16
17
18
# File 'lib/ucert/citidirect_be_tracker.rb', line 16

def file_be_user_map
  @file_be_user_map
end

#verboseObject

Class constant variables



16
17
18
# File 'lib/ucert/citidirect_be_tracker.rb', line 16

def verbose
  @verbose
end

Instance Method Details

#be_search_by_dn(dn) ⇒ Object Also known as: search_by_dn

Search user entitlement record by AD DN



403
404
405
406
407
408
409
410
411
412
413
# File 'lib/ucert/citidirect_be_tracker.rb', line 403

def be_search_by_dn (dn)
	begin
     puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose
     @be_user_entitlement.each do |key, val|
         return val if @be_user_entitlement[key]['DN'].eql? dn
     end
		return nil
   rescue => ee
     puts "Exception on method #{__method__}: #{ee}"
   end
end

#dn_2_index(dn) ⇒ Object

Retrieve the user index from the @be_user_entitlement data structure



316
317
318
319
320
321
322
323
324
# File 'lib/ucert/citidirect_be_tracker.rb', line 316

def dn_2_index (dn)
		begin
       (1..@be_user_entitlement.count).map do |index|
         return index if @be_user_entitlement[index]["DN"]==dn
       end
		rescue => ee
			puts "Exception on method #{__method__}: #{ee}"
		end
end

#parse_be_user_entitlement_report_new(file) ⇒ Object

Parsing the Citidirect BE user entitlement report in the native Excel format



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/ucert/citidirect_be_tracker.rb', line 166

def parse_be_user_entitlement_report_new (file)
	begin
		puts "Start parsing Excel workbook file: #{file}" if @verbose
		be_user_entitlement=Hash.new
		workbook = RubyXL::Parser.parse(file)
		worksheet = workbook[0]
		user_number = 0		# Total Number of Users in the report
		report_date = String.new # Report generation date
		record=0	# user record index
		ent_profiles = Hash.new
		 = true
		entitlement_recording = false
		cur_ent = String.new
		cur_serv = String.new
		worksheet.count.times  do |row|
			puts "Processing worksheet row: #{row}" if @verbose
			# Step 0 - Pre-proccessing
			# Skip empty row
			next if worksheet[row].nil?
			# if not recording entitlement, skip row with column A null or empty
			unless entitlement_recording
				next if worksheet[row][0].nil?
				next if worksheet[row][0].value.nil?
				next if worksheet[row][0].value.to_s.empty?
				puts "First cell of the row: #{worksheet[row][0].value.to_s}" if @verbose
			end
			# Step 1 - logic to extract report date
			if report_date.empty? && worksheet[row][0].value.to_s.include?("Report Date")
				puts "Recording report date:" if @verbose
				report_date = worksheet[row][0].value.to_s.split("Report Date ")[1]
				puts report_date if @verbose
			end
			# Step 2 - logic to determine starting of new user
			unless worksheet[row][0].nil?
				if worksheet[row][0].value.to_s.downcase.include?("first name")
					 = true
					if record > 0
						entitlement_recording = false
						be_user_entitlement[record] = Hash.new unless be_user_entitlement.key?(record)
						be_user_entitlement[record]['Assigned_Access_Profiles'] = ent_profiles
					end
					record += 1
					puts "\nRecording user record number: #{record}" if @verbose
					be_user_entitlement[record] = Hash.new unless be_user_entitlement.key?(record)
					ent_profiles = Hash.new
				end
			end
			# Step 3 - logic to collect user basic profile
			#unless worksheet[row][1].nil?
			if 
				case worksheet[row][0].value.to_s
        when /First Name/
					be_user_entitlement[record]['First_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					entitlement_recording = false
					next
				when /Middle Name/
					be_user_entitlement[record]['Middle_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
        when /Last Name/
					be_user_entitlement[record]['Last_Name'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
				when /Initials/
					be_user_entitlement[record]['Initials'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
				when /Status/
					be_user_entitlement[record]['Status'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
				when /Alias/
					be_user_entitlement[record]['Alias'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
				when /E-Mail Address/
					be_user_entitlement[record]['E-Mail'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
        when /Credential/
					be_user_entitlement[record]['Credential'] = worksheet[row][1].nil? ? nil : worksheet[row][1].value.to_s.strip
					next
        when /Entitlement Name/
					entitlement_recording = true
					 = false
					next

				else
					# doing nothing at this time
        end
			end
			# Step 4 - logic to collect user entitlement details: name -> product -> service -> entitlement attributes
			# Recording user product details

			if entitlement_recording
				# check column B, C not empty to determin the product name
				if !worksheet[row][0].nil? and !worksheet[row][1].nil? and !worksheet[row][2].nil?
					cur_ent = worksheet[row][0].value.to_s.strip
					cur_serv = worksheet[row][2].value.to_s.strip
					ent_profiles[cur_ent] = Hash.new
					ent_profiles[cur_ent]['Product Name']=worksheet[row][1].value.to_s.strip
					ent_profiles[cur_ent][cur_serv]=Hash.new
					ent_profiles[cur_ent][cur_serv]['Service Name']=cur_serv
					ent_profiles[cur_ent][cur_serv]['Entitlements']=Array.new
					next
				end
				# check column c to determine current service name
				if !worksheet[row][2].nil?
					cur_serv = worksheet[row][2].value.to_s.strip
					ent_profiles[cur_ent][cur_serv]=Hash.new
					ent_profiles[cur_ent][cur_serv]['Service Name']=cur_serv
					ent_profiles[cur_ent][cur_serv]['Entitlements']=Array.new
					next
				end
				# catch the entitlement key value pairs
				if !worksheet[row][3].nil? and !worksheet[row][4].nil?
					ent = {worksheet[row][3].value.to_s => worksheet[row][4].value.to_s}
					puts "Entilement pair found: #{ent}" if @verbose
					ent_profiles[cur_ent][cur_serv]['Entitlements'].push(ent)
					next
				end
				# catch the footer of the report
				if !worksheet[row][0].nil?
					case worksheet[row][0].value.to_s
					when /Filters have been applied to this data/
						 = false
						entitlement_recording = false
						next
					else
					end
				end

			end
			puts "Finish processing worksheet row: #{row}" if @verbose
		end
		puts "Finish parsing the workbook: #{file} " if @verbose
		workbook=nil
		be_user_entitlement[record]['Assigned_Access_Profiles'] = ent_profiles
		return be_user_entitlement
	rescue => ee
		puts "Exception on method #{__method__}: #{ee}"
	end
end