Skip to content

Commit

Permalink
Allow the user to define PKs at the host-level (align with the docs)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefmathiot committed Nov 26, 2014
1 parent 57b2571 commit 7751d11
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/electric_sheep/interactors/ssh_interactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ def build_session
@host.hostname,
@user,
port: @host.ssh_port,
key_data: Crypto.get_key(@project.private_key, :private).export,
key_data: Crypto.get_key(private_key, :private).export,
keys_only: true
)
end

def private_key
@host.private_key || @project.private_key
end

end
end
end
1 change: 1 addition & 0 deletions lib/electric_sheep/metadata/hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Host < BaseHost
option :hostname, required: true
option :ssh_port
option :description
option :private_key

def initialize(options={})
options[:ssh_port] ||= 22
Expand Down
18 changes: 18 additions & 0 deletions spec/electric_sheep/interactors/ssh_interactor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ def exchange_keys
Net::SSH::Test.remove_io_aliases
end

describe 'selecting the private key' do

let(:host){ mock }
let(:project){ mock }

it 'uses the host key if specified' do
host.expects(:private_key).returns('key_rsa')
subject.new(host, project, 'user').send(:private_key).must_equal 'key_rsa'
end

it 'falls back to the project key' do
host.expects(:private_key).returns(nil)
project.expects(:private_key).returns('key_rsa')
subject.new(host, project, 'user').send(:private_key).must_equal 'key_rsa'
end

end

describe "with a session" do

def build_ssh_story(cmd, replies={}, exit_status=0)
Expand Down
6 changes: 4 additions & 2 deletions spec/electric_sheep/metadata/hosts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
include Support::Options

it{
defines_options :hostname, :id, :description, :ssh_port
defines_options :hostname, :id, :description, :ssh_port, :private_key
requires :hostname
}

it 'is remote' do
subject.new.local?.must_equal false
end

it 'use its id when converting to string' do
it 'uses its id when converting to string' do
subject.new(id: 'some-id').to_s.must_equal 'some-id'
end

end

describe ElectricSheep::Metadata::Localhost do
Expand Down

0 comments on commit 7751d11

Please sign in to comment.