Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration option for using the public IP. #145

Merged
merged 1 commit into from
Jan 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/tugboat/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def ssh_port
@data['ssh']['ssh_port']
end

def use_public_ip
@data['use_public_ip']
end

def default_region
@data['defaults'].nil? ? DEFAULT_REGION : @data['defaults']['region']
end
Expand Down
17 changes: 14 additions & 3 deletions lib/tugboat/middleware/ssh_droplet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ def call(env)
end

ssh_user = env["user_droplet_ssh_user"] || env["config"].ssh_user
host_string = "#{ssh_user}@#{env["droplet_ip"]}"

if env["droplet_ip_private"] and not env["user_droplet_use_public_ip"]
host_string = "#{ssh_user}@#{env["droplet_ip_private"]}"
host_ip = env["droplet_ip"]

if env["droplet_ip_private"]
use_public_ip = env["config"].use_public_ip

if not env["user_droplet_use_public_ip"].nil?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably better as

unless env["user_droplet_use_public_ip"].nil? 

use_public_ip = env["user_droplet_use_public_ip"]
end

if not use_public_ip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, unless is probably better.

host_ip = env["droplet_ip_private"]
end
end

host_string = "#{ssh_user}@#{host_ip}"

options << host_string

if env["user_droplet_ssh_command"]
Expand Down
19 changes: 19 additions & 0 deletions spec/middleware/ssh_droplet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@
described_class.new(app).call(env)
end

it "executes ssh using public ip setting from config" do
config.data["use_public_ip"] = true

expect(Kernel).to receive(:exec).with("ssh",
"-o", "IdentitiesOnly=yes",
"-o", "LogLevel=ERROR",
"-o", "StrictHostKeyChecking=no",
"-o", "UserKnownHostsFile=/dev/null",
"-i", ssh_key_path,
"-p", ssh_port,
"#{ssh_user}@#{droplet_ip}")

env["droplet_ip"] = droplet_ip
env["droplet_ip_private"] = droplet_ip_private
env["config"] = config

described_class.new(app).call(env)
end

end

end