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.66.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.65.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.65.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.64.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.63.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.62.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.62.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.61.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.61.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
avm-eac_ubuntu_base0-0.4.2 lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.60.3 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.60.2 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.60.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.60.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.59.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.58.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.57.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.56.1 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.56.0 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb
eac_tools-0.55.7 sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/rspec/ssh_docker_server.rb