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.86.8 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.7 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.6 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.5 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.4 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.3 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.2 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.86.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.85.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.85.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.84.2 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.84.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.84.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.83.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.82.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.81.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.80.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.79.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.78.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb