Sha256: af361c5e9b9aa1eefa2d037a04e09512ef9d5408b810a1e52058572380dd362f

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

module Dockage
  class SSH
    class << self
      SSH_OPTS = %w( StrictHostKeyChecking=no UserKnownHostsFile=/dev/null )

      def execute(provision, opts)
        return Dockage.logger('Nothing to provide') unless provision
        set_ssh_command(opts)
        Dockage.logger("Provisioning #{ provision.map{ |k,v| "#{k.to_s.yellow}: #{v}" }.join }")
        execute = "#{@command} #{provision[:inline]}" if provision[:inline]
        if provision[:script]
          Dockage.error("File #{provision[:script].bold} is not exist") unless File.exist?(provision[:script])
          execute = "cat #{provision[:script]} | #{@command}"
        end
        Dockage.verbose(execute)
        system(execute)
      end

      def connect(opts)
        set_ssh_command(opts)
        Dockage.debug(@command)
        system(@command)
        exit 0
      end

      def set_ssh_command(opts)
        raise SSHOptionsError if !opts[:login] || !opts[:host]
        return if @command
        @command = which_ssh
        @command += SSH_OPTS.map { |opt| " -o #{opt}" }.join if SSH_OPTS.any?
        @command += " -i #{opts[:identity_file]}" if opts[:identity_file]
        @command += " #{opts[:login]}@#{opts[:host]}"
        @command += " -p #{opts[:port]}" if opts[:port]
        @command += " -q" unless Dockage.verbose_mode
      end

      private

      def which_ssh
        Dockage.which('ssh')
      end

      def which_ssh_add
        Dockage.which('ssh-add')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dockage-0.1.1 lib/dockage/ssh.rb
dockage-0.1.0 lib/dockage/ssh.rb