Class: Cheftacular::Auditor

Inherits:
Object
  • Object
show all
Defined in:
lib/cheftacular/auditor.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, config) ⇒ Auditor

Returns a new instance of Auditor.



4
5
6
# File 'lib/cheftacular/auditor.rb', line 4

def initialize options, config
  @options, @config = options, config
end

Instance Method Details

#audit_runObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/cheftacular/auditor.rb', line 8

def audit_run
  current_day  = Time.now.strftime('%Y%m%d')
  current_time = Time.now.strftime('%H:%M')

  @config[@options['env']]['audit_bag_hash']['audit_log'][current_day] ||= {}
  @config[@options['env']]['audit_bag_hash']['audit_log'][current_day][current_time] ||= []
  @config[@options['env']]['audit_bag_hash']['audit_log'][current_day][current_time] << read_audit_cache_file_to_hash

  @config['ChefDataBag'].save_audit_bag
end

#fetch_audit_data_hash(ret_hash = {}, ip = "") ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/cheftacular/auditor.rb', line 32

def fetch_audit_data_hash ret_hash={}, ip=""
  ret_hash['hostname']  = Socket.gethostname

  ret_hash
rescue StandardError => exception
  @config['helper'].cleanup_file_caches('current-audit-only')

  @config['helper'].exception_output "Unable to finish parsing auditing hash", exception
end

#read_audit_cache_file_to_hash(ret_hash = {}) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/cheftacular/auditor.rb', line 23

def read_audit_cache_file_to_hash ret_hash={}
  ret_hash = Hash.class_eval( File.read( @config['helper'].current_audit_file_path ))
  ret_hash['command']   = @options['command']
  ret_hash['options']   = @options.except(:preferred_cloud, :preferred_cloud_region, :preferred_cloud_image) #TODO load preferred_X options if they are not the default?
  ret_hash['arguments'] = ARGV[1..ARGV.length]

  ret_hash
end

#write_audit_cache_fileObject



19
20
21
# File 'lib/cheftacular/auditor.rb', line 19

def write_audit_cache_file
  File.open( @config['helper'].current_audit_file_path, "w") { |f| f.write( fetch_audit_data_hash ) }
end