summaryrefslogtreecommitdiff
path: root/lib/leap_cli/util/vagrant.rb
blob: c67ea4f1cd1a000c6ef670c815007a856d834817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'fileutils'

module LeapCli
  module Util
    module Vagrant

      #
      # returns the path to a vagrant ssh private key file.
      #
      # if the vagrant.key file is owned by root or ourselves, then
      # we need to make sure that it owned by us and not world readable.
      #
      def self.vagrant_ssh_key_file
        file_path = Path.vagrant_ssh_priv_key_file
        Util.assert_files_exist! file_path
        uid = File.new(file_path).stat.uid
        if uid == 0 || uid == Process.euid
          FileUtils.install file_path, '/tmp/vagrant.key', :mode => 0600
          file_path = '/tmp/vagrant.key'
        end
        return file_path
      end

    end
  end
end