class Ucert::ClearParTracker

Class to handle the ClearPar user entitlement report

Attributes

clear_par_2_ad_user[R]
clear_par_users[R]
file_clear_par_user_map[RW]
verbose[RW]

Public Class Methods

new(params ={}) click to toggle source

Instance default variables

# File lib/ucert/clear_par_tracker.rb, line 18
def initialize (params ={})
  @verbose=params.fetch(:verbose, false)
  # ClearPar report generation: Contact Xi Wang, Amy Chan / Sharon Song for the latest user entitlement report
              # Then save it into Excel xlsx format
  @clear_par_users_report = File.dirname(__FILE__)+"/../../data/clear_par/ClearPar User Report.xlsx"
  # ADP Payroll to AD user map file
  @file_clear_par_user_map =  File.dirname(__FILE__)+"/../../data/clear_par/clear_par_user_map.txt"
              # Load user map from the local cacsh file
              @clear_par_2_ad_user=load_known_user_map_from_file(@file_clear_par_user_map)
              # Read the user security report
              @clear_par_users=parse_clear_par_report(@clear_par_users_report)
              #TBD - @clear_par_proxy_users=parse_clear_par_proxy_report(@clear_par_users_report)
              # Procedure to add DN foreign key to the @clear_par_users, by performing the AD search
              insert_dn
              # Save the user map to local cache file
              save!
      end

Public Instance Methods

clear_par_search_by_dn(dn) click to toggle source

Search user entitlement record by AD DN

# File lib/ucert/clear_par_tracker.rb, line 172
    def clear_par_search_by_dn (dn)
            begin
  puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose
  @clear_par_users.each do |key, val|
      return val if @clear_par_users[key]['DN'].eql? dn
  end
                    return nil
rescue => ee
  puts "Exception on method #{__method__}: #{ee}"
end
    end
Also aliased as: search_by_dn
dn_2_index(dn) click to toggle source

Retrieve the user index from the @clear_par_users data structure

# File lib/ucert/clear_par_tracker.rb, line 83
def dn_2_index (dn)
                begin
(1..@clear_par_users.count).map do |index|
  return index if @clear_par_users[index]["DN"]==dn
end
                rescue => ee
                        puts "Exception on method #{__method__}: #{ee}"
                end
end
print_user()
Alias for: print_user_access
save!(file=@file_clear_par_user_map)
search_by_dn(dn)

Private Instance Methods

insert_dn() click to toggle source

Procedures to add additonal field 'dn' into the @clear_par_users data structure, by person the AD search

# File lib/ucert/clear_par_tracker.rb, line 94
def insert_dn
                #begin
                         tracker = Ucert::AdTracker.new(:verbose=>false)
                         @clear_par_users.each do |index, record|
                                puts "\n\nPerform DN lookup for record: #{record}" if @verbose
                                key1 = record['Email']
                                key2 = record['User Name']
                                key3 = record['Login']
                                my_key = record['Email'].upcase + ":" + record['User Name'].upcase
                                puts "Perform 1st order search from the local cache: #{my_key}" if @verbose
                                if @clear_par_2_ad_user.key?(my_key)
                                        dn=@clear_par_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
                #=begin
                                        if dn.nil? and !key1.nil?
                                                puts "Perform 2nd order search only if the last 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
                #=end
                                end
                                @clear_par_users[index]['DN'] = dn
                        end
                        tracker=nil
                #rescue => ee
                #    puts "Exception on method #{__method__}: #{ee}"
                #end
end
parse_clear_par_report(file) click to toggle source

Parsing the ClearPar user entitlement report

# File lib/ucert/clear_par_tracker.rb, line 37
def parse_clear_par_report (file)
        begin
                puts "Start parsing Excel workbook file: #{file}" if @verbose
                clear_par=Hash.new
                workbook = RubyXL::Parser.parse(file)
                worksheet=workbook.worksheets.first
                row_cnt=0
                header=Array.new
                user_index=0
                worksheet.count.times  do |row|
                        row_cnt+=1
                        puts "Parsing workbook row: #{row_cnt}" if @verbose
                        next if row_cnt == 1  # skip the 1st row - report timestamp information only
                        entry=Array.new
                        # Processing Header Row
                        if row_cnt==2
                                0.upto(worksheet[row].size) do |col|
                                        if worksheet[row][col].nil?
                                                header.push(nil)
                                        else
                                                header.push(worksheet[row][col].value.to_s)
                                        end
                                end
                                next
                        else
                                0.upto(worksheet[row].size) do |col|
                                        if worksheet[row][col].nil?
                                                entry.push(nil)
                                        else
                                                entry.push(worksheet[row][col].value.to_s.strip)
                                        end
                                end
                                user_index += 1
                        end
                        record = header.zip(entry).to_h.reject {|k,v| k.nil?}
                        puts "User record: #{record}" if @verbose
                        clear_par[user_index] = record unless clear_par.key?(user_index)
                end
                workbook=nil
                return clear_par
        rescue => ee
                puts "Exception on method #{__method__}: #{ee}"
        end
end
print_user_access() click to toggle source

Print out the user entitlement table in plain text, to be imported into database

Also aliased as: print_user
save_clear_par_user_map!(file=@file_clear_par_user_map) click to toggle source

Save the ClearPar to AD user mapping relation into the cache file

# File lib/ucert/clear_par_tracker.rb, line 152
def save_clear_par_user_map!(file=@file_clear_par_user_map)
        puts "Saving the known ClearPar to AD user mapping relationship to file: #{file} ..." if @verbose
        begin
                timestamp=Time.now
                f=File.open(file, 'w')
                f.write "# ClearPar to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}"
                @clear_par_users.values.map do |record|
                        key = record['Email'].upcase + ":" + record['User Name'].upcase
                        value = record['DN']
                        f.write "\n#{key}|#{value}"
                end
                f.close
                puts "ADP Payroll 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!