Class: VagrantPlugins::RekeySSH::ActionSSHInfo

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/vagrant-rekey-ssh/actions/ssh_info.rb

Instance Method Summary collapse

Methods included from Helpers

#generate_ssh_key, #rekey_sentinel_file, #ssh_key_path, #ssh_pubkey_path, #ssh_public_key

Constructor Details

#initialize(app, env) ⇒ ActionSSHInfo

Returns a new instance of ActionSSHInfo.



9
10
11
12
13
# File 'lib/vagrant-rekey-ssh/actions/ssh_info.rb', line 9

def initialize(app, env)
  @app = app
  @env = env
  @machine = env[:machine]
end

Instance Method Details

#call(env) ⇒ Object



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
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-rekey-ssh/actions/ssh_info.rb', line 15

def call(env)
  
  if @machine.config.rekey_ssh.enable
  
    # ensure we have a key
    generate_ssh_key
    
    # if the user's config hasn't specified a key, then set our key
    # in here. We also specify the insecure key too so that it works
    # in case we haven't replaced the key yet.
    # -> TODO: only specify the insecure key when we haven't set the
    #    less insecure key on the box.
    
    if @machine.config.ssh.private_key_path.nil?
      
      if ::File.exists?(rekey_sentinel_file)
        if Vagrant::VERSION < "1.4.0"
          @machine.config.ssh.private_key_path = ssh_key_path
        else
          @machine.config.ssh.private_key_path = [ssh_key_path, @machine.env.default_private_key_path]
        end
      end
      
      # Vagrant < 1.4 only supports a single ssh key, do this differently
      #if Vagrant::VERSION <= "1.4.0"
      #else
      #  @machine.config.ssh.private_key_path = [ssh_key_path, @machine.env.default_private_key_path]
      #end
    end
    
  end
  
  @app.call(env)
  
end