Class: RsUserPolicy::AuditLog

Inherits:
Object
  • Object
show all
Defined in:
lib/rs_user_policy/audit_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AuditLog

Initializes a new AuditLog

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options that impact the audit log filename.

Options Hash (options):

  • :timestamp (String)

    The timestamp to append to the filename

  • :dry_run (Bool)

    A boolean indicating if this is a dry run

  • :audit_dir (String)

    The directory where the audit log should be created



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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

Instance Attribute Details

#audit_logObject

Returns the value of attribute audit_log.



25
26
27
# File 'lib/rs_user_policy/audit_log.rb', line 25

def audit_log
  @audit_log
end

#filenameObject

Returns the value of attribute filename.



25
26
27
# File 'lib/rs_user_policy/audit_log.rb', line 25

def filename
  @filename
end

Instance Method Details

#add_entry(email, account, action, changes) ⇒ Object

Adds a new entry to the audit log

Parameters:

  • email (String)

    The email address of the user impacted by the change

  • account (String)

    The account name impacted by the change

  • action (String)

    The action performed. Expected options are [‘update_permissions’, ‘created’, ‘deleted’]

  • changes (String)

    A free form description of the changes



57
58
59
60
61
62
63
64
# File 'lib/rs_user_policy/audit_log.rb', line 57

def add_entry(email, , action, changes)
  @audit_log[email] = [] unless audit_log[email]
  @audit_log[email] << {
    :account => ,
    :action => action,
    :changes => changes
  }
end

#write_fileObject

Writes the audit log to a file



68
69
70
# 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