Sha256: 7ad7d90f78016320fc74c5dbb0e56c5e02095ed52a9219364d70b682d683f4ca

Contents?: true

Size: 1.79 KB

Versions: 76

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'eac_docker/images/templatized'
require 'eac_ruby_utils/core_ext'
require 'eac_templates/core_ext'

module Avm
  module EacUbuntuBase0
    module Rspec
      class SshDockerServer < ::EacDocker::Images::Templatized
        # @return [EacRubyUtils::Envs::SshEnv]
        def env
          raise '@env is blank' if @env.blank?

          @env
        end

        def on_run
          on_container do
            on_env do
              yield
            end
          end
        end

        private

        def container
          raise '@container is blank' if @container.blank?

          @container
        end

        def env_identity_file
          template.child('id_rsa').path
        end

        def env_identity_file_good_permissions
          r = ::EacRubyUtils::Fs::Temp.file
          ::FileUtils.cp env_identity_file, r
          r.chmod(0o600)
          r
        end

        def close_env
          @identity_file.remove
          @env = nil
        end

        def on_env
          open_env
          begin
            yield
          ensure
            close_env
          end
        end

        def on_container
          provide.container.temporary(true).on_detached do |container|
            @container = container
            begin
              yield
            ensure
              @container = nil
            end
          end
        end

        def open_env
          raise 'Environment already open' if @env.present?

          @identity_file = env_identity_file_good_permissions
          @env = ::EacRubyUtils::Envs::SshEnv.new(
            "ssh://root@#{container.hostname}" \
              '?StrictHostKeyChecking=no' \
              '&BatchMode=yes' \
              "&IdentityFile=#{@identity_file}"
          )
        end
      end
    end
  end
end

Version data entries

76 entries across 76 versions & 2 rubygems

Version Path
eac_tools-0.77.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.77.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.76.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.76.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.75.2 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.75.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.75.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.74.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.74.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.73.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.72.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.70.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
avm-eac_ubuntu_base0-0.5.0 lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.70.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.69.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.69.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.68.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.67.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
avm-eac_ubuntu_base0-0.4.3 lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.67.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb