Class: Freighthop::CLI::SSH
- Inherits:
-
Object
- Object
- Freighthop::CLI::SSH
- Defined in:
- lib/freighthop/cli/ssh.rb
Class Method Summary collapse
Instance Method Summary collapse
- #app_name ⇒ Object
- #config ⇒ Object
- #config_path ⇒ Object
- #guest_root ⇒ Object
- #hostname ⇒ Object
-
#initialize(*args) ⇒ SSH
constructor
A new instance of SSH.
- #run ⇒ Object
- #shell? ⇒ Boolean
- #ssh(cmd) ⇒ Object
- #ssh_config ⇒ Object
- #vagrant_ssh_key_path ⇒ Object
Constructor Details
#initialize(*args) ⇒ SSH
Returns a new instance of SSH.
8 9 10 |
# File 'lib/freighthop/cli/ssh.rb', line 8 def initialize(*args) @args = args end |
Class Method Details
.match?(*args) ⇒ Boolean
4 5 6 |
# File 'lib/freighthop/cli/ssh.rb', line 4 def self.match?(*args) !args.empty? # we handle guest passthrough end |
Instance Method Details
#app_name ⇒ Object
65 66 67 |
# File 'lib/freighthop/cli/ssh.rb', line 65 def app_name Freighthop.app_name end |
#config ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/freighthop/cli/ssh.rb', line 29 def config config_path.tap do |conf| if !conf.exist? || (Time.now - conf.mtime) > 86400 File.write(conf, ssh_config) end end end |
#config_path ⇒ Object
57 58 59 |
# File 'lib/freighthop/cli/ssh.rb', line 57 def config_path Pathname("/tmp/freighthop.#{app_name}.ssh-config") end |
#guest_root ⇒ Object
69 70 71 |
# File 'lib/freighthop/cli/ssh.rb', line 69 def guest_root Freighthop.guest_root end |
#hostname ⇒ Object
61 62 63 |
# File 'lib/freighthop/cli/ssh.rb', line 61 def hostname Freighthop.hostname end |
#run ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/freighthop/cli/ssh.rb', line 12 def run Freighthop::CLI::Checks.ensure_config_exists! if shell? ssh('-i') else ssh(%Q(-c "#{Shellwords.join(@args)}")) end end |
#shell? ⇒ Boolean
21 22 23 |
# File 'lib/freighthop/cli/ssh.rb', line 21 def shell? @args.first == 'ssh' end |
#ssh(cmd) ⇒ Object
25 26 27 |
# File 'lib/freighthop/cli/ssh.rb', line 25 def ssh(cmd) exec %Q(ssh -q -t -F #{config} #{app_name} 'cd #{guest_root}; /bin/bash -l #{cmd}') end |
#ssh_config ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/freighthop/cli/ssh.rb', line 37 def ssh_config <<-SSH_CONFIG.gsub(/^ /, '') Host #{app_name} HostName #{hostname} User vagrant Port 22 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile #{vagrant_ssh_key_path} IdentitiesOnly yes LogLevel FATAL ForwardAgent yes SSH_CONFIG end |
#vagrant_ssh_key_path ⇒ Object
53 54 55 |
# File 'lib/freighthop/cli/ssh.rb', line 53 def vagrant_ssh_key_path Pathname('~/.vagrant.d/insecure_private_key'). end |