Sha256: 72c0aa5d490129df3f0823f8ca59698a820eee21be6c79debbca1db1a79d5a66

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'shellwords'

module Aptible
  module CLI
    module Subcommands
      module SSH
        # rubocop:disable MethodLength
        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
            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'] = options[:app]

              Kernel.exec "ssh -o 'SendEnv=*' -p #{port} root@#{host}"
            end

            private

            def command_from_args(*args)
              Shellwords.join(args)
            end
          end
        end
        # rubocop:enable MethodLength
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aptible-cli-0.3.0 lib/aptible/cli/subcommands/ssh.rb