-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Utils methods into specific helper classes
- Loading branch information
Showing
6 changed files
with
99 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'tempfile' | ||
require 'fileutils' | ||
require 'highline/import' | ||
|
||
class Hiera | ||
module Backend | ||
module Eyaml | ||
class EncryptHelper | ||
|
||
def self.read_password | ||
ask("Enter password: ") {|q| q.echo = "*" } | ||
end | ||
|
||
def self.confirm? message | ||
result = ask("#{message} (y/N): ") | ||
if result.downcase == "y" or result.downcase == "yes" | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def self.write_important_file args | ||
filename = args[ :filename ] | ||
content = args[ :content ] | ||
mode = args[ :mode ] | ||
if File.file? "#{filename}" | ||
raise StandardError, "User aborted" unless EncryptHelper::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 | ||
|
||
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 | ||
Utils::info "Created key directory: #{key_dir}" | ||
rescue | ||
raise StandardError, "Cannot create key directory: #{key_dir}" | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters