Sha256: e550c1e73f41f81d16248f3dd191221608b9ed4287986972f73a2a11b8a77df3

Contents?: true

Size: 888 Bytes

Versions: 26

Compression:

Stored size: 888 Bytes

Contents

module Isomorfeus
  module Puppetmaster
    class Server
      class Checker
        TRY_HTTPS_ERRORS = [EOFError, Net::ReadTimeout, Errno::ECONNRESET].freeze

        def initialize(host, port)
          @host, @port = host, port
          @ssl = false
        end

        def request(&block)
          ssl? ? https_request(&block) : http_request(&block)
        rescue *TRY_HTTPS_ERRORS
          res = https_request(&block)
          @ssl = true
          res
        end

        def ssl?
          @ssl
        end

      private

        def http_request(&block)
          Net::HTTP.start(@host, @port, read_timeout: 2, &block)
        end

        def https_request(&block)
          Net::HTTP.start(@host, @port, ssl_options, &block)
        end

        def ssl_options
          { use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
isomorfeus-puppetmaster-0.5.6 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.5.5 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.5.4 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.5.3 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.5.2 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.5.1 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.5.0 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.4.1 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.4.0 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.3.5 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.3.4 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.3.3 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.3.2 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.3.1 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.3.0 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.2.9 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.2.8 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.2.7 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.2.6 lib/isomorfeus/puppetmaster/server/checker.rb
isomorfeus-puppetmaster-0.2.5 lib/isomorfeus/puppetmaster/server/checker.rb