Class: Immunio::EnvironmentReporter
- Inherits:
-
Object
- Object
- Immunio::EnvironmentReporter
- Defined in:
- lib/immunio/plugins/environment_reporter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #hostname ⇒ Object
- #hostname_ip ⇒ Object
-
#initialize(app) ⇒ EnvironmentReporter
constructor
A new instance of EnvironmentReporter.
- #ips ⇒ Object
- #report ⇒ Object
- #runtime_name ⇒ Object
- #runtime_version ⇒ Object
Constructor Details
#initialize(app) ⇒ EnvironmentReporter
Returns a new instance of EnvironmentReporter.
8 9 10 11 12 13 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 8 def initialize(app) @app = app # No need for mutex, reporting environment is idempotent @reported = false end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 15 def call(env) response = @app.call(env) # Report gem usage at the end so that everything as been loaded. Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do report if !@reported end response end |
#hostname ⇒ Object
50 51 52 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 50 def hostname Socket.gethostname rescue SocketError end |
#hostname_ip ⇒ Object
54 55 56 57 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 54 def hostname_ip # SocketError is raised if we can't fetch the hostname with `Socket.gethostname`. Addrinfo.getaddrinfo(hostname, nil).first.ip_address rescue SocketError end |
#ips ⇒ Object
45 46 47 48 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 45 def ips ips = Socket.ip_address_list.map(&:ip_address) ips.reject { |ip| ['::1', '127.0.0.1'].include?(ip) } end |
#report ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 59 def report @reported = true info = { runtime: { name: runtime_name, version: runtime_version }, language: { name: 'ruby', version: RUBY_VERSION }, platform: { description: RUBY_PLATFORM }, host: { hostname: hostname, hostname_ip: hostname_ip, ips: ips }, dependencies: {} } Gem.loaded_specs.each_pair do |name, spec| info[:dependencies][name] = spec.version.to_s end Immunio.agent.environment = info end |
#runtime_name ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 26 def runtime_name if Object.const_defined?(:RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Enterprise/ 'ree' elsif Object.const_defined? :RUBY_ENGINE RUBY_ENGINE.to_s else 'unknown' end end |
#runtime_version ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/immunio/plugins/environment_reporter.rb', line 36 def runtime_version case runtime_name when 'ruby' then RUBY_VERSION when 'jruby' then JRUBY_VERSION when 'rbx' then Rubinius::VERSION else 'unknown' end end |