Class: Hiera::Backend::Eyaml::EncryptHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/backend/eyaml/encrypthelper.rb

Class Method Summary collapse

Class Method Details

.ensure_key_dir_exists(key_file) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hiera/backend/eyaml/encrypthelper.rb', line 23

def self.ensure_key_dir_exists key_file
  key_dir = File.dirname key_file

  unless File.directory? key_dir
    begin
      FileUtils.mkdir_p key_dir
      LoggingHelper::info "Created key directory: #{key_dir}"
    rescue
      raise StandardError, "Cannot create key directory: #{key_dir}"
    end
  end

end

.write_important_file(args) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hiera/backend/eyaml/encrypthelper.rb', line 9

def self.write_important_file args
  require 'hiera/backend/eyaml/highlinehelper'
  filename = args[ :filename ]
  content = args[ :content ]
  mode = args[ :mode ]
  if File.file? "#{filename}"
    raise StandardError, "User aborted" unless HighlineHelper::confirm? "Are you sure you want to overwrite \"#{filename}\"?"
  end
  open( "#{filename}", "w" ) do |io|
    io.write(content)
  end
  File.chmod( mode, filename ) unless mode.nil?
end