Class: Ucert::YstTracker

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/ucert/yst_tracker.rb

Overview

Class to handle Yi Shi Tong (一事通) user account IDs

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {}) ⇒ YstTracker

Instance default variables



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ucert/yst_tracker.rb', line 18

def initialize (params ={})

   @verbose=params.fetch(:verbose, false)
   # Yst user entitlement report in CSV format, generated by Ryan Li's user table exportation script
   @yst_user_report = File.dirname(__FILE__)+"/../../data/yst/YiShiTong_User.csv"
	# Yst user entitlement report in CSV format, generated by Ryan Li's user table exportation script
   @yst_org_report = File.dirname(__FILE__)+"/../../data/yst/YiShiTong_Org.csv"
	# Yst to AD user map file
	@file_user_map =  File.dirname(__FILE__)+"/../../data/yst/yst_user_map.txt"
	# Load the user map file to an instance variable (for performance gain)
	@yst_2_ad_user=load_known_user_map_from_file(@file_user_map)
	# Load the user entitlement instance variable from the native Yst user entitlement report
	@yst_user_entitlement=parse_yst_user_report(@yst_user_report)
	# Insert DN field into the user entitlement data structure
	insert_dn
	# Load the org entitlement instance variable from the native Yst org entitlement reportk=Uc
   @yst_org_entitlement=parse_yst_org_report(@yst_org_report)
	save!
end

Instance Attribute Details

#file_user_mapObject

Class constant variables



14
15
16
# File 'lib/ucert/yst_tracker.rb', line 14

def file_user_map
  @file_user_map
end

#verboseObject

Class constant variables



14
15
16
# File 'lib/ucert/yst_tracker.rb', line 14

def verbose
  @verbose
end

#yst_2_ad_userObject (readonly)

Returns the value of attribute yst_2_ad_user.



15
16
17
# File 'lib/ucert/yst_tracker.rb', line 15

def yst_2_ad_user
  @yst_2_ad_user
end

#yst_org_entitlementObject (readonly)

Returns the value of attribute yst_org_entitlement.



15
16
17
# File 'lib/ucert/yst_tracker.rb', line 15

def yst_org_entitlement
  @yst_org_entitlement
end

#yst_org_reportObject

Class constant variables



14
15
16
# File 'lib/ucert/yst_tracker.rb', line 14

def yst_org_report
  @yst_org_report
end

#yst_user_entitlementObject (readonly)

Returns the value of attribute yst_user_entitlement.



15
16
17
# File 'lib/ucert/yst_tracker.rb', line 15

def yst_user_entitlement
  @yst_user_entitlement
end

#yst_user_reportObject

Class constant variables



14
15
16
# File 'lib/ucert/yst_tracker.rb', line 14

def yst_user_report
  @yst_user_report
end

Instance Method Details

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



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ucert/yst_tracker.rb', line 199

def print_org_entitlement
  begin
	puts "Organization Entitlement Report in Plain-text Format" if @verbose
	@yst_org_entitlement.first[1].each {|k,v| print k,"|"} if @verbose
	puts if @verbose
	@yst_org_entitlement.values.map do |rec|
		rec.each {|k,v| print v,"|"}
		puts
    end
rescue => ee
	puts "Exception on method #{__method__}: #{ee}"
end
end

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



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/ucert/yst_tracker.rb', line 183

def print_user_entitlement
	begin
     puts "User Entitlement Report in Plain-text Format" if @verbose
		@yst_user_entitlement.first[1].each {|k,v| print k,"|"} if @verbose
		puts if @verbose
		@yst_user_entitlement.values.map do |rec|
			rec.each {|k,v| print v,"|"}
			puts
     end
	rescue => ee
		puts "Exception on method #{__method__}: #{ee}"
	end
end

#save_yst_user_map!(file = @file_user_map) ⇒ Object Also known as: save!

Save the Yi Shi Tong to AD user mapping relation into the cache file



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ucert/yst_tracker.rb', line 215

def save_yst_user_map!(file=@file_user_map)
	puts "Saving the known Yst to AD user mapping relationship to file: #{file} ..." if @verbose
	begin
		timestamp=Time.now
		f=File.open(file, 'w')
		f.write "# local Yst to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}"
		@yst_user_entitlement.values.map do |record|
			key = record['USER_NAME'].upcase + ':' + record['EMAIL'].upcase
			value = record['DN']
			f.write "\n#{key}|#{value}"
		end
		f.close
		puts "Yst to AD user map file is successfully saved to: #{file}" if @verbose
	rescue => ee
		puts "Exception on method #{__method__}: #{ee}" if @verbose
	end
end

#yst_id_2_dn(id) ⇒ Object

DN lookup via YST for systems under YST, such as CVM



174
175
176
177
178
179
# File 'lib/ucert/yst_tracker.rb', line 174

def yst_id_2_dn (id)
	@yst_user_entitlement.each do |key,val|
		return val["DN"] if val["USER_ID"] == id.strip
	end
	return nil
end

#yst_search_by_dn(dn) ⇒ Object Also known as: search_by_dn

Search user entitlement record by AD DN



235
236
237
238
239
240
241
242
243
244
245
# File 'lib/ucert/yst_tracker.rb', line 235

def yst_search_by_dn (dn)
	begin
     puts "Perform search on the user entitlement record by AD DN: #{dn}" if @verbose
     @yst_user_entitlement.each do |key, val|
         return val if @yst_user_entitlement[key]['DN'].eql? dn
     end
		return nil
   rescue => ee
     puts "Exception on method #{__method__}: #{ee}"
   end
end

#yst_search_by_id(id) ⇒ Object Also known as: search_by_id

Search user entitlement record by USER_ID



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/ucert/yst_tracker.rb', line 249

def yst_search_by_id (id)
	begin
     puts "Perform search on the user entitlement record by USER_ID: #{id}" if @verbose
     @yst_user_entitlement.each do |key, val|
         return val if @yst_user_entitlement[key]['USER_ID'].eql? id.strip
     end
		return nil
   rescue => ee
     puts "Exception on method #{__method__}: #{ee}"
   end
end