Class: Treblle::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/treblle/configuration.rb

Constant Summary collapse

DEFAULT_SENSITIVE_ATTRS =
%w[
  card_number
  cardNumber
  cc
  ccv
  credit_score
  creditScore
  password
  password_confirmation
  passwordConfirmation
  pwd
  secretn
  ssn
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



26
27
28
29
30
31
# File 'lib/treblle/configuration.rb', line 26

def initialize
  @restricted_endpoints = []
  @whitelisted_endpoints = '/api/'
  @app_version = nil
  @sensitive_attrs = DEFAULT_SENSITIVE_ATTRS
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



22
23
24
# File 'lib/treblle/configuration.rb', line 22

def api_key
  @api_key
end

#app_versionObject

Returns the value of attribute app_version.



22
23
24
# File 'lib/treblle/configuration.rb', line 22

def app_version
  @app_version
end

#enabled_environmentsObject

Returns the value of attribute enabled_environments.



24
25
26
# File 'lib/treblle/configuration.rb', line 24

def enabled_environments
  @enabled_environments
end

#project_idObject

Returns the value of attribute project_id.



22
23
24
# File 'lib/treblle/configuration.rb', line 22

def project_id
  @project_id
end

#restricted_endpointsObject

Returns the value of attribute restricted_endpoints.



22
23
24
# File 'lib/treblle/configuration.rb', line 22

def restricted_endpoints
  @restricted_endpoints
end

#sensitive_attrsObject

Returns the value of attribute sensitive_attrs.



24
25
26
# File 'lib/treblle/configuration.rb', line 24

def sensitive_attrs
  @sensitive_attrs
end

#whitelisted_endpointsObject

Returns the value of attribute whitelisted_endpoints.



22
23
24
# File 'lib/treblle/configuration.rb', line 22

def whitelisted_endpoints
  @whitelisted_endpoints
end

Instance Method Details

#enabled_environment?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/treblle/configuration.rb', line 45

def enabled_environment?
  return false if enabled_environments.empty?

  enabled_environments.include?(environment)
end

#monitoring_enabled?(request_url) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/treblle/configuration.rb', line 33

def monitoring_enabled?(request_url)
  whitelisted_endpoint?(request_url) && !restricted_endpoint?(request_url)
end

#validate_credentials!Object



51
52
53
54
# File 'lib/treblle/configuration.rb', line 51

def validate_credentials!
  raise Errors::MissingApiKeyError if api_key.to_s.empty?
  raise Errors::MissingProjectIdError if project_id.to_s.empty?
end