Class: Kiev::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kiev/config.rb

Constant Summary collapse

DEFAULT_LOG_REQUEST_CONDITION =
proc do |request, _response|
  !DEFAULT_LOG_REQUEST_REGEXP.match(request.path)
end
DEFAULT_LOG_REQUEST_ERROR_CONDITION =
proc do |_request, response|
  response.status != 404
end
DEFAULT_LOG_RESPONSE_BODY_CONDITION =
proc do |_request, response|
  !!(response.status >= 400 && response.status < 500 && response.content_type =~ DEFAULT_LOG_RESPONSE_BODY_REGEXP)
end
DEFAULT_LOG_REQUEST_BODY_CONDITION =
proc do |request, _response|
  !!(request.content_type =~ /(application|text)\/xml/)
end
DEFAULT_IGNORED_RACK_EXCEPTIONS =
%w(
  ActiveRecord::RecordNotFound
  Mongoid::Errors::DocumentNotFound
  Sequel::RecordNotFound
).freeze
FILTERED_PARAMS =
%w(
  client_secret
  token
  password
  password_confirmation
  old_password
  credit_card_number
  credit_card_cvv
  credit_card_holder
  credit_card_expiry_month
  credit_card_expiry_year
  CardNumber
  CardCVV
  CardExpires
).freeze
IGNORED_PARAMS =
(%w(
  controller
  action
  format
  authenticity_token
  utf8
  tempfile
) << :tempfile).freeze
DEFAULT_HTTP_PROPAGATED_FIELDS =
{
  request_id: "X-Request-Id",
  request_depth: "X-Request-Depth",
  tree_path: "X-Tree-Path"
}.freeze
DEFAULT_PRE_RACK_HOOK =
proc do |env|
  Config.instance.http_propagated_fields.each do |key, http_key|
    Kiev[key] = Util.sanitize(env[Util.to_http(http_key)])
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/kiev/config.rb', line 96

def initialize
  @log_request_condition = DEFAULT_LOG_REQUEST_CONDITION
  @log_request_error_condition = DEFAULT_LOG_REQUEST_ERROR_CONDITION
  @log_response_body_condition = DEFAULT_LOG_RESPONSE_BODY_CONDITION
  @log_request_body_condition = DEFAULT_LOG_REQUEST_BODY_CONDITION
  @filtered_params = FILTERED_PARAMS
  @ignored_params = IGNORED_PARAMS
  @disable_default_logger = true
  @development_mode = false
  @ignored_rack_exceptions = DEFAULT_IGNORED_RACK_EXCEPTIONS.dup
  @logger = Kiev::Logger.new(STDOUT)
  @log_level = nil
  @persistent_log_fields = []
  @pre_rack_hook = DEFAULT_PRE_RACK_HOOK
  self.propagated_fields = {}
  update_logger_settings
end

Instance Attribute Details

#all_http_propagated_fieldsObject (readonly)

Returns the value of attribute all_http_propagated_fields.



89
90
91
# File 'lib/kiev/config.rb', line 89

def all_http_propagated_fields
  @all_http_propagated_fields
end

#all_jobs_propagated_fieldsObject (readonly)

Returns the value of attribute all_jobs_propagated_fields.



89
90
91
# File 'lib/kiev/config.rb', line 89

def all_jobs_propagated_fields
  @all_jobs_propagated_fields
end

#appObject

Returns the value of attribute app.



77
78
79
# File 'lib/kiev/config.rb', line 77

def app
  @app
end

#development_modeObject

Returns the value of attribute development_mode.



89
90
91
# File 'lib/kiev/config.rb', line 89

def development_mode
  @development_mode
end

#disable_default_loggerObject

Returns the value of attribute disable_default_logger.



77
78
79
# File 'lib/kiev/config.rb', line 77

def disable_default_logger
  @disable_default_logger
end

#filtered_paramsObject

Returns the value of attribute filtered_params.



77
78
79
# File 'lib/kiev/config.rb', line 77

def filtered_params
  @filtered_params
end

#http_propagated_fieldsObject

Returns the value of attribute http_propagated_fields.



89
90
91
# File 'lib/kiev/config.rb', line 89

def http_propagated_fields
  @http_propagated_fields
end

#ignored_paramsObject

Returns the value of attribute ignored_params.



77
78
79
# File 'lib/kiev/config.rb', line 77

def ignored_params
  @ignored_params
end

#ignored_rack_exceptionsObject

Returns the value of attribute ignored_rack_exceptions.



77
78
79
# File 'lib/kiev/config.rb', line 77

def ignored_rack_exceptions
  @ignored_rack_exceptions
end

#jobs_propagated_fieldsObject

Returns the value of attribute jobs_propagated_fields.



89
90
91
# File 'lib/kiev/config.rb', line 89

def jobs_propagated_fields
  @jobs_propagated_fields
end

#log_request_body_conditionObject

Returns the value of attribute log_request_body_condition.



77
78
79
# File 'lib/kiev/config.rb', line 77

def log_request_body_condition
  @log_request_body_condition
end

#log_request_conditionObject

Returns the value of attribute log_request_condition.



77
78
79
# File 'lib/kiev/config.rb', line 77

def log_request_condition
  @log_request_condition
end

#log_request_error_conditionObject

Returns the value of attribute log_request_error_condition.



77
78
79
# File 'lib/kiev/config.rb', line 77

def log_request_error_condition
  @log_request_error_condition
end

#log_response_body_conditionObject

Returns the value of attribute log_response_body_condition.



77
78
79
# File 'lib/kiev/config.rb', line 77

def log_response_body_condition
  @log_response_body_condition
end

#loggerObject (readonly)

Returns the value of attribute logger.



89
90
91
# File 'lib/kiev/config.rb', line 89

def logger
  @logger
end

#persistent_log_fieldsObject

Returns the value of attribute persistent_log_fields.



77
78
79
# File 'lib/kiev/config.rb', line 77

def persistent_log_fields
  @persistent_log_fields
end

#pre_rack_hookObject

Returns the value of attribute pre_rack_hook.



77
78
79
# File 'lib/kiev/config.rb', line 77

def pre_rack_hook
  @pre_rack_hook
end

Instance Method Details

#log_level=(value) ⇒ Object



139
140
141
142
# File 'lib/kiev/config.rb', line 139

def log_level=(value)
  @log_level = value
  update_logger_settings
end

#log_path=(value) ⇒ Object



134
135
136
137
# File 'lib/kiev/config.rb', line 134

def log_path=(value)
  logger.path = value
  update_logger_settings
end

#propagated_fields=(value) ⇒ Object

shortcut



129
130
131
132
# File 'lib/kiev/config.rb', line 129

def propagated_fields=(value)
  self.http_propagated_fields = value
  self.jobs_propagated_fields = value.keys
end