1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Merge pull request #557 from korin/ssh-options

Allow SSHKit::Backend.ssh_options to be set.
This commit is contained in:
Lee Hambley 2013-07-14 11:48:55 -07:00
commit c96314d4b4
5 changed files with 82 additions and 0 deletions

View file

@ -59,6 +59,7 @@ module Capistrano
sshkit.backend.configure do |backend|
backend.pty = fetch(:pty)
backend.connection_timeout = fetch(:connection_timeout)
backend.ssh_options = fetch(:ssh_options) if fetch(:ssh_options)
end
end
end

View file

@ -35,6 +35,12 @@ module Capistrano
@properties ||= Properties.new
end
def netssh_options_with_options
@netssh_options ||= netssh_options_without_options.merge( fetch(:ssh_options) || {} )
end
alias_method :netssh_options_without_options, :netssh_options
alias_method :netssh_options, :netssh_options_with_options
class Properties
def initialize

View file

@ -17,4 +17,26 @@ role :db, %w{deploy@example.com}
# extended properties on the server.
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
# and/or per server
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
# setting per server overrides global ssh_options
# set :rails_env, :<%= stage %>

View file

@ -234,6 +234,11 @@ describe Capistrano::DSL do
dsl.set(:default_env, default_env)
dsl.set(:pty, true)
dsl.set(:connection_timeout, 10)
dsl.set(:ssh_options, {
keys: %w(/home/user/.ssh/id_rsa),
forward_agent: false,
auth_methods: %w(publickey password)
})
dsl.configure_backend
end
@ -256,6 +261,13 @@ describe Capistrano::DSL do
it 'sets the backend connection timeout' do
expect(backend.connection_timeout).to eq 10
end
it 'sets the backend ssh_options' do
expect(backend.ssh_options[:keys]).to eq %w(/home/user/.ssh/id_rsa)
expect(backend.ssh_options[:forward_agent]).to eq false
expect(backend.ssh_options[:auth_methods]).to eq %w(publickey password)
end
end
end

View file

@ -134,6 +134,47 @@ module Capistrano
end
end
describe 'assign ssh_options' do
let(:server) { Server.new('user_name@hostname') }
context 'defaults' do
it 'forward agent' do
expect(server.netssh_options[:forward_agent]).to eq true
end
it 'contains user' do
expect(server.netssh_options[:user]).to eq 'user_name'
end
end
context 'custom' do
let(:properties) do
{ ssh_options: {
user: 'another_user',
keys: %w(/home/another_user/.ssh/id_rsa),
forward_agent: false,
auth_methods: %w(publickey password) } }
end
before do
server.with(properties)
end
it 'not forward agent' do
expect(server.netssh_options[:forward_agent]).to eq false
end
it 'contains correct user' do
expect(server.netssh_options[:user]).to eq 'another_user'
end
it 'contains keys' do
expect(server.netssh_options[:keys]).to eq %w(/home/another_user/.ssh/id_rsa)
end
it 'contains auth_methods' do
expect(server.netssh_options[:auth_methods]).to eq %w(publickey password)
end
end
end
end
end
end