class Ucert::FrbTracker
Class to handle FRB Services ERP user entitlement reprot
Attributes
file_user_map[RW]
Class constant variables
frb_2_ad_user[R]
frb_subscriber_roles_report[RW]
Class constant variables
frb_user_entitlement[R]
known_service_group[R]
verbose[RW]
Class constant variables
Public Class Methods
new(params ={})
click to toggle source
Instance default variables
# File lib/ucert/frb_tracker.rb, line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # FRB Services 'Subscrber and Roles Report' in xlsx format. Generated by obtaining the PDF report from # the EUAC, then convert it into the EXcel workbook all-in-one sheet format by using online pdftables Services. # # Note 04/15/2016: # The subscriber report was generated by Joseph Loffredo # Note 11/20/2016 # The exported xlsx format table format change - shell shift one column to the left @frb_subscriber_roles_report = File.dirname(__FILE__)+"/../../data/frb/FRB_Subscriber_Roles_Report.xlsx" #@frb_subscriber_roles_report = File.dirname(__FILE__)+"/../../data/frb/SubscriberReport2015.xlsx" # frb to AD user map file @file_user_map = File.dirname(__FILE__)+"/../../data/frb/frb_user_map.txt" # Load the user map file to an instance variable (for performance gain) @frb_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' FRB report # Fedline services are grouped into different packages: @known_service_group={"FedLine Web Services"=>true, "FedLine Advantage Services"=>true} @frb_user_entitlement=parse_frb_rpt (@frb_subscriber_roles_report) # Procedure to perform FRB to AD user matching, insert AD DN into @frb_user_entitlement data structure insert_dn save! end
Public Instance Methods
frb_search_by_dn(dn)
click to toggle source
Search user entitlement r_index by AD DN
# File lib/ucert/frb_tracker.rb, line 218 def frb_search_by_dn (dn) begin puts "Perform search on the user entitlement r_index by AD DN: #{dn}" if @verbose @frb_user_entitlement.each do |key, val| return val if @frb_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/frb_tracker.rb, line 182 def print_user_entitlement begin puts "user Entitlement Report in Plain-text Format" if @verbose @frb_user_entitlement.first[1].each {|k,v| print k,"|"} if @verbose puts if @verbose @frb_user_entitlement.values.map do |rec| rec.each {|k,v| print v,"|"} puts end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: print_user
user_name_2_index(name)
click to toggle source
frb_user_entitlement
table lookup, input is “User Name”, output is the corresponding user r_index number
# File lib/ucert/frb_tracker.rb, line 164 def user_name_2_index (name) begin raise "Invalid user name: #{name}" if name.nil? or name.empty? puts "Perform Record number lookup for user name: #{name}" if @verbose @frb_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 "User 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 @frb_user_entitlement instance variable
# File lib/ucert/frb_tracker.rb, line 129 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @frb_user_entitlement.each do |r_index, value| puts "\n\nPerform DN lookup for r_index: #{r_index}" if @verbose key1 = @frb_user_entitlement[r_index]['Email'] if @frb_user_entitlement[r_index]['Email'] key2 = @frb_user_entitlement[r_index]['User Name'] if @frb_user_entitlement[r_index]['User Name'] my_key=key2.upcase + ":" + key1.upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @frb_2_ad_user.key?(my_key) dn=@frb_2_ad_user[my_key] # additional logic to update the existing DN r_index 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 end @frb_user_entitlement[r_index]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_frb_rpt(file)
click to toggle source
Parsing the “User Report” details in Excel xlsx format (exported from FRB Services)
# File lib/ucert/frb_tracker.rb, line 45 def parse_frb_rpt (file) #begin puts "Start parsing Excel workbook file: #{file}" if @verbose frb_user_entitlement = Hash.new workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] r_index=0 # user record index cur_user_start_row=0 # counter for the start row of the current user being recorded. cur_service_catalog=String.new # detect current subscriber service line name cur_services=Hash.new worksheet.count.times do |row| puts "Processing row: #{row}" if @verbose #puts "Step 1" if @verbose # Step 1 - Protection check first if worksheet[row].nil? puts "Skip row #{row}" if @verbose next else # continue Processing in the section below end # Step 2 - Processing user general profile row #puts "Step 2" if @verbose unless worksheet[row][0].nil? if worksheet[row][0].value.to_s.eql?("Service Information") r_index += 1 if r_index > 1 # save previous recorded service details puts "Assign service portfolio to user #{frb_user_entitlement[r_index-1]["User Name"]}: #{cur_services}" if @verbose frb_user_entitlement[r_index-1]["Services"]=cur_services unless frb_user_entitlement[r_index-1].key?("Services") cur_services = Hash.new end cur_user_start_row = row frb_user_entitlement[r_index] = Hash.new unless frb_user_entitlement.key?(r_index) puts "Recording user index #{r_index}, user name #{frb_user_entitlement[r_index]["User Name"]} profile: " if @verbose frb_user_entitlement[r_index]["User Name"] = worksheet[row-1][0].value.to_s #frb_user_entitlement[r_index]["Services"] = Hash.new unless frb_user_entitlement[r_index].key?("Services") end next if r_index==0 # recording current service details; if @known_service_group.key?(worksheet[row][0].value.to_s.strip) cur_service_catalog=worksheet[row][0].value.to_s puts "Recording user #{r_index} service catalog: #{cur_service_catalog} " if @verbose cur_services[cur_service_catalog]=Array.new unless cur_services.key?(cur_service_catalog) next end # if !worksheet[row][0].nil? && !worksheet[row][1].nil? service=Hash.new service[worksheet[row][0].value.to_s] = worksheet[row][1].value.to_s puts "Service: #{service}" if @verbose cur_services[cur_service_catalog].push(service) if cur_services[cur_service_catalog] puts "Current service catalog: #{cur_services[cur_service_catalog]}" if @verbose end end # Step 3 - Recording Subscriber Email, and Credential Information #puts "Step 3" if @verbose unless worksheet[row][2].nil? if worksheet[row][2].value.to_s.include?("Subscriber Email") frb_user_entitlement[r_index]["Email"]=worksheet[row][4].value.to_s end if worksheet[row][2].value.to_s.include?("Created:") frb_user_entitlement[r_index]["Credential Created:"]=worksheet[row][3].value.to_s frb_user_entitlement[r_index]["Credential Expires:"]=worksheet[row][5].value.to_s end if worksheet[row][2].value.to_s.eql?("Credential Information") puts "Recording Credential Information" if @verbose frb_user_entitlement[r_index]["Credential Type:"]=worksheet[row+1][3].value.to_s unless worksheet[row+1][3].nil? frb_user_entitlement[r_index]["Credential Status:"]=worksheet[row+1][5].value.to_s unless worksheet[row+1][5].nil? # frb_user_entitlement[r_index]["Credential Created:"]=worksheet[row+2][3].value.to_s unless worksheet[row+2][3].nil? # frb_user_entitlement[r_index]["Credential Expires:"]=worksheet[row+2][5].value.to_s unless worksheet[row+2][5].nil? end end end puts "Done parsing the workbook: #{file} " if @verbose workbook=nil # save the current service inforamtion recording to the last user frb_user_entitlement[r_index]["Services"]=cur_services return frb_user_entitlement #rescue => ee # puts "Exception on method #{__method__}: #{ee}" #end end
save_frb_user_map!(file=@file_user_map)
click to toggle source
Save the frb to AD user mapping relation into the cache file
# File lib/ucert/frb_tracker.rb, line 198 def save_frb_user_map!(file=@file_user_map) puts "Saving the known Frb to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local Frb to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @frb_user_entitlement.values.map do |r_index| key = r_index['User Name'].upcase + ":" + r_index['Email'].upcase value = r_index['DN'] f.write "\n#{key}|#{value}" end f.close puts "Frb 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!