Class: VagrantPlugins::TrellisSequel::VaultPass

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_plugins/trellis_sequel/vault_pass.rb

Class Method Summary collapse

Class Method Details

.candidates(file_path:, machine_root_path:) ⇒ Object



18
19
20
21
22
23
# File 'lib/vagrant_plugins/trellis_sequel/vault_pass.rb', line 18

def self.candidates(file_path:, machine_root_path:)
  paths = []
  paths << file_path unless file_path.nil?
  paths << File.join(machine_root_path, file_path) unless file_path.nil? || machine_root_path.nil?
  paths << File.join(machine_root_path, '.vault_pass') unless machine_root_path.nil?
end

.read_from_file(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/vagrant_plugins/trellis_sequel/vault_pass.rb', line 6

def self.read_from_file(args)
  path = candidates(**args).find do |p|
    File.file?(p)
  end

  if path.nil?
    raise "Couldn't determine vault password. I looked in:\r\n    * #{candidates(**args).join("\r\n    * ")}\r\n"
  end

  File.read(path).chomp
end