Class: Inspec::Resources::Port
- Inherits:
-
Object
- Object
- Inspec::Resources::Port
- Defined in:
- lib/resources/port.rb
Instance Method Summary collapse
- #addresses ⇒ Object
-
#initialize(ip = nil, port) ⇒ Port
constructor
rubocop:disable OptionalArguments.
- #listening?(_protocol = nil, _local_address = nil) ⇒ Boolean
- #pids ⇒ Object
- #processes ⇒ Object
- #protocols ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ip = nil, port) ⇒ Port
rubocop:disable OptionalArguments
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/resources/port.rb', line 31 def initialize(ip = nil, port) # rubocop:disable OptionalArguments @ip = ip @port = port @port_manager = nil @cache = nil os = inspec.os if os.linux? @port_manager = LinuxPorts.new(inspec) elsif %w{darwin aix}.include?(os[:family]) # AIX: see http://www.ibm.com/developerworks/aix/library/au-lsof.html#resources # and https://www-01.ibm.com/marketing/iwm/iwm/web/reg/pick.do?source=aixbp # Darwin: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/lsof.8.html @port_manager = LsofPorts.new(inspec) elsif os.windows? @port_manager = WindowsPorts.new(inspec) elsif ['freebsd'].include?(os[:family]) @port_manager = FreeBsdPorts.new(inspec) elsif os.solaris? @port_manager = SolarisPorts.new(inspec) else return skip_resource 'The `port` resource is not supported on your OS yet.' end end |
Instance Method Details
#addresses ⇒ Object
69 70 71 72 |
# File 'lib/resources/port.rb', line 69 def addresses res = info.map { |x| x[:address] }.uniq.compact res.size > 0 ? res : nil end |
#listening?(_protocol = nil, _local_address = nil) ⇒ Boolean
55 56 57 |
# File 'lib/resources/port.rb', line 55 def listening?(_protocol = nil, _local_address = nil) info.size > 0 end |
#pids ⇒ Object
74 75 76 77 |
# File 'lib/resources/port.rb', line 74 def pids res = info.map { |x| x[:pid] }.uniq.compact res.size > 0 ? res : nil end |
#processes ⇒ Object
64 65 66 67 |
# File 'lib/resources/port.rb', line 64 def processes res = info.map { |x| x[:process] }.uniq.compact res.size > 0 ? res : nil end |
#protocols ⇒ Object
59 60 61 62 |
# File 'lib/resources/port.rb', line 59 def protocols res = info.map { |x| x[:protocol] }.uniq.compact res.size > 0 ? res : nil end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/resources/port.rb', line 79 def to_s "Port #{@port}" end |