Class: Apidepth::Configuration

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

Constant Summary collapse

HARD_IGNORED_HOSTS =

Always ignored regardless of user config. Covers unambiguous loopback addresses — we deliberately avoid wildcard patterns like *.internal here because silently swallowing traffic the developer wants to see is worse than showing mystery vendors. The setup subcommand prompts for custom patterns interactively.

%w[localhost 127.0.0.1 0.0.0.0 ::1].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/apidepth/configuration.rb', line 27

def initialize
  @enabled                   = true
  @flush_interval            = 20
  @registry_refresh_interval = 6 * 60 * 60
  @registry_cache_path       = "/tmp/apidepth_registry.json"
  @collector_url             = nil
  @_user_hosts               = []
  @on_flush_error            = nil
  @environment               = nil   # Railtie sets this to Rails.env at boot
  @sample_rate               = 1.0   # capture everything by default
  @extra_vendors             = {}    # customer-defined host mappings
  _rebuild_ignored_hosts
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def api_key
  @api_key
end

#collector_urlObject

Returns the value of attribute collector_url.



25
26
27
# File 'lib/apidepth/configuration.rb', line 25

def collector_url
  @collector_url
end

#enabledObject

Returns the value of attribute enabled.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def enabled
  @enabled
end

#environmentObject

Returns the value of attribute environment.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def environment
  @environment
end

#extra_vendorsObject

Returns the value of attribute extra_vendors.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def extra_vendors
  @extra_vendors
end

#flush_intervalObject

Returns the value of attribute flush_interval.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def flush_interval
  @flush_interval
end

#ignored_hostsObject

Returns the value of attribute ignored_hosts.



25
26
27
# File 'lib/apidepth/configuration.rb', line 25

def ignored_hosts
  @ignored_hosts
end

#on_flush_errorObject

Returns the value of attribute on_flush_error.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def on_flush_error
  @on_flush_error
end

#registry_cache_pathObject

Returns the value of attribute registry_cache_path.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def registry_cache_path
  @registry_cache_path
end

#registry_refresh_intervalObject

Returns the value of attribute registry_refresh_interval.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def registry_refresh_interval
  @registry_refresh_interval
end

#sample_rateObject

Returns the value of attribute sample_rate.



15
16
17
# File 'lib/apidepth/configuration.rb', line 15

def sample_rate
  @sample_rate
end

Instance Method Details

#ignored_host?(host) ⇒ Boolean

Returns true if host should be skipped. Supports glob wildcards (* matches any sequence, ? matches one character) so customers can ignore entire internal domains: “*.internal”, “*.svc.cluster.local”.

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/apidepth/configuration.rb', line 54

def ignored_host?(host)
  @_exact_ignored.include?(host) ||
    @_glob_ignored.any? { |pat| File.fnmatch(pat, host) }
end