Sha256: 00457a717429c160c0dfc7dcc32158ddc0c3305baf26a0a7d2706069c72bd180

Contents?: true

Size: 1.14 KB

Versions: 72

Compression:

Stored size: 1.14 KB

Contents

module Specinfra
  module Command
    module Module
      module Ss
        def check_is_listening(port, options={})
          pattern = ":#{port} "
          pattern = " #{inaddr_any_to_asterisk(options[:local_address])}#{pattern}" if options[:local_address]
          "ss #{command_options(options[:protocol])} | grep -- #{escape(pattern)}"
        end

        private

        # WORKAROUND:
        #   ss displays "*" instead of "0.0.0.0".
        #   But serverspec validates IP address by `valid_ip_address?` method:
        #     https://github.com/serverspec/serverspec/blob/master/lib/serverspec/type/port.rb
        def inaddr_any_to_asterisk(local_address)
          if local_address == '0.0.0.0'
            '*'
          else
            local_address
          end
        end

        def command_options(protocol)
          case protocol.to_s
          when 'tcp'  then "-tnl4"
          when 'tcp6' then "-tnl6"
          when 'udp'  then "-unl4"
          when 'udp6' then "-unl6"
          when ''     then "-tunl"
          else
            raise ArgumentError, "Unknown protocol [#{protocol}]"
          end
        end
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 3 rubygems

Version Path
specinfra-rb19-2.44.7 lib/specinfra/command/module/ss.rb
specinfra-2.60.2 lib/specinfra/command/module/ss.rb
specinfra-2.60.1 lib/specinfra/command/module/ss.rb
specinfra-2.60.0 lib/specinfra/command/module/ss.rb
specinfra-2.59.6 lib/specinfra/command/module/ss.rb
specinfra-2.59.5 lib/specinfra/command/module/ss.rb
specinfra-2.59.4 lib/specinfra/command/module/ss.rb
specinfra-2.59.3 lib/specinfra/command/module/ss.rb
specinfra-2.59.2 lib/specinfra/command/module/ss.rb
specinfra-2.59.1 lib/specinfra/command/module/ss.rb
specinfra-2.59.0 lib/specinfra/command/module/ss.rb
specinfra-2.58.0 lib/specinfra/command/module/ss.rb
specinfra-2.57.5 lib/specinfra/command/module/ss.rb
specinfra-2.57.4 lib/specinfra/command/module/ss.rb
specinfra-2.57.3 lib/specinfra/command/module/ss.rb
specinfra-2.57.2 lib/specinfra/command/module/ss.rb
specinfra-2.57.1 lib/specinfra/command/module/ss.rb
specinfra-cisco-2.41.0 lib/specinfra/command/module/ss.rb
specinfra-2.57.0 lib/specinfra/command/module/ss.rb
specinfra-2.56.1 lib/specinfra/command/module/ss.rb