Class: Ucert::AllianceSwiftTracker
- Inherits:
-
Object
- Object
- Ucert::AllianceSwiftTracker
- Includes:
- Utils
- Defined in:
- lib/ucert/alliance_swift_tracker.rb
Overview
Class to handle Alliance Swift operator entitlement reprot
Instance Attribute Summary collapse
-
#file_operator_map ⇒ Object
Class constant variables.
-
#swift_2_ad_operator ⇒ Object
readonly
Returns the value of attribute swift_2_ad_operator.
-
#swift_operator_details_report ⇒ Object
Class constant variables.
-
#swift_operator_entitlement ⇒ Object
readonly
Returns the value of attribute swift_operator_entitlement.
-
#swift_operator_profile_details_report ⇒ Object
Class constant variables.
-
#swift_operator_profiles ⇒ Object
readonly
Returns the value of attribute swift_operator_profiles.
-
#verbose ⇒ Object
Class constant variables.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ AllianceSwiftTracker
constructor
Instance default variables.
-
#insert_dn ⇒ Object
Perform search on the AD database, insert AD DN as a foreign key to the @swift_operator_entitlement instance variable.
-
#operator_name_2_index(name) ⇒ Object
swift_operator_entitlement table lookup, input is “User Name”, output is the corresponding operator record number.
-
#parse_swift_operator_profile_details_report(file) ⇒ Object
Parsing the Alliance Access “Operator Profile Details” report in Excel xlsx format (exported from Swifts as .xls; open it in Excel, then save as .xlsx).
-
#print_operator_entitlement ⇒ Object
(also: #print_operators)
Print out the operator entitlement table in plain text, to be imported into database.
-
#print_operator_profiles ⇒ Object
(also: #print_profiles)
Print out the operator entitlement table in plain text, to be imported into database.
-
#swift_search_by_dn(dn) ⇒ Object
(also: #search_by_dn)
Search operator entitlement record by AD DN.
Methods included from Utils
#file_2_list, #is_fqdn?, #is_ip?, #is_url?, #list_2_file, #load_known_user_map_from_file, #nslookup, #search_ad, #update_dn
Constructor Details
#initialize(params = {}) ⇒ AllianceSwiftTracker
Instance default variables
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # swift operator entitlement details report in xlxl format, generated by accessing "Configuration # -> Alliance Access: Access -> User Management -> Operators -> Search -> Report, select "Details" as 'Report type' # 'XLS' as 'Output Format', then click on 'OK' to save the report -> re-open it in Excel and save as 'XLXS' format. @swift_operator_details_report = File.dirname(__FILE__)+"/../../data/alliance_swift/Swift_Operator_Details.xlsx" # swift operator entitlement details report in 'XLXS' format, generated by accessing "Configuration -> Alliance Access: Access # -> User Management -> Operator Profiles -> Search, Report, Details"; 'XLS' as 'Output Format', then click on 'OK' to save the report # -> re-open it in Excel and save as 'XLXS' format. @swift_operator_profile_details_report = File.dirname(__FILE__)+"/../../data/alliance_swift/Swift_Operator_Profiles_Details.xlsx" # swift to AD operator map file @file_operator_map = File.dirname(__FILE__)+"/../../data/alliance_swift/swift_operator_map.txt" # Load the operator map file to an instance variable (for performance gain) @swift_2_ad_operator=load_known_user_map_from_file(@file_operator_map) # Load the operator entitlement instance variable from the most complete 'User Accout Function' Swift report @swift_operator_entitlement=Hash.new parse_swift_operator_details_report(@swift_operator_details_report) @swift_operator_profiles=Hash.new parse_swift_operator_profile_details_report(@swift_operator_profile_details_report) # Procedure to perform Swift to AD operator matching, insert AD DN into @swift_operator_entitlement data structure insert_dn save! end |
Instance Attribute Details
#file_operator_map ⇒ Object
Class constant variables
15 16 17 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 15 def file_operator_map @file_operator_map end |
#swift_2_ad_operator ⇒ Object (readonly)
Returns the value of attribute swift_2_ad_operator.
16 17 18 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 16 def swift_2_ad_operator @swift_2_ad_operator end |
#swift_operator_details_report ⇒ Object
Class constant variables
15 16 17 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 15 def swift_operator_details_report @swift_operator_details_report end |
#swift_operator_entitlement ⇒ Object (readonly)
Returns the value of attribute swift_operator_entitlement.
16 17 18 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 16 def swift_operator_entitlement @swift_operator_entitlement end |
#swift_operator_profile_details_report ⇒ Object
Class constant variables
15 16 17 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 15 def swift_operator_profile_details_report @swift_operator_profile_details_report end |
#swift_operator_profiles ⇒ Object (readonly)
Returns the value of attribute swift_operator_profiles.
16 17 18 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 16 def swift_operator_profiles @swift_operator_profiles end |
#verbose ⇒ Object
Class constant variables
15 16 17 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 15 def verbose @verbose end |
Instance Method Details
#insert_dn ⇒ Object
Perform search on the AD database, insert AD DN as a foreign key to the @swift_operator_entitlement instance variable
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 180 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @swift_operator_entitlement.each do |record, value| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = @swift_operator_entitlement[record]['Name'].gsub("NY_","") if @swift_operator_entitlement[record]['Name'] key2 = @swift_operator_entitlement[record]['Name'] if @swift_operator_entitlement[record]['Name'] key3 = @swift_operator_entitlement[record]['Description'] if @swift_operator_entitlement[record]['Description'] my_key=key2.upcase + ':' + key3.upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @swift_2_ad_operator.key?(my_key) dn=@swift_2_ad_operator[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 45d order search only if the last fail, by using: #{key3}" if @verbose dn = tracker.ad_search_by_text(key3, "person") end end @swift_operator_entitlement[record]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#operator_name_2_index(name) ⇒ Object
swift_operator_entitlement table lookup, input is “User Name”, output is the corresponding operator record number
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 220 def operator_name_2_index (name) begin raise "Invalid operator name: #{name}" if name.nil? or name.empty? puts "Perform record number lookup for operator name: #{name}" if @verbose @swift_operator_entitlement.each do |key,val| next if val['Name'].nil? or val['Name'].empty? if val['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 |
#parse_swift_operator_profile_details_report(file) ⇒ Object
Parsing the Alliance Access “Operator Profile Details” report in Excel xlsx format (exported from Swifts as .xls; open it in Excel, then save as .xlsx)
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 105 def parse_swift_operator_profile_details_report (file) begin puts "Start parsing Excel workbook file: #{file}" if @verbose workbook = RubyXL::Parser.parse(file) worksheet = workbook[0] operator_count = 0 # Total Number of Operator in the report report_type = String.new record=0 # opeartor record index worksheet.count.times do |row| puts "Processing worksheet row: #{row}" if @verbose unless worksheet[row][0].nil? next if worksheet[row][0].value.to_s.empty? # Used for unique record identification if worksheet[row][0].value.to_s.downcase.include?("operator profile details") record += 1 puts "Recording operator record number: #{record}" if @verbose @swift_operator_profiles[record] = Hash.new unless @swift_operator_profiles.key?(record) end # Used for record recording self check purpose if worksheet[row][0].value.to_s.downcase.include?("number of entities:") puts "Record Operator Count " if @verbose operator_count=worksheet[row][2].value.to_i break end # Recording report header and criteria section if record == 0 puts "Recording Report Header, Criteria" if @verbose report_type=worksheet[row][2].value.to_s.strip unless worksheet[row][2].nil? if worksheet[row][0].value.to_s.strip.downcase.eql?("report type:") end if record > 0 puts "Record Operator Profile Details " if @verbose @swift_operator_profiles[record]['Name'] = worksheet[row][1].value.to_s.strip if worksheet[row][0].value.to_s.downcase.strip.eql?("name") if worksheet[row][0].value.to_s.downcase.strip.eql?("entities") @swift_operator_profiles[record]['Entities'] = Hash.new unless @swift_operator_profiles[record]['Entities'] worksheet[row][1].value.to_s.strip.split(/\n/).map do |entity| @swift_operator_profiles[record]['Entities'][entity]=Hash.new unless @swift_operator_profiles[record]['Entities'].key?(entity) end end if worksheet[row][0].value.to_s.downcase.strip.eql?("actions") cur_entity = String.new cur_act = String.new worksheet[row][1].value.to_s.strip.split(/\n/).map do |line| # split and process the 'Actions' field in the spreadsheet if line.include?('-') and line !~ /^\s+/ entry = line.split('-').map {|x| x.strip} cur_entity = entry[0] cur_act = entry[1] @swift_operator_profiles[record]['Entities'][cur_entity] = Hash.new unless @swift_operator_profiles[record]['Entities'].key?(cur_entity) @swift_operator_profiles[record]['Entities'][cur_entity][cur_act] = Array.new unless @swift_operator_profiles[record]['Entities'][cur_entity][cur_act] else #if action =~ /^\s+/ @swift_operator_profiles[record]['Entities'][cur_entity][cur_act].push(line.strip) end end end 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 @swift_operator_profiles.count == operator_count and report_type.eql?("Operator Profiles - Detailed Report") puts "Past the sanity check!" if @verbose else abort "Parsing error: inconsistancy of Report Type #{report_type} or Operator Count #{operator_count} " end return @swift_operator_profiles rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#print_operator_entitlement ⇒ Object Also known as: print_operators
Print out the operator entitlement table in plain text, to be imported into database
238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 238 def print_operator_entitlement begin puts "Operator Entitlement Report in Plain-text Format" if @verbose puts "Name Description Status Last Login Type Authentication Type Authoriser DN for FileAct Profiles Units DN" if @verbose @swift_operator_entitlement.values.map do |record| puts "#{record['Name']}|#{record['Description']}|#{record['Status']}|#{record['Last_Login']}|#{record['Type']}|#{record['Authentication_Type']}|#{record['Authoriser_DN_for_FileAct']}|#{record['Profile']}|#{record['Units']}|#{record['DN']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#print_operator_profiles ⇒ Object Also known as: print_profiles
Print out the operator entitlement table in plain text, to be imported into database
252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 252 def print_operator_profiles begin puts "Operator Profiles Report in Plain-text Format" if @verbose puts "Name Entities" if @verbose @swift_operator_profiles.values.map do |record| puts "#{record['Name']}|#{record['Entities']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |
#swift_search_by_dn(dn) ⇒ Object Also known as: search_by_dn
Search operator entitlement record by AD DN
286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/ucert/alliance_swift_tracker.rb', line 286 def swift_search_by_dn (dn) begin puts "Perform search on the operator entitlement record by AD DN: #{dn}" if @verbose @swift_operator_entitlement.each do |key, val| return val if @swift_operator_entitlement[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end |