Skip to content

Commit

Permalink
Add ability to RemoteForward
Browse files Browse the repository at this point in the history
This adds the ability to set a remote forward option in order to forward
ports to a remote server potentially through a bastion host.
  • Loading branch information
Gregor MacDougall committed Feb 9, 2017
1 parent 3afc5e9 commit 9227d94
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/omc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Cli < Thor
class_option :account, aliases: '-a'
class_option :layer, aliases: '-l'
class_option :forward_agent, aliases: "-A", type: :boolean, default: false
class_option :remote_forward, aliases: "-R", type: :string, default: nil

desc 'ssh STACK', 'Connect to an instance on a stack on an account'
def ssh(stack)
Expand All @@ -17,7 +18,8 @@ def ssh(stack)
user,
stack,
layer: options[:layer],
forward_agent: options[:forward_agent]
forward_agent: options[:forward_agent],
remote_forward: options[:remote_forward]
)
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,13 +3,14 @@

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

def ssh
Expand Down Expand Up @@ -100,8 +101,11 @@ def bastion

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

Expand Down

0 comments on commit 9227d94

Please sign in to comment.