class RsUserPolicy::AuditLog

Attributes

audit_log[RW]
filename[RW]

Public Class Methods

new(options={}) click to toggle source

Initializes a new AuditLog

@param [Hash] options A hash of options that impact the audit log filename. @option options [String] :timestamp The timestamp to append to the filename @option options [Bool] :dry_run A boolean indicating if this is a dry run @option options [String] :audit_dir The directory where the audit log should be created

# File lib/rs_user_policy/audit_log.rb, line 33
def initialize(options={})
  timestamp = options[:timestamp] || Time.now.to_i
  @audit_log = {}
  @filename = ''

  if options[:audit_dir]
    @filename << ::File.join(options[:audit_dir], 'audit_log')
  else
    @filename << 'audit_log'
  end

  if options[:dry_run]
    @filename << '_dryrun'
  end

  @filename << "-#{timestamp}.json"
end

Public Instance Methods

add_entry(email, account, action, changes) click to toggle source

Adds a new entry to the audit log

@param [String] email The email address of the user impacted by the change @param [String] account The account name impacted by the change @param [String] action The action performed. Expected options are [‘update_permissions’, ‘created’, ‘deleted’] @param [String] changes A free form description of the changes

# File lib/rs_user_policy/audit_log.rb, line 57
def add_entry(email, account, action, changes)
  @audit_log[email] = [] unless audit_log[email]
  @audit_log[email] << {
    :account => account,
    :action => action,
    :changes => changes
  }
end
write_file() click to toggle source

Writes the audit log to a file

# File lib/rs_user_policy/audit_log.rb, line 68
def write_file
  File.open(@filename, 'w') {|f| f.write(JSON.pretty_generate(@audit_log))}
end