class Sumodev::Commands::Push
Constants
- DEV_TEAM
Public Instance Methods
replace_keys()
click to toggle source
# File lib/sumodev/commands/push.rb, line 24 def replace_keys connect do |ssh| say "Pushing SSH keys to #{login}@#{host}" ssh.exec! 'mkdir -p ~/.ssh; touch ~/.ssh/authorized_keys' say "Checking authorized_keys file" keys_file = ssh.scp.download!('.ssh/authorized_keys', nil, :verbose => true) do |ch, name, sent, total| say "#{name}: #{sent}/#{total}" end authorized_keys = AuthorizedKeys.new(keys_file) authorized_users.each do |user| say "Adding #{user[:identity]}" authorized_keys.add user end say 'Uploading updated authorized_keys file' ssh.scp.upload!(authorized_keys.to_io, '.ssh/authorized_keys', :verbose => true) do |ch, name, sent, total| say "#{name}: #{sent}/#{total}" end end rescue Net::SCP::Error $stderr.puts $stderr.puts "ERROR - There seems to be an error fetching the file from the server." $stderr.puts "Make sure you have SSH access and a working shell" exit 1 end
Private Instance Methods
ask_password(message)
click to toggle source
# File lib/sumodev/commands/push.rb, line 96 def ask_password(message) HighLine.new.ask(message) do |q| q.echo = false end end
connect() { |ssh| ... }
click to toggle source
# File lib/sumodev/commands/push.rb, line 83 def connect options = {:port => port} options[:password] = pass if @needs_pass Net::SSH.start(host, login, options) do |ssh| yield ssh end rescue Net::SSH::AuthenticationFailed @needs_pass = true @pass = nil retry end
host()
click to toggle source
# File lib/sumodev/commands/push.rb, line 57 def host server[/^(?:.+@)?(.+?)(?::.+)?$/, 1] end
login()
click to toggle source
# File lib/sumodev/commands/push.rb, line 53 def login server[/(.*)@/, 1] || 'root' end
pass()
click to toggle source
# File lib/sumodev/commands/push.rb, line 61 def pass @pass ||= ask_password("No valid SSH key found, please enter the password\nPass: ") end
port()
click to toggle source
# File lib/sumodev/commands/push.rb, line 65 def port server[/:(.+)/, 1] || 22 end
users()
click to toggle source
# File lib/sumodev/commands/push.rb, line 69 def users DEV_TEAM.values end