Sha256: 6db48d7f183fcd22690d76bbe8801ad3a9fca854d5765c1c72cbaefc08b96e09

Contents?: true

Size: 1.22 KB

Versions: 16

Compression:

Stored size: 1.22 KB

Contents

class VagrantWrapper
  class << self
    def hosts
      @vm_hosts ||= begin
        result = {}

        boxes = boxes_list

        unless running?
          boxes.map! do |box|
            box['user'] = ENV['USER']
            box['port'] = '22'
            box
          end
        end

        boxes.each do |vm|
          result[vm['name']] = vm_host(vm)
        end

        result
      end
    end

    def running?
      @running ||= begin
        status = `#{vagrant_binary} status`
        status.include?('running')
      end
    end

    def boxes_list
      json_config_path = File.join('test', 'boxes.json')
      boxes = File.open(json_config_path).read
      JSON.parse(boxes)
    end

    def vagrant_binary
      'vagrant'
    end

    private

    def vm_host(vm)
      host_options = {
          user: vm['user'] || 'vagrant',
          hostname: vm['hostname'] || 'localhost',
          port: vm['port'] || '22',
          password: vm['password'] || 'vagrant',
          ssh_options: host_verify_options
      }

      SSHKit::Host.new(host_options)
    end

    def host_verify_options
      if Net::SSH::Version::MAJOR >= 5
        { verify_host_key: :never }
      else
        { paranoid: false }
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sshkit-1.22.2 test/support/vagrant_wrapper.rb
sshkit-1.22.1 test/support/vagrant_wrapper.rb
sshkit-1.22.0 test/support/vagrant_wrapper.rb
sshkit-1.21.7 test/support/vagrant_wrapper.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/sshkit-1.21.6/test/support/vagrant_wrapper.rb
sshkit-1.21.6 test/support/vagrant_wrapper.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/sshkit-1.21.5/test/support/vagrant_wrapper.rb
sshkit-1.21.5 test/support/vagrant_wrapper.rb
sshkit-1.21.4 test/support/vagrant_wrapper.rb
sshkit-1.21.3 test/support/vagrant_wrapper.rb
sshkit-1.21.2 test/support/vagrant_wrapper.rb
sshkit-1.21.1 test/support/vagrant_wrapper.rb
sshkit-1.21.0 test/support/vagrant_wrapper.rb
sshkit-1.20.0 test/support/vagrant_wrapper.rb
sshkit-1.19.1 test/support/vagrant_wrapper.rb
sshkit-1.19.0 test/support/vagrant_wrapper.rb