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

Instance Method Details

#as_jsonObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aikido/zen/system_info.rb', line 62

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)


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

def attacks_are_only_reported?
  !attacks_block_requests?
end

#attacks_block_requests?Boolean

Returns:

  • (Boolean)


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

def attacks_block_requests?
  !!Aikido::Zen.blocking_mode?
end

#hostnameObject



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

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.



47
48
49
50
51
52
# File 'lib/aikido/zen/system_info.rb', line 47

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



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

def library_name
  "firewall-ruby"
end

#library_versionObject



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

def library_version
  VERSION
end

#os_nameObject



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

def os_name
  Gem::Platform.local.os
end

#os_versionObject



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

def os_version
  Gem::Platform.local.version || "unknown"
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).



38
39
40
41
42
# File 'lib/aikido/zen/system_info.rb', line 38

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

#platform_versionObject



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

def platform_version
  RUBY_VERSION
end