class Ucert::StbTracker
Class to handle STB user account IDs
Attributes
file_stb_user_map[RW]
Class constant variables
stb_2_ad_user[R]
stb_user_entitlement[R]
stb_user_entitlement_report[RW]
Class constant variables
stb_user_group_entitlement[R]
stb_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/stb_tracker.rb, line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # STB user entitlement report generation: Logon to STBAdmin program in the production VM # Once logon, click "Reports" -> "Users" -> "Print Report"-> Save to PDF file # Convert PDF file into CSV file using online utility https://pdftables.com/ # @stb_user_entitlement_report = File.dirname(__FILE__)+"/../../data/stb/STB_USERS.csv" # STB to AD user map file @file_stb_user_map = File.dirname(__FILE__)+"/../../data/stb/stb_user_map.txt" # Load user map from the local cacsh file @stb_2_ad_user=load_known_user_map_from_file(@file_stb_user_map) # Load the user entitlement instance variable from the user report @stb_user_entitlement=parse_stb_user_entitlement_report(@stb_user_entitlement_report) # Procedure to add DN foreign key to the @stb_user_entitlement, by performing the AD search insert_dn # Save the user map to local cache file save! end
Public Instance Methods
db_search_by_dn(dn)
click to toggle source
Search user entitlement record by AD DN
# File lib/ucert/stb_tracker.rb, line 184 def db_search_by_dn (dn) begin puts "Perform search on the user entitlement records by AD DN: #{dn}" if @verbose @stb_user_entitlement.each do |key, val| return val if @stb_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
dn_2_index(dn)
click to toggle source
Retrieve the user index from the @stb_user_entitlement data structure
# File lib/ucert/stb_tracker.rb, line 96 def dn_2_index (dn) begin (1..@stb_user_entitlement.count).map do |index| return index if @stb_user_entitlement[index]["DN"]==dn end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Private Instance Methods
insert_dn()
click to toggle source
Procedures to add additonal field 'dn' into the @stb_user_entitlement data structure, by person the AD search
# File lib/ucert/stb_tracker.rb, line 107 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @stb_user_entitlement.each do |index, record| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = record['Full Name'] if record['Full Name'] key2 = record['User ID'] if record['User ID'] key3 = record['Domain User Name'] if record['Domain User Name'] my_key = record['User ID'].upcase + ":" + record['Full Name'].upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @stb_2_ad_user.key?(my_key) dn=@stb_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 @stb_user_entitlement[index]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_stb_user_entitlement_report(file)
click to toggle source
Parsing the db Access user entitlement report in text format
# File lib/ucert/stb_tracker.rb, line 39 def parse_stb_user_entitlement_report (file) begin puts "Parse the user entitlement report: #{file}" if @verbose stb_user_entitlement=Hash.new user_index=1 line_cnt=0 doc = File.open(file,'r') header=Array.new rpt_time=String.new doc.each_line do |line| #stb_user_entitlement[user_index]=Hash.new unless stb_user_entitlement.key?(user_index) line_cnt+=1 puts "\n\nProcessing row number: #{line_cnt}" if @verbose next if line_cnt==1 record=line.chomp.split(',') puts "Processing record:\n #{header}\n #{record}" if @verbose if line_cnt==2 header=record puts "Header line: #{header}" if @verbose next # skip the header line end next if record[0].nil? next if record[0].empty? next if record[0].eql?("User ID") # Processing the last line of report containing report generation time if record[0].include?("Lombard Risk Administrator") rpt_time=record[0].split("Lombard Risk Administrator")[1] next end record_h=Hash[header.zip(record)[0..8]] puts "Adding STB Entitlement Record: #{record_h}" if @verbose if stb_user_entitlement.key?(user_index) puts "Checking record User_ID field match: #{stb_user_entitlement[user_index]['User ID']}, #{record_h['User ID']}" if @verbose next if record_h["User ID"].nil? if stb_user_entitlement[user_index]["User ID"] == record_h["User ID"] stb_user_entitlement[user_index]["Access Group"].push(record[9]) else user_index+=1 puts "Processing user record number: #{user_index}" if @verbose stb_user_entitlement[user_index]=Hash.new stb_user_entitlement[user_index]=record_h stb_user_entitlement[user_index]["Access Group"]=[record[9]] end else stb_user_entitlement[user_index]=Hash.new stb_user_entitlement[user_index]=record_h stb_user_entitlement[user_index]["Access Group"]=[record[9]] end end doc=nil return stb_user_entitlement 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/stb_tracker.rb, line 147 def print_user_entitlement begin puts "user Entitlement Report in Plain-text Format" if @verbose @stb_user_entitlement[1].each {|k,v| print k,"|"} if @verbose puts if @verbose @stb_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_stb_user_map!(file=@file_stb_user_map)
click to toggle source
Save the Prime to AD user mapping relation into the cache file
# File lib/ucert/stb_tracker.rb, line 164 def save_stb_user_map!(file=@file_stb_user_map) puts "Saving the known STB to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local STB to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @stb_user_entitlement.values.map do |record| key = record['User ID'].upcase + ":" + record['Full Name'].upcase value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "STB 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!