Class: Aikido::Zen::SystemInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/system_info.rb

Overview

Provides information about the currently running Agent.

Instance Method Summary collapse

Constructor Details

#initialize(config = Aikido::Zen.config) ⇒ SystemInfo

Returns a new instance of SystemInfo.



11
12
13
# File 'lib/aikido/zen/system_info.rb', line 11

def initialize(config = Aikido::Zen.config)
  @config = config
end

Instance Method Details

#as_jsonObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/aikido/zen/system_info.rb', line 66

def as_json
  {
    dryMode: attacks_are_only_reported?,
    library: library_name,
    version: library_version,
    hostname: hostname,
    ipAddress: ip_address,
    platform: {version: platform_version},
    os: {name: os_name, version: os_version},
    packages: packages.reduce({}) { |all, package| all.update(package.as_json) },
    incompatiblePackages: {},
    stack: [],
    serverless: false,
    nodeEnv: "",
    preventedPrototypePollution: false
  }
end

#attacks_are_only_reported?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/aikido/zen/system_info.rb', line 19

def attacks_are_only_reported?
  !attacks_block_requests?
end

#attacks_block_requests?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/aikido/zen/system_info.rb', line 15

def attacks_block_requests?
  !!@config.blocking_mode
end

#hostnameObject



35
36
37
# File 'lib/aikido/zen/system_info.rb', line 35

def hostname
  @hostname ||= Socket.gethostname
end

#ip_addressString

Returns the first non-loopback IPv4 address that we can use to identify this host. If the machine is solely identified by IPv6 addresses, then this will instead return an IPv6 address.

Returns:

  • (String)

    the first non-loopback IPv4 address that we can use to identify this host. If the machine is solely identified by IPv6 addresses, then this will instead return an IPv6 address.



51
52
53
54
55
56
# File 'lib/aikido/zen/system_info.rb', line 51

def ip_address
  @ip_address ||= Socket.ip_address_list
    .reject { |ip| ip.ipv4_loopback? || ip.ipv6_loopback? || ip.unix? }
    .min_by { |ip| ip.ipv4? ? 0 : 1 }
    .ip_address
end

#library_nameObject



23
24
25
# File 'lib/aikido/zen/system_info.rb', line 23

def library_name
  "firewall-ruby"
end

#library_versionObject



27
28
29
# File 'lib/aikido/zen/system_info.rb', line 27

def library_version
  VERSION
end

#os_nameObject



58
59
60
# File 'lib/aikido/zen/system_info.rb', line 58

def os_name
  Gem::Platform.local.os
end

#os_versionObject



62
63
64
# File 'lib/aikido/zen/system_info.rb', line 62

def os_version
  Gem::Platform.local.version
end

#packagesArray<Aikido::Zen::Package>

Returns a list of loaded rubygems that are supported by Aikido (i.e. we have a Sink that scans the package for vulnerabilities and protects you).

Returns:

  • (Array<Aikido::Zen::Package>)

    a list of loaded rubygems that are supported by Aikido (i.e. we have a Sink that scans the package for vulnerabilities and protects you).



42
43
44
45
46
# File 'lib/aikido/zen/system_info.rb', line 42

def packages
  @packages ||= Gem.loaded_specs
    .map { |_, spec| Package.new(spec.name, spec.version) }
    .select(&:supported?)
end

#platform_versionObject



31
32
33
# File 'lib/aikido/zen/system_info.rb', line 31

def platform_version
  RUBY_VERSION
end