Class: Bizside::AuditLog

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

Constant Summary collapse

@@ignore_paths =
[]
@@trusted_proxy_cidrs =
[]
@@trusted_proxy_cidr_objects =
{}
@@truncate_length =
8192

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AuditLog

Returns a new instance of AuditLog.



29
30
31
# File 'lib/bizside/audit_log.rb', line 29

def initialize(app)
  @app = app
end

Class Method Details

.ignore_pathsObject



12
13
14
# File 'lib/bizside/audit_log.rb', line 12

def self.ignore_paths
  @@ignore_paths
end

.truncate_lengthObject



21
22
23
# File 'lib/bizside/audit_log.rb', line 21

def self.truncate_length
  @@truncate_length
end

.truncate_length=(value) ⇒ Object



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

def self.truncate_length=(value)
  @@truncate_length = value
end

.trusted_proxy_cidrsObject

192.168.0.0/24 といったCIDR表記の文字列を複数指定可能



17
18
19
# File 'lib/bizside/audit_log.rb', line 17

def self.trusted_proxy_cidrs
  @@trusted_proxy_cidrs
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bizside/audit_log.rb', line 33

def call(env)
  start = Time.now.strftime('%Y-%m-%dT%H:%M:%S.%3N%z')
  status, headers, response = @app.call(env)
  stop = Time.now.strftime('%Y-%m-%dT%H:%M:%S.%3N%z')
  exception = env[Bizside::ShowExceptions::BIZSIDE_EXCEPTION_ENV_KEY]

  if env['BIZSIDE_SUPPRESS_AUDIT']
    return status, headers, response
  end

  if @@ignore_paths.any? do |path|
      case path
      when Regexp
        env['REQUEST_URI'] =~ path
      else
        env['REQUEST_URI'] == path
      end
    end
    return status, headers, response
  end

  if Bizside.rails_env&.development?
    return status, headers, response if env['REQUEST_URI'] =~ /\/[^\/]+\/assets\/.*/
  elsif Bizside.rails_env&.test?
    return status, headers, response
  end

  info = build_loginfo(env, start, stop, status, exception)
  logger.record(info)

  return status, headers, response
end