Skip to content

Commit

Permalink
Support agent forwarding in SSH
Browse files Browse the repository at this point in the history
  • Loading branch information
adammathys committed Apr 27, 2016
1 parent 716d81d commit af35569
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lib/omc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@

module Omc
class Cli < Thor
class_option :account, aliases: '-a', optional: true
class_option :layer, aliases: '-l', optional: true
class_option :account, aliases: '-a'
class_option :layer, aliases: '-l'
class_option :forward_agent, aliases: "-A", type: :boolean, default: false

desc 'ssh STACK', 'Connect to an instance on a stack on an account'
def ssh(stack)
command = StackCommand.new(aws_account, user, stack, layer: options[:layer])
command = StackCommand.new(
aws_account,
user,
stack,
layer: options[:layer],
forward_agent: options[:forward_agent]
)
command.ssh
end

Expand Down
8 changes: 6 additions & 2 deletions lib/omc/stack_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

module Omc
class StackCommand
def initialize aws_account, user, stack_name, app: nil, layer: nil
def initialize aws_account, user, stack_name, app: nil, layer: nil, forward_agent: false
@aws_account = aws_account
@user = user
@stack_name = stack_name
@app_name = app
@layer_name = layer
@forward_agent = forward_agent
end

def ssh
Expand Down Expand Up @@ -98,7 +99,10 @@ def bastion
end

def default_ssh_args
bastion ? [ '-o', "ProxyCommand ssh -W %h:%p #{bastion.host}" ] : []
[].tap do |args|
args.push("-o", "ProxyCommand ssh -W %h:%p #{bastion.host}") if bastion
args.push("-A") if @forward_agent
end
end

def get_by_name collection, name, key: :name
Expand Down

0 comments on commit af35569

Please sign in to comment.