class Ucert::SwiftOnlineTracker
Class to handle Swift Online user entitlement report
Attributes
file_swo_user_map[RW]
Class constant variables
swo_2_ad_user[R]
swo_user_entitlement[R]
swo_user_status_report[RW]
Class constant variables
verbose[RW]
Class constant variables
Public Class Methods
new(params ={})
click to toggle source
Instance default variables
# File lib/ucert/swift_online_tracker.rb, line 20 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # Swift Online user entitlement report generation: # TBD @swo_user_entitlement_report = File.dirname(__FILE__)+"/../../data/swift_online/UserReport.xlsx" # Swift Online to AD user map file @file_swo_user_map = File.dirname(__FILE__)+"/../../data/swift_online/swo_access_user_map.txt" # Load user map from the local cacsh file @swo_2_ad_user=load_known_user_map_from_file(@file_swo_user_map) # Load the user entitlement instance variable from the user report @swo_user_entitlement=parse_swo_user_entitlement_report(@swo_user_entitlement_report) # Procedure to add DN foreign key to the @swo_user_entitlement, by performing the AD search insert_dn # Save the user map to local cache file save! end
Public Instance Methods
dn_2_index(dn)
click to toggle source
Retrieve the user index from the @swo_user_entitlement data structure
# File lib/ucert/swift_online_tracker.rb, line 95 def dn_2_index (dn) begin (1..@swo_user_entitlement.count).map do |index| return index if @swo_user_entitlement[index]["DN"]==dn end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
swo_search_by_dn(dn)
click to toggle source
Search user entitlement record by AD DN
# File lib/ucert/swift_online_tracker.rb, line 182 def swo_search_by_dn (dn) begin puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose @swo_user_entitlement.each do |key, val| return val if @swo_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
Private Instance Methods
insert_dn()
click to toggle source
Procedures to add additonal field 'dn' into the @swo_user_entitlement data structure, by person the AD search
# File lib/ucert/swift_online_tracker.rb, line 106 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @swo_user_entitlement.each do |index, record| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = record['Mail'] if record['Email'] key2 = record['First Name'] + " " + record['Last Name'] if record['First Name'] and record['Last Name'] key3 = record['First Name'] if record['First Name'] my_key = record['Mail'].upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @swo_2_ad_user.key?(my_key) dn=@swo_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 end @swo_user_entitlement[index]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_swo_user_entitlement_report(file)
click to toggle source
Parsing the Swift Online user entitlement report in text format
# File lib/ucert/swift_online_tracker.rb, line 38 def parse_swo_user_entitlement_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose swo_user_entitlement=Hash.new workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] operator_count = 0 # Total Number of Operator in the report report_type = String.new row_cnt=0 user_index=0 # user record index header=Array.new worksheet.count.times do |row| row_cnt+=1 puts "Parsing workbook row: #{row_cnt}" if @verbose entry=Array.new # Processing Header Row if row_cnt==1 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) end end user_index += 1 end record = header.zip(entry).to_h.reject {|k,v| k.nil?} puts "User record: #{record}" if @verbose swo_user_entitlement[user_index] = record unless swo_user_entitlement.key?(user_index) end workbook=nil return swo_user_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_swo_user_group_entitlement_report(file)
click to toggle source
Parsing the Swift Online user group entitlement report in text format TBD as currently this feature is Unknown
# File lib/ucert/swift_online_tracker.rb, line 86 def parse_swo_user_group_entitlement_report (file) begin rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
print_user_entitlement()
click to toggle source
Print out the user entitlement table in plain text, to be imported into database
# File lib/ucert/swift_online_tracker.rb, line 146 def print_user_entitlement begin puts "user Entitlement Report in Plain-text Format" if @verbose @swo_user_entitlement[1].each {|k,v| print k,"|"} if @verbose puts if @verbose @swo_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
save_swo_user_map!(file=@file_swo_user_map)
click to toggle source
Save the Prime to AD user mapping relation into the cache file
# File lib/ucert/swift_online_tracker.rb, line 162 def save_swo_user_map!(file=@file_swo_user_map) puts "Saving the known Prime to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local Swift Online to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @swo_user_entitlement.values.map do |record| key = record['Mail'].upcase value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "Swift Online 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!