Sha256: 78b3c2bf146a61c4a8887c572f871478f1ad997ab0f655e4384c81e6efb45ed9

Contents?: true

Size: 1.35 KB

Versions: 11

Compression:

Stored size: 1.35 KB

Contents

require 'shellwords'

module Aptible
  module CLI
    module Subcommands
      module SSH
        def self.included(thor)
          thor.class_eval do
            include Helpers::Operation
            include Helpers::App

            desc 'ssh [COMMAND]', 'Run a command against an app'
            long_desc <<-LONGDESC
              Runs an interactive command against a remote Aptible app

              If specifying an app, invoke via: aptible ssh [--app=APP] COMMAND
            LONGDESC
            option :app
            option :remote, aliases: '-r'
            option :force_tty, type: :boolean
            def ssh(*args)
              app = ensure_app(options)
              host = app.account.bastion_host
              port = app.account.bastion_port

              ENV['ACCESS_TOKEN'] = fetch_token
              ENV['APTIBLE_COMMAND'] = command_from_args(*args)
              ENV['APTIBLE_APP'] = app.handle

              opts = options[:force_tty] ? '-t -t' : ''
              opts << " -o 'SendEnv=*' -o StrictHostKeyChecking=no " \
                      '-o UserKnownHostsFile=/dev/null'
              Kernel.exec "ssh #{opts} -p #{port} root@#{host}"
            end

            private

            def command_from_args(*args)
              args.empty? ? '/bin/bash' : Shellwords.join(args)
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
aptible-cli-0.6.0 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.15 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.14 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.13 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.12 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.11 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.10 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.9 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.8 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.7 lib/aptible/cli/subcommands/ssh.rb
aptible-cli-0.5.6 lib/aptible/cli/subcommands/ssh.rb