Class: VagrantPoderosa::Shortcut

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-poderosa/shortcut.rb

Class Method Summary collapse

Class Method Details

.absolute_winpath(path, root_path) ⇒ Object



41
42
43
44
45
# File 'lib/vagrant-poderosa/shortcut.rb', line 41

def self.absolute_winpath(path, root_path)
  p = Pathname(path)
  return path.gsub(%r{\/}, '\\') if p.absolute?
  Pathname(root_path).join(p).to_s.gsub(%r{\/}, '\\')
end

.create_shortcut(vm, ssh_info) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-poderosa/shortcut.rb', line 8

def self.create_shortcut(vm, ssh_info)
   = {
    'destination' => ssh_info[:host],
    'port' => ssh_info[:port],
    'account' => ssh_info[:username]
  }
  if ssh_info.include?(:password)
    ['authentication'] = 'Password'
    ['passphrase'] = ssh_info[:password]
  elsif ssh_info.include?(:private_key_path)
    ['authentication'] = 'PublicKey'
    # FIXME: multiple identity files
    ['identityFileName'] =
      absolute_winpath(ssh_info[:private_key_path][0], vm.env.root_path)
  end

  doc = REXML::Document.new
  doc << REXML::XMLDecl.new('1.0', 'UTF-8')
  root = doc.add_element('poderosa-shortcut', 'version' => '4.0')
  root.add_element('Poderosa.Terminal.TerminalSettings',
                   'encoding' => 'UTF8', 'caption' => ssh_info[:host])
  root.add_element('Poderosa.Protocols.SSHLoginParameter',
                   )

  filename = Pathname(Dir.tmpdir) + ('vagrant-' + vm.name.to_s + '.gts')

  File.open(filename, 'wb') do |file|
    doc.write file
    file.close
  end
  filename
end