class Ucert::FisEgiftsTracker
Class to handle FIS eGifts user entitlement reprot
Attributes
egifts_2_ad_user[R]
egifts_group_entitlement[R]
egifts_user_account_function_report[RW]
Class constant variables
egifts_user_entitlement[R]
file_user_map[RW]
Class constant variables
verbose[RW]
Class constant variables
Public Class Methods
new(params ={})
click to toggle source
Instance default variables
# File lib/ucert/fis_egifts_tracker.rb, line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # egifts user entitlement report in xlxl format, generated by using super user from the portal: egifts web portal # -> REPORTS -> User Functions -> output type "Excel" -> open in Excel and resave it to 'XLXS' format @egifts_user_account_function_report = File.dirname(__FILE__)+"/../../data/fis_egifts/CHINA_MERCHANTS_BANK_-_USER_ACCOUNT_FUNCTION_REPORT.xlsx" # egifts to AD user map file @file_user_map = File.dirname(__FILE__)+"/../../data/fis_egifts/egifts_user_map.txt" # Load the user map file to an instance variable (for performance gain) @egifts_2_ad_user=load_known_user_map_from_file(@file_user_map) # Load the user entitlement instance variable from the most complete 'User Accout Function' eGifts report @egifts_user_entitlement=parse_egifts_user_account_function_report(@egifts_user_account_function_report) # perform AD lookup for the corresponding DN record, add it into @egifts_user_entitlement hash insert_dn # save! end
Public Instance Methods
egifts_search_by_dn(dn)
click to toggle source
Search user entitlement record by AD DN
# File lib/ucert/fis_egifts_tracker.rb, line 235 def egifts_search_by_dn (dn) begin puts "Perform search on the user entitlement record by AD DN: #{dn}" if @verbose @egifts_user_entitlement.each do |key, val| return val if @egifts_user_entitlement[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: search_by_dn
print_user_entitlement()
click to toggle source
Print out the user entitlement table in plain text, to be imported into database
# File lib/ucert/fis_egifts_tracker.rb, line 201 def print_user_entitlement begin puts "User Entitlement Report in Plain-text Format" if @verbose puts "User_Name Institution Branch Department First_Name Middle_Initial Last_Name Added_On Added_by Last_Login Last_Logout Password_Expiry Enable Deleted Verify_Status Profile Role Functions DN" if @verbose @egifts_user_entitlement.values.map do |record| puts "#{record['User_Name']}|#{record['Institution']}|#{record['Branch']}|#{record['Department']}|#{record['First_Name']}|#{record['Middle_Initial']}|#{record['Last_Name']}|#{record['Added_On']}|#{record['Added_by']}|#{record['Last_Login']}|#{record['Last_Logout']}|#{record['Password_Expiry']}|#{record['Enable']}|#{record['Deleted']}|#{record['Verify_Status']}|#{record['Profile']}|#{record['Role']}|#{record['Functions']}|#{record['DN']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: print_user
save_egifts_user_map!(file=@file_user_map)
click to toggle source
Save the egifts to AD user mapping relation into the cache file
# File lib/ucert/fis_egifts_tracker.rb, line 215 def save_egifts_user_map!(file=@file_user_map) puts "Saving the known egifts to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local egifts to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @egifts_user_entitlement.values.map do |record| key = record['User_Name'].upcase + ':' + record['First_Name'].upcase value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "egifts to AD user map file is successfully saved to: #{file}" if @verbose rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end end
Also aliased as: save!
user_name_2_record_num(name)
click to toggle source
egifts_user_entitlement
table lookup, input is a user name, output is the corresponding user record number
# File lib/ucert/fis_egifts_tracker.rb, line 183 def user_name_2_record_num (name) begin raise "Invalid user name: #{name}" if name.nil? or name.empty? puts "Perform record number lookup for user name: #{name}" if @verbose @egifts_user_entitlement.each do |key,val| next if val['User_Name'].nil? or val['User_Name'].empty? if val['User_Name'].upcase == name.upcase puts "Record number found: #{key}" if @verbose return key end end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Private Instance Methods
insert_dn()
click to toggle source
Perform search on the AD database, insert AD DN as a foreign key to the @egifts_user_entitlement instance variable
# File lib/ucert/fis_egifts_tracker.rb, line 138 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @egifts_user_entitlement.each do |record, value| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = @egifts_user_entitlement[record]['E-Mail'] if @egifts_user_entitlement[record]['E-mail'] key2 = @egifts_user_entitlement[record]['User_Name'] if @egifts_user_entitlement[record]['User_Name'] key3 = @egifts_user_entitlement[record]['First_Name'] if @egifts_user_entitlement[record]['First_Name'] key4 = @egifts_user_entitlement[record]['Last_Name'] if @egifts_user_entitlement[record]['Last_Name'] my_key=value['User_Name'].upcase + ':' + value['First_Name'].upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @egifts_2_ad_user.key?(my_key) dn=@egifts_2_ad_user[my_key] # additional logic to update the existing DN record unless tracker.ad_person_records.key?(dn) dn = update_dn(tracker,dn) end puts "Found in the local cache file: #{dn}" if @verbose else if dn.nil? and !key1.nil? puts "Perform 2nd order search only if the 1st one fail, by using: #{key1}" if @verbose dn = tracker.ad_search_by_text(key1, "person") end if dn.nil? and !key2.nil? puts "Perform 3rd order search only if the last fail, by using: #{key2}" if @verbose dn = tracker.ad_search_by_text(key2, "person") end if dn.nil? and !key3.nil? puts "Perform 4th order search only if the last fail, by using: #{key3}" if @verbose dn = tracker.ad_search_by_text(key3, "person") end if dn.nil? and !key4.nil? puts "Perform 5th order search only if the last fail, by using: #{key4}" if @verbose dn = tracker.ad_search_by_text(key4, "person") end end @egifts_user_entitlement[record]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_egifts_user_account_function_report(file)
click to toggle source
Parsing the egifts “User Account Function Report” in Excel xlsx format (exported from eGifts as .xls; open it in Excel, then save as .xlsx)
# File lib/ucert/fis_egifts_tracker.rb, line 37 def parse_egifts_user_account_function_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose egifts_user_entitlement=Hash.new workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] user_number = 0 # Total Number of Users in the report record=0 # user record index functions_recording=false func_key=String.new # User Account Function Key worksheet.count.times do |row| puts "Processing worksheet row: #{row}" if @verbose unless worksheet[row][2].nil? if worksheet[row][2].value.to_s.downcase.include?("institution") record += 1 puts "Recording user record number: #{record}" if @verbose egifts_user_entitlement[record] = Hash.new unless egifts_user_entitlement.key?(record) # do not start recording the user account function yet functions_recording = false end if worksheet[row][2].value.to_s.downcase.include?("total number of users:") user_number=worksheet[row][10].value.to_i break end unless worksheet[row][6].nil? puts "Institution header section check" if @verbose egifts_user_entitlement[record]['Institution'] = worksheet[row][6].value.to_s.strip if worksheet[row][2].value.to_s.downcase.include?("institution") egifts_user_entitlement[record]['Branch'] = worksheet[row][6].value.to_s.strip if worksheet[row][2].value.to_s.downcase.include?("branch") egifts_user_entitlement[record]['Department'] = worksheet[row][6].value.to_s.strip if worksheet[row][2].value.to_s.downcase.include?("department") egifts_user_entitlement[record]['User_Name'] = worksheet[row][6].value.to_s.strip if worksheet[row][2].value.to_s.downcase.include?("user name") end end # recording user account access left portion information if !worksheet[row][3].nil? and !worksheet[row][8].nil? and !functions_recording puts "User account access header left portion check" if @verbose egifts_user_entitlement[record]['First_Name'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.downcase.include?("first name") egifts_user_entitlement[record]['Middle_Initial'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.downcase.include?("middle initial") egifts_user_entitlement[record]['Last_Name'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.downcase.include?("last name") egifts_user_entitlement[record]['E-Mail'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.downcase.include?("e-mail") egifts_user_entitlement[record]['Default'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.downcase.include?("Default") egifts_user_entitlement[record]['Last_Login'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Last Login") egifts_user_entitlement[record]['Last_Logout'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Last Logout") egifts_user_entitlement[record]['Added_On'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Added On") egifts_user_entitlement[record]['Added_by'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Added By") egifts_user_entitlement[record]['Password_Expiry'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Password Expiry") egifts_user_entitlement[record]['Enable'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Enable") egifts_user_entitlement[record]['Deleted'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Deleted") egifts_user_entitlement[record]['Verify_Status'] = worksheet[row][8].value.to_s.strip if worksheet[row][3].value.to_s.include?("Verify Status") if worksheet[row][3].value.to_s.include?("Functions") puts "Functions header check" if @verbose functions_recording = true egifts_user_entitlement[record]['Functions'] = Hash.new unless egifts_user_entitlement[record]['Functions'] next end end # recording user account access right portion information if !worksheet[row][18].nil? and !worksheet[row][21].nil? and !functions_recording puts "User account access header right portion check" if @verbose egifts_user_entitlement[record]['Monday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Monday") egifts_user_entitlement[record]['Tuesday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Tuesday") egifts_user_entitlement[record]['Wednesday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Wednesday") egifts_user_entitlement[record]['Thursday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Thursday") egifts_user_entitlement[record]['Friday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Friday") egifts_user_entitlement[record]['Saturday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Saturday") egifts_user_entitlement[record]['Sunday'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Sunday") egifts_user_entitlement[record]['Profile'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Profile") egifts_user_entitlement[record]['Role'] = worksheet[row][21].value.to_s.strip if worksheet[row][18].value.to_s.include?("Role") end # Recording functions Details if functions_recording #and (!worksheet[row][3].nil? or !worksheet[row][8].nil?) puts "Recording user functions for user account record number: #{record}" if @verbose if !worksheet[row][3].nil? unless worksheet[row][3].value.nil? puts "Check cell content to see if it's a valid function key: #{worksheet[row][3].value}" if @verbose func_key=worksheet[row][3].value.strip unless worksheet[row][3].value.strip.empty? puts "User account function key found: #{func_key}" if @verbose egifts_user_entitlement[record]['Functions'][func_key]=Array.new unless egifts_user_entitlement[record]['Functions'][func_key] end end if !worksheet[row][8].nil? #and !key.empty? puts "Check cell content to see if it's a valid function attributes: #{worksheet[row][8].value}" if @verbose egifts_user_entitlement[record]['Functions'][func_key].push(worksheet[row][8].value.to_s.strip) unless worksheet[row][8].value.to_s.strip.empty? end end puts "Finish processing worksheet row: #{row}" if @verbose end puts "Finish parsing the workbook: #{file} " if @verbose workbook=nil #self sanity quick check if egifts_user_entitlement.count == user_number puts "Past sanity check past!" if @verbose else abort "Parsing error: inconsistancy number of users: #{user_number}" end return egifts_user_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end